2024/10/10

Stonez56 創客工坊 開幕了~ 誠摯的邀請大家加入FB社團~

Stonez56 創客工坊 開幕了~ 誠摯的邀請大家加入FB社團~
https://www.facebook.com/groups/stonez56




您好!我是 Kevin Chen,也是 Stonez56。作為一位資訊/電子技術愛好者,我在各種平台上分享我的知識和專案,旨在幫助他人學習和實踐技術。

在這個社團中,我將分享我的經驗和知識,包括:

Arduino 和 IoT 的教學和專案分享:從基本的 Arduino 教學到 IoT 專案的實踐,我將分享我的經驗和知識。

應用程式開發:我將分享我的 App Inventor 教程,幫助您創建自己的 App Inventor 應用程式。

博客分享:我將分享我的週末專案和其他技術相關內容,讓您了解最新的技術趨勢。

我的目標是教育性地幫助他人學習和實踐技術,特別是在 Arduino 程式設計和App應用程式開發及AI等領域。您可以在這裡與我和其他技術愛好者交流、學習和分享您的經驗。

我住在台灣新竹,歡迎您加入這個社團,與我一起探索技術世界!讓我們一起學習、分享和創造!

從 Arduino, ESP32, App Inventor, Raspberry Pi 都有. 如果你有需要個人教學或是團體授課, 請聯絡我!

 

2024/06/13

Arduino #43使用LoRa模組,輕鬆實現長距離免費通訊!(How to use LoRa modules with ESP32 for long distance communication)

 歡迎來到本週的Weekend project with Stonez56!你準備好體驗超炫的科技應用了嗎?本週的主題是使用Arduino #43 LoRa模組,輕鬆實現長距離免費通訊!

這次的影片內容可謂豐富多元,包括以下精彩部分:


* 什麼是LoRa技術以及其應用

* 使用ESP32 LED燈顯示連線狀態,簡單易懂

* 深入探索LoRa模組,一步步教你如何使用

* 教你使用SSD1306 OLED顯示器,方便實用

* 帶你體驗DHT11溫濕度感測器,監測環境變化

* 最後還有程式碼解說,讓你輕鬆上手


這次的Weekend project一定不會讓你失望,絕對值得一看!快來點開影片,體驗科技的樂趣吧!


00:00 開始 00:16 本集影片概要 02:12 LoRa 適用的場合 02:42 RYLR998 LoRa 模組的特性 04:17 使用前所需之基本設定 07:12 AT Command 設定實作(以 VS Code做設定) 09:45 點對點連線實際運作展示 11:15 發射端程式解析 21:00 接收端程式解析


Source code:

2023/11/12

Arduino #39 使用 u8g2 庫在 SSD1306 OLED 上動態繪製骰子 (Draw dynamic dice on SSD1306 OLED with u8g2 library)

 Hi, welcome to this week's Weekend project with Stonez56.

This week is Arduino Episode #39, "Drawing Dice Dynamically at 0.96" OLED with u8g2" This video is suitable for people who want to learn how to draw patterns on SD 1336 LED.


=== IMPORTANT NOTICE === Do you want to generate u8g2 UTF8 font for your own Arduino projects? Try this online web tool I created @ https://kidsgo.net/u8g2 Just 3 easy steps to get UTF8 Arduino codes for your projects! Try it today!! === NOTICE ===

In the previous episode, I showed audiences how to use the accelerometer to draw dynamic dice in APP inventor 2. People who are interested can click this link to watch. (App Inventor Episode 11: https: //   • App Inventor #11 Write your own App (...   ) The next video is planned to transfer the dice points from App Inventor 2 to the OLED on ESP32 for display in real time. In this way, we can learn how to communicate from mobile App to ESP32. Stay tuned! References: * u8g2 font reference: https://github.com/olikraus/u8g2/wiki... * u8g2 Github: https://github.com/olikraus/u8g2
* u8g2 UTF8 font generator: https://kidsgo.net/u8g2 If you don’t have enough time, you can also choose the part you want to watch from the timeline below! Video timeline: 00:00 start 00:40 Results presentation (Demo) 01:15 Coding briefing 02:13 Use random in code 04:23 Show dice at random location 08:53 drawDice function 14:59 Show total points 16:07 Select u8g2 fonts

==================== 中文版 =================================

Hi,歡迎來到本週的 Weekend project with Stonez56。本週是 Arduino 第 39 集,“在 0.96" OLED 上使用 u8g2 動態繪製骰子”。此影片適合希望學習如何在 SD 1336 LED 上繪製圖案的人。


描述: 嗨,歡迎來到本週的 Stonez56 週末項目。本週是 Arduino 第 39 集,“在 0.96" OLED 上使用 u8g2 動態繪製骰子”。此視頻適合希望學習如何在 SD 1336 LED 上繪製圖案的人。 在上一集中,我向觀眾展示了如何使用加速計在 APP inventor 2 中繪製動態骰子。感興趣的人可以點擊此鏈接觀看。 (App Inventor 第 11 集:https://www.youtube.com/watch?v=2d6Si6u8FVE) 下一個視頻計劃將骰子點數從 App Inventor 2 轉移到 ESP32 上的 OLED 以進行實時顯示。這樣,我們就可以學習如何從移動應用程序與 ESP32 通信。敬請期待! 參考文獻:
如果您沒有足夠的時間,您還可以在以下時間軸中選擇您想觀看的部分! 視頻時間軸: 00:00 開始 00:40 結果展示(演示) 01:15 編碼簡報 02:13 在代碼中使用隨機 04:23 在隨機位置顯示骰子 08:53 drawDice 函數 14:59 顯示總分 16:07 選擇 u8g2 字體>


====================== ESP32 Codes ===============================
#include <Arduino.h>
#include <U8g2lib.h>

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);

void setup(void)
{
    Serial.begin(115200);
    u8g2.begin();
    randomSeed(analogRead(5)); // randomSeed() must be in setup()!
}


// OLED TEXT ROW number, vertical position
const byte ROW[5] = {0, 15, 31, 47, 63};

// 4 dice top-left {x, y} locations in tl[]
const int tl[4][2] = {{2, 20}, {34, 28}, {68, 20}, {100, 28}};
const int size = 28; // dice width and height
const int diceRoundedCorner = 5;
/**
 * drawDiceImage
 *  n = dice serial (1 ~ 4)
 *  pnt = dice points (1 ~ 6)
 */
void drawDiceImage(int n, int pnt)
{
    int tx = tl[n][0];       // top left x
    int ty = random(17, 35); // Makes the y showing at random height
    // int ty = tl[n][1]; //top left y, makes Y showing at fixed height
    int centerX = tx + (size / 2); // center of the dice X
    int centerY = ty + (size / 2); // center of th dice  Y
    const int largeDotSize = 4;    // drawing dot size for 1 only
    const int smallDotSize = 2;    // drawing dot size for rest

    u8g2.drawRFrame(tx, ty, size, size, diceRoundedCorner); // draw the dice border

    // draw the points based on the variable: pnt
    switch (pnt)                                            
    {
    case 1:
        u8g2.drawFilledEllipse(centerX, centerY, largeDotSize, largeDotSize, U8G2_DRAW_ALL);
        break;
    case 2:
        u8g2.drawFilledEllipse(centerX, centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX, centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        break;
    case 3:
        u8g2.drawFilledEllipse(centerX, centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX, centerY, smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX, centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        break;
    case 4:
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        break;
    case 5:
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX, centerY, smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        break;
    case 6:
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY, smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX - (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY - (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY, smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        u8g2.drawFilledEllipse(centerX + (size / 4), centerY + (size / 4), smallDotSize, smallDotSize, U8G2_DRAW_ALL);
        break;
    default:
        break;
    }
}

void loop(void)
{
    int dicePoint[4];
    int totalPoints = 0;
    u8g2.clearBuffer();

    //Generate 4 random dice points 
    for (int i = 0; i < 4; i++)
    {
        dicePoint[i] = random(1, 6);    // get random dice number to point
        drawDiceImage(i, dicePoint[i]); // draw dice i with the random dicePoint
        totalPoints += dicePoint[i];    // adding current points to totalPoints
    }

    //Print out the title + total points
    u8g2.setCursor(0, ROW[1]);
    u8g2.setFont(u8g2_font_lubBI14_te); // font list: https://github.com/olikraus/u8g2/wiki/fntlist16
    u8g2.print("POINTS:");
    u8g2.print(totalPoints);

    u8g2.sendBuffer();
    delay(1500);
}
  
==================================================================

2023/11/05

VS Code 初始化的時候出現 Cannot find Arduino tools. Use Arduino CLI bundled with this extension instead? 要如何處理?



"安裝 Arduino Extension for VS code 時,如果遇到 “Cannot find Arduino tools. Use Arduino CLI bundled with this extension instead?”錯誤訊息。




請嘗試以下方法解決此問題。

解決步驟:


    1. Arduino: command path -> 保持為空白
    2. Arduino: path -> 保持為空白
    3. Arduino: Use Arduino Cli -> 勾選“Use Arduino CLI installed instated of the legacy Arduino IDE”
    4. 重新啟動 VS code

============ ENGLISH =====================

When install Arduino Extension for VS code, if you encountered "Cannot find Arduino tools. Use Arduino CLI bundled with this extension instead?" error message. Try this to fix it.


Steps to fix:


    1. Arduino: command path -> leave it empty
    2. Arduino: path -> leave it empty
    3. Arduino: Use Arduino Cli -> tick "Use Arduino CLI installed instated of the legacy Arduino IDE"
    4. Restart VS code





2023/09/29

[從零開始學習 App Inventor 系列] 之 自己來寫 APP 系列 - 新影片上架了~

 [從零開始學習 App Inventor 系列] 之 自己來寫 APP 系列,
有新單元推出囉~有興趣的朋友,趕緊來觀看!

別忘了點讚,按下喜歡及分享給好朋友喔~



這個是一個專門為初學者來開發的一個系列, 所以會講的比較詳細, 

相信各位只要仔細收看內容並進行實作, 一定會收獲滿滿滿!! :)


(0) 課程簡介 https://youtu.be/gkGW8bnO66w

(1) 基本認識, 環境設定及註冊帳號 https://youtu.be/BesQP6GckjE

(2) 使用者 / 程式設計介面介紹 (忘了增加開發流程介紹 / ) https://youtu.be/ukV7c5IWMaA

(3) 動手寫程式吧! (犬犬汪汪 App) https://youtu.be/kih39aqtI64

(4) App 開發流程 / 各式變數介紹 https://youtu.be/L9jtQBDIzow

(5) 單位換算 App 之實作練習 https://youtu.be/f4l6uckAfEo

(6) 條件判斷式 (if then else) https://youtu.be/y8MVDTkskHA

(7) 高鐵票優惠計算 App 實作練習 https://youtu.be/30Sq8610WFk

(8) 待續... 

2023/09/16

[從零開始學習 App Inventor 系列] 之 自己來寫 APP 系列

Stonez56 推出全新的單元 -
[從零開始學習 App Inventor 系列] 之 自己來寫 APP 系列 


這個是一個專門為初學者來開發的一個系列, 所以會講的比較詳細,

相信各位只要仔細收看內容並進行實作, 一定會收獲滿滿滿!! :)

自己來寫 APP 課程內容:

(0) 課程簡介



   (1) 基本認識, 環境設定及註冊帳號

  • 本集內容主要包括了以下內容: 
  • - AppInventor介紹 
  • - 基本需求 
  • - 環境設定 
  • - 如何註冊帳號


  (2) 使用者 / 程式設計介面介紹

  • 本集內容主要包括了以下內容: 
  • - 主界面介紹 
  • - 程式設計界面介紹


  (3) 動手寫程式吧! (犬犬汪汪 App)

  • 本集內容主要包括了以下內容: 
  • - 寫出 小狗汪汪 App
  • - 測驗 寫出猫咪喵喵 App



   (4) App 開發流程 / 各式變數介紹

  • 本集內容主要包括了以下內容: 
  • - App 開發流程  (四思而後行)
  • - 什麼是變數?
  • - 全域變數 & 區域變數 App 實作
  • - 各式變數型別介紹 - 數字, 字串, 布林, 顏色


#stonez56, #weekendproject , #EPS32, #ESP8226, #Arduinoproject, #Arduino, #IOTprojects, #tutorials, #Raspberrypi, #虛擬容器, #IOT, #樹莓派, #docker, #rclone, #mqtt, #appinventor, app inventortutorial , #appinventor2教學, #樹莓派教學, #iotproject, #u8G2, #wifimanager, #ESP32 FOTA, #FOTA, #VScode, #lighttracing, #lighttracking, #voicecontrol, #IFTTT, #Adafruit, #Scratch, #Tello, #PIRsensor, #rgbledcontroller, #WS2812B, #LCD, #Temperaturesensor, #uwb, #uwb technology, #lora, #loramodule, #loratest, #從零開始學習AppInventor!, #自己來寫APP

2023/06/23

Arduino #48集, 用一塊ESP32來學 IOT (#48 Learn IOT with MQTT + ESP32) 把 MQTTlens 換成 EMQX MQTT Web Client

大家好, 今天和大家來分享, Arduino #48集, 用一塊ESP32來學 IOT (#32 Learn IOT with MQTT + ESP32)   這個影片很適合初學者來觀看學習. 

影片內容主要是告訴大家,  只要手上有一塊 ESP32 和一台電腦, 就可以開始學習 IOT 了 !   看過這個影片, 你會了解學習 IOT 一點都不難喔! 甚至可以延伸作法, EMQX MQTT web client 透過雲端EMQX來做遠端的控制! 


使用 MQTT 來幫助你快速完成第一個 IoT專案

有幾位朋友寫信來告知, MQTTLens 這個 Chrome 流覽器插件(extension) 已經無法再使用了, 所以我把這個教學的流程, 整理一下, 改用了 EMQX 本身自有的 MQTT web client 來做這個教學. 

這個是一個專門為初學者來開發的一個系列, 所以會講的比較詳細, 相信各位只要仔細收看內容並進行實作, 一定會收獲滿滿滿。好, 那我們就開始吧今天的練習吧~




如果時間不夠的朋友, 也可以從以下的時間軸挑選想看的部份即可!

影片時間軸:

00:00 開始

01:03 什麼是 MQTT,它是如何運作的?

02:29 打造你的第一個MQTT IOT專案!

03:34 MQTT 程式:pubsubclient

04:27 Arduino IDE: 設定Additional Boards Manager URL

04:55 Arduino IDE 其它設定

05:22 從我的部落格中下載程式並貼在Arduino IDE

05:51 在程式中更改必要的設定

08:55 使用 EMQX MQTT web client

09:34 EMQX 簡易設定

11:39 訂閱 ESP32上的主題

14:30 從EMQX MQTT client 訂閱主題

16:52 從EMQX MQTT client 發佈主題 Stonez56/esp32s




參考資料:

///
/*
 Basic ESP8266 MQTT example
 This sketch demonstrates the capabilities of the pubsub library in combination
 with the ESP8266 board/library.
 It connects to an MQTT server then:
  - publishes "hello world" to the topic "outTopic" every two seconds
  - subscribes to the topic "inTopic", printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary
  - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
    else switch it off
 It will reconnect to the server if the connection is lost using a blocking
 reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
 achieve the same result without blocking the main loop.
 To install the ESP8266 board, (using Arduino 1.6.4+):
  - Add the following 3rd party board manager under "File -&nbgt; Preferences -&nbgt; Additional Boards Manager URLs":
       http://arduino.esp8266.com/stable/package_esp8266com_index.json
  - Open the "Tools -&nbgt; Board -&nbgt; Board Manager" and click install for the ESP8266"
  - Select your ESP8266 in "Tools -&nbgt; Board"
*/
 
#include &nblt;WiFi.h&nbgt;
#include &nblt;PubSubClient.h&nbgt;
#include &nblt;EasyButton.h&nbgt;
#define LED 2        //built-in LED on ESP32
 
// Update these with values suitable for your network.
const char *ssid = "Stonez24";
const char *password = "a0101010101a";
 
// Define your client ID on EMQX
String mqtt_ClientID = "stonez56_IOT_Station_";
 
// Define your topics to subscribe / publish
const char* sub_topic = "stonez56/esp32s";
const char* pub_led_topic = "stonez56/esp32s_led_state";
const char* pub_init_topic = "stonez56/esp32s_is_back";
 
// EMQX broker parameters
const char *mqtt_server = "broker.emqx.io";
const char *mqtt_userName = "emqx";
const char *mqtt_password = "public";
 
WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int value = 0;
 
void setup_wifi()
{
    delay(10);
    // We start by connecting to a WiFi network
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
 
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
 
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
 
    randomSeed(micros());
 
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}
 
void callback(char *topic, byte *payload, unsigned int length)
{
    Serial.print("Message arrived [");
    Serial.print(topic);
    Serial.print("] ");
    for (int i = 0; i &nblt; length; i++)
    {
        Serial.print((char)payload[i]);
    }
    Serial.println();
 
    payload[length] = '\0';
    String message = (char *)payload;
    
    if (strcmp(topic, sub_topic) == 0)
    {
        if (message == "off")
        {
            digitalWrite(LED, LOW); //Turn off
            client.publish(pub_led_topic, "LED off");
        }
        if (message == "on")
        {
            digitalWrite(LED, HIGH); //Turn on
            client.publish(pub_led_topic, "LED on");
        }
        if (message == "flash")
        {
            digitalWrite(LED, LOW); //LED flashing 2 times
            delay(200);
            digitalWrite(LED, HIGH); 
            delay(200);
            digitalWrite(LED, LOW); 
            delay(200);
            digitalWrite(LED, HIGH); 
            delay(200);
            digitalWrite(LED, LOW); 
            client.publish(pub_led_topic, "LED flashed 2 times");
        }        
    }
 
    /* Switch on the LED if an 1 was received as first character
    // if ((char)payload[0] == '1')
    // {
    //     digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
    //                                     // but actually the LED is on; this is because
    //                                     // it is active low on the ESP-01)
    // }
    // else
    // {
    //     digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
    // } */
}
 
void reconnect()
{
    // Loop until we're reconnected
    while (!client.connected())
    {
 
        Serial.println("Attempting EMQX MQTT connection...");
        // Create a random client ID
        mqtt_ClientID += String(random(0xffff), HEX);
        // Attempt to connect
        if (client.connect((mqtt_ClientID, mqtt_userName, mqtt_password)))
        {
            Serial.print(" connected with Client ID: ");
            Serial.println(mqtt_ClientID);
            // Once connected, publish an announcement...
            client.publish(pub_init_topic, "Hi, I'm online!");
            // ... and resubscribe
            client.subscribe(sub_topic);
        }
        else
        {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}
 
void setup()
{
    pinMode(LED, OUTPUT); // Initialize the _LED pin as an output
    digitalWrite(LED, LOW); //default ESP32 LOW is turn off
 
    Serial.begin(115200);
    setup_wifi();
    client.setServer(mqtt_server, 1883);
    client.setCallback(callback);
}
 
void loop()
{
 
    if (!client.connected())
    {
        reconnect();
    }
    client.loop();
 
    /* unsigned long now = millis();
    // if (now - lastMsg &nbgt; 2000)
    // {
    //     lastMsg = now;
    //     ++value;
    //     snprintf(msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
    //     Serial.print("Publish message: ");
    //     Serial.println(msg);
    //     client.publish("stonez56/esp32s_button_pushed", msg);
    // } */
}