Showing posts with label tutorials. Show all posts
Showing posts with label tutorials. Show all posts

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 都有. 如果你有需要個人教學或是團體授課, 請聯絡我!

 

2021/11/14

#7 動態查詢InfluxDB 資料庫 以及 用MQTT來遠端開/關繼電器

 大家好, 今天來和大家分享 “一起來學樹莓派”, 

本週的主題為: “#7 動態查詢InfluxDB 資料庫 以及 用MQTT來遠端開/關繼電器”.


上期的資料庫查詢的方式是固定時間軸的, 每次要查詢資料時, 可能都要重新下 SQL 指令.

本期要介紹的是使用 Slider 滑桿的方式來調整時間的區間, 並用 Interval 滑桿來調整時間的平均值, 使查詢資料的方法更便利. 


另外, 本次也介紹如何使用 MQTT out 來從遠端來開/關繼電器. 

(如果你要接上 110V or 220V 電器, 請自行小心高壓電的危險! 本人無法負責您的風險)


一起來學樹莓派吧!


這影片主要內容有:

  • 如何用 Slider 建立動態查詢 InfluxDB 的界面

  • 用 MQTT out 來遠端開/關繼電器 (可以接上電器開/關)

  • 如何把 SQL 讀出的資料解析送到 Dashboard Chart

  • 使用 Layout 工具來佈置 dashboard 排列位置

  • 使用 CSS template 來改變 dashboard 外觀


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




影片時間軸:

00:00 開始 00:34 課程開始 02:29 在 NodeRED 中開始寫程式 03:48 建立Dashboard (後來不小心被我刪除.. :( 05:27 將時間/平均時間 Sliders 加到立Dashboard 08:20 將變數儲存到 context.flow 10:45 解釋 SQL 命令的內容 11:50 從Flow 變數中取得 hours 變數內容 12:58 點擊Deploy儲存Nodes 14:29 使用 Influx client 在 terminal 上查看SQL的正確性 15:20 使用 Link in / Link out nodes 讓畫面更清楚 18:25 查看資料庫讀取後資料結構 20:33 使用 .toFixed(2) 設定小數點位數為 2 位 25:45 使用 Layout 工具來佈置 dashboard 排列位置 28:05 複製自其他 flow 的 Nodes 31:39 加入 Switch / MQTT out Nodes 34:39 解釋 ESP8266 + 繼電器程式碼 37:25 根據收到的 Message 來打開/關閉 relay 38:21 實機展示:用 MQTT來遠端打開/關閉繼電器 38:53 危險! 注意高壓電可能會致命或使人受到傷害!! 39:14 使用 Template (CSS) 來自行定義Dashboard 的外觀


Create query 程式碼(A):

msg.query = "select mean(temp) as temp, mean(humd) as humd from studioTemp where location='studio' and time > now() - ";
msg.query += flow.get("hours") + "h GROUP by time(" + flow.get("interval") + "m) FILL(0)";

return msg;

Format DB data 程式碼(B):

var My_series = ["Temperature °C", "Humidity %"];
var My_labels = ["temp", "Humd"];
var data = msg.payload;

// var data = msg.payload;
// Not sure the same query produced differnet results...?

temp = data.map(point=> {return {x:point.time , y:point.temp.toFixed(2)}});
humd = data.map(point=> {return {x:point.time , y:point.humd.toFixed(2)}});
var My_data = [temp, humd];

msg.payload = [{ series: My_series, data: My_data, labels: My_labels}]

return msg;

NodeRED source code is available here: Download it here.

Stonez56 一起來學樹莓派系列影片: 

參考資料:

2021/10/31

#6 監測資料寫入InfluxDB資料庫, 長期保存並在NodeRED資訊看板裡顯示

大家好, 今天來和大家分享 “一起來學樹莓派, 寫入InfluxDB 資料庫”. 上集分享的是資料送到 MQTT 顯示到資訊看板後, 時間後後資料就消失了. 本集是把所有的資料收集起來之後, 可以用來以後做為資料分析的依據. 以前你可能要把資料寫到 Thinkspeak server上, 現在自己家裡的樹莓派上就可以做到了! 一起來學樹莓派吧!


這影片內容有:
  • 安裝 InfluxDB 資料庫
  • 比較 InfluxDB 與關聯式資庫的不同
  • 如何把ESP32送到 MQTT 資料寫入InfluxDB 資料庫
  • 讀取InfluxDB 資料庫, 再把這些資料在資訊看板上顯示出來




Format code for writing InfluxDB

// Create the object key to match DB filed name from topic name(studio/temp1)
msg.payload["temp"] = msg.payload["studio/temp1"];
// Delete the unwanted studio/temp1
delete msg.payload["studio/temp1"];
// Update temp from string to float
msg.payload["temp"] = parseFloat(msg.payload["temp"]);

msg.payload["humd"] = msg.payload["studio/humd1"];
delete msg.payload["studio/humd1"];
msg.payload["humd"] = parseFloat(msg.payload["humd"]);

//remove unused topic
delete msg.topic;

//Create a temporary array
var data = [];
data.push(msg.payload);


//Add object to DB Tag(index field)
data.push({"location":"studio"});
//msg.payload.push({"location":"studio"});

//Copy temporary array to msg.payload
msg.payload = data;
return msg;

Format code for reading historical InfluxDB data


//Source from: https://discourse.nodered.org/t/display-2-extracts-from-influxdb-in-an-ui-chart/29665 var series = ["Temperature °C", "Humdity %"]; var labels = ["temp", "Humdity"]; var data0 = "["; var thetime0; for (var i=0; i < msg.payload.results[0].series[0].values.length; i++) { thetime0 = (msg.payload.results[0].series[0].values[i][0]); // Some manipulation of the time may be required thetime0 = Date.parse(thetime0); data0 += '{ "x":' + thetime0 + ', "y":' + (msg.payload.results[0].series[0].values[i][1]) + '}'; if (i < (msg.payload.results[0].series[0].values.length - 1)) { data0 += "," } else { data0 += "]" } } var data1 = "["; var thetime1; for (var j=0; j < msg.payload.results[0].series[0].values.length; j++) { thetime1 = (msg.payload.results[0].series[0].values[j][0]); // Some manipulation of the time may be required thetime1 = Date.parse(thetime1); data1 += '{ "x":' + thetime1 + ', "y":' + (msg.payload.results[0].series[0].values[j][2]) + '}'; if (j < (msg.payload.results[0].series[0].values.length - 1)) { data1 += "," } else { data1 += "]" } } var data = [data0, data1]; var jsondata = [JSON.parse(data0), JSON.parse(data1)]; msg.payload = [{"series": series, "data": jsondata, "labels": labels}]; msg.dataPoints = data; return msg;

請在此下載本篇教學的 NodeRead 程式: #6 監測資料寫入InfluxDB資料庫, 長期保存並在NodeRED資訊看板裡顯示

更新:
影片內容不小心略過這個 InfluxDB Out Node (Write to studioTempDB)的內容:

InfluxDB out node 內容有兩項資料要輸入:
(1) 定義 InfluxDB Server, 按下鉛筆符號(見下圖)
(2) 寫入的 Measurement 資料表名稱,我們的範例裡,Measurement = studioTemp

定義 InfluxDB Server:
(1) InfluxDB - 在 Flow 裡看到的名稱
(2) InfluxDB 版本 - 教學裡案裝的是 v1.64
(3) Host: InfluxDB 的主機: 由於我們裝在本機,所以用 : raspberrypi.local, Port: 8086
(4) 資料庫名稱: 範例裡使用 studioTemp
(5) 資料庫帳號及密碼: 如果未設定可略過


Stonez56 一起來學樹莓派系列影片: 


2021/10/23

#5 2021 一起學 Raspberry Pi 4 - 溫溼度感測器DHT11由 ESP32 經 MQTT 送到 Node-RED

大家好, 今天來和大家分享如何把 DHT11溫溼度感測器上的資料由ESP32 讀取, 並用MQTT Client 發佈到 Mosquitto Server(MQTT), 再送到 Node-RED上, 再把這些資料在資訊看板上顯示出來. 


本篇使用到的程式碼:

//---- Setup update frequency -----//
const long TEMP_updateInterval = 10000; // How long to change temp and update, 10000 = 10 sec
unsigned long TEMP_currentMillis = 0;
unsigned long TEMP_previousMillis = 0; // store last time temp update

#include "DHT.h"
#define DHTPIN 23  //ESP32 pin 23
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor

/*
  SimpleMQTTClient.ino
  The purpose of this exemple is to illustrate a simple handling of MQTT and Wifi connection.
  Once it connects successfully to a Wifi network and a MQTT broker, it subscribe to a topic and send a message to it.
  It will also send a message delayed 5 seconds later.
*/

#include "EspMQTTClient.h"

EspMQTTClient client(
    "Your_WiFi_AP",     // Wi-Fi AP name
    "Wi-FI_Password", // Wi-Fi Password
    "192.168.0.119", // MQTT Broker server ip
    "",                  // Broker user name; Can be omitted if not needed
    "",                  // Broker password; Can be omitted if not needed
    "ESP32_Client",      // Client name that uniquely identify your device
    1883                 // The MQTT port, default to 1883. this line can be omitted
);

void setup()
{
    Serial.begin(115200);
    //Start DH11 sensor
    dht.begin();
    
    // Optionnal functionnalities of EspMQTTClient :
    client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
    //client.enableHTTPWebUpdater();  // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
    //client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true
}

// This function is called once everything is connected (Wifi and MQTT)
// WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient
void onConnectionEstablished()
{
    // Subscribe to "mytopic/test" and display received message to Serial
    client.subscribe("message/hello", [](const String &payload)
                     { Serial.println(payload); });

    // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
    //client.subscribe("mytopic/wildcardtest/#", [](const String &topic, const String &payload)
    //                 { Serial.println("(From wildcard) topic: " + topic + ", payload: " + payload); });

    // Publish a message to "mytopic/test"
    client.publish("studio/temp1", "Let's go!"); // You can activate the retain flag by setting the third parameter to true

    // Execute delayed instructions
    //client.executeDelayed(5 * 1000, []()
    //                      { client.publish("mytopic/wildcardtest/test123", "This is a message sent 5 seconds later"); });
}



void loop()
{

    TEMP_currentMillis = millis();
    if(TEMP_currentMillis - TEMP_previousMillis >= TEMP_updateInterval){
        TEMP_previousMillis = TEMP_currentMillis;

        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float humidity = dht.readHumidity();
        float temperature = dht.readTemperature();
        // Read temperature as Fahrenheit (isFahrenheit = true)
        //float f = dht.readTemperature(true);

        // Check if any reads failed and exit early (to try again).
        if (isnan(humidity) || isnan(temperature))
        {
            Serial.println(F("Failed to read from DHT sensor!"));
            return;
        }

        String tmp = "Current Temperature: ";
        String hud = "Current Humidity: ";
        Serial.print(tmp);
        Serial.println(String(temperature));
        Serial.print(hud);
        Serial.println(String(humidity));
        //Publish
        client.publish("studio/temp1", String(temperature));
        client.publish("studio/humd1", String(humidity));

        // Here is how to subscribe
        //client.subscribe("message/hello", [](const String &payload) { Serial.println(payload); });
    }

    client.loop();
}

*** 影片中忘了說明, 在 VS Code 裡, 按下 F1 到 Arduino Library Manager 裡, 搜尋 EspMQTTClient V.11.1版本, 並按下安裝 , 程式才能正確執行喔~~ ***


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

影片時間軸:

00:29 課程開始 00:52 如何將 DHT11 連接到 ESP32 (接線圖) 00:59 在 ESP32 利用 EspMQTTClient 來寫程式 01:22 安裝 DHT11 程式庫 02:16 設定 EspMQTTClient 02:45 由 Raspberry Pi Terminal 找出 Mosquitto(MQTT) IP 地址 04:51 不要用 delay() 在程式 Loop 裡! 06:50 上傳並檢查發佈/訂閱的 messages 07:54 安裝 Node-RED 資訊看板(在 Node-RED 中) 08:57 按主題來訂閱消息 09:58 設置 MQTT 服務器的位置 11:34 建立資訊看板選項 Tabs Links & Groups 17:00 建立歷史資料資訊看板 20:32 查看資訊看板 20:50 資訊看板中的選項 Tabs Links & Groups在哪裡

下一集將介紹如何把歷史資料存儲到樹莓派的資料庫(influxDBvor MySQL)中, 以取得長時間的記錄資料. 


Stonez56 一起來學樹莓派系列影片: 


參考資料:

EspMQTTClient: https://github.com/plapointe6/EspMQTTClient 

2021/08/08

Arduino - How to use U8g2 library to show graphic & UTF8 characters for monochrome displays

In order to use the newly purchased 0.96" OLED SD1306 display, I studied the u8g2 library and made this video to share with you on how to use U8g2 library with monochrome display. In the video, I also included a section on how to use the free 5000+ traditional Chinese font created by Mr. Yang. The file is free for anyone to use. Really appreciated what he did for Arduino community! For those who do not have time to watch the entire video , here is the video timeline.

Video Timeline:

00:22 Install u8g2 01:04 Open PrintUTF8 example 02:00 Define display used 02:23 Explain display naming rules 04:13 Uncomment the line selected 04:33 Explain the code 04:42 enableUTF8Print() for symbol and Chinese 05:14 u8g2 supported font list 06:23 display location setCursor(X,Y) 07:05 Upload the sketch & show characters 07:23 Can't overwrite characters! 08:08 Char overwrite solution 08:37 OledOverlayPrint() function 09:06 Use OledOverlayPrint() in code 10:08 Use Open Iconic Fonts 11:29 Display cloud symbol 11:52 \u with number to show cloud 13:02 Change fonts for different lines 14:34 Download 5000+ Chinese font 15:11 Install 5000+Chinese font 15:39 Test missing fonts again 16:42 Reminder of memory usage 17:45 End of tutorial

References:

U8g2 library: https://github.com/olikraus/u8g2 U8g2 plain font: https://github.com/olikraus/u8g2/wiki... U8g2 setCursor command: https://github.com/olikraus/u8g2/wiki... U8g2 iconic font: https://github.com/olikraus/u8g2/wiki... How to make your own font: https://blog.jmaker.com.tw/chinese_oled/ MQTT & IoT Integration FB group: https://www.facebook.com/groups/36360... Download 5000+ Chinese font: https://drive.google.com/drive/folder...

 END

------------------------------------------------------------------------------------------------------------------------------------------------

2019/11/03

Arduino ESP32-CAM for video stream notebook

Preface

Recently, I acquired an ESP32-CAM Wi-Fi + Bluetooth + OV2640 camera module. My first intent was to learn how to use new Arduino ESP32 compatible modules. Then, I quickly found out with ESP3D that I could use ESP32-CAM to monitor and control my Ender 3 Pro 3D printer remotely, what a bonus!

This is my personal notebook and you are welcome to follow along and hope it might actually help!



Goal for this post

Config ESP32-CAM to use it as a web server to stream videos.
Long term goal is to use ESP32-CAM and ESP3D to make a 3D printer remote monitoring device.



ESP32-CAM Spec

  • ESP32 32bit dual core 600 DIMPS
  • 520KB SRAM + 4MB PSRAM
  • I/O: UART, SPI, I2C, PWM
  • MicroSD: Up to 4GB
  • Baud Rate: Default 115200 bps
  • Photo format: JPEG( OV2640 only), BMP, GRAYSCALE
  • Wi-Fi: 802.11 b/g/n/d/e/i/k/r 
  • Bluetooth: V4.2 BR/EDR and BLE
  • Power: 5V/2A
  • Built-in flash light
  • Camera module: OV2640, 200 Mega pixels


Schematic 

Since there is no USB on ESP32, I use a CP210x USB to UART bridge to upload.
Or, you can use a FTDI USB to UART bridge to upload sketches.

IMPORTANT NOTICE:
  • Enable ESP32 upload mode: Connect ESP32 IO0  to GND
  • ESP32 Normal operation mode: Remove ESP32  IO0 to GND connection
  • Power: must connect ESP32 VCC (5V) to VCC 
  • Wiring:
    • ESP32 GND <-> ESP32 IO0 (Upload only, remove for normal operation)
    • ESP32 GND <-> CP210x GND
    • ESP32 VCC(5V) <-> CP210x VCC
    • ESP32 U0R <-> CP210x TXD
    • ESP32 U0T <-> CP210x RXD

Then, connect
  • Camera module to ESP32-CAM
  • Then, plug CP210x dongle to PC USB port





Download Arduino IDE version greater than V1.8.9

Version 1.8.9 or above is required for ESP32-CAM. Please visit Arduino official website to download the version, if needed.

After installation follow the steps below:

1. Click File -> Preferences

 




2. Click the small square at end of Additional Boards Manager URL:

  • Enter: https://dl.espressif.com/dl/package_esp32_index.json
  • This URL allows Arduino IDE to download ESP32 package. If you had two URLs, separate them with a ',' common. Click OK to exit. Usually, the first one is for ESP8266 related package.




3. Select Boards Manager to install ESP32 library




4. Type 'ESP32'  in the search box and hit enter

  • Board manager will start to search ESP32 library. When 'esp32 by Espressif Systems' is found, click Install. 



5. Wait till the installing process finish



6. Click 'Close' when ESP32 package is INSTALLED


7. From Arduino IDE, Tools, select Board, and select "ESP32 Wrover Module"

  • Also, change Upload Speed to "115200", the ESP32 default baud rate. (No screenshot shown here)




8. From Tools, select Partition Scheme, select Huge APP (3MP No OTA/1MB SPIFFS)

  • Due to ESP32-CAM sketch size is quite large, select this item is necessary to keep program memory at it's maximum for ESP32

  • By now, Arduino IDE setting is completed.



9. (Optional) Only needed if you do not have FTDI/CP210x USB drivers in PC/Mac


10. Connect CP210x USB dongle to PC USB port

  • From Arduino IDE, select "Toos"->"Monitor"
  • Change baud rate to 115200 to match default ESP32 baud rate setting


11. Load a sketch from File->Examples->WiFi->WiFiScan

  • Load WiFiScan sketch to ensure the hardware and software /IDE settings are correct.

12. Upload the sketch 

  • Just click the small arrow circled below to upload to ESP32



If you encountered ERROR: Upload failed: "Timed out waiting for packet header"

  • CAUSE: This error indicates ESP32 IO0 didn't connect to GND. This connection is needed enable ESP32 upload mode.
  • Push reset button: when you see ....._____....._____.....____



After the connection made from ESP32 IO0 to GND and the uploading worked. 

  • Message window shows "Writing at .......100%" indicates the upload completed!




13. Check out serial monitor for messages

  • In this step, ESP32 will scan available AP nearby and show them in the monitor.
  • If you encountered ERROR: "waiting for download" message!  This error indicates that you need to remove ESP32 IO0 Pin to GND pin (Mentioned above that this connection must be removed for ESP32 to work properly!)


After remove the connection, and push reset, ESP32 found few Wi-Fi AP nearby




14. Load CameraWebServer sketch

  • It's time to test out the ESP32 web server and stream videos
  • From "File"->"Examples"->"ESP32"->"Camera"->CameraWebServer


15. Change Wi-Fi AP SSID and Password to match your own Wi-FI SSID/Password





16. Change the camera model to AI_THINKER

  • The camera module is the in the package came with ESP32. So I selected the default "AI_THINKER"


17. Get web server IP address

  • If everything goes well, the camera IP address would show on the serial monitor
  • Copy the IP address shown



18. Open a browser and type the IP address specified above

  • The screen below shows ESP32 web server is running successfully
  • Select the resolution on the top
  • Click Start Stream and the video will show on the right hand side




19. Real-time camera video stream in browser

  • If you like, you could change the resolution and play around many OV2640 parameters.
  • For the resolution, the larger the resolution, the fewer the frame rates.


If you encountered ERROR message "Brownout detector was triggered", many articles indicated causes could be:
  • Poor quality USB cable
  • USB cable is too long
  • Or not enough power to USB port


After I changed to dedicated USB port to connect ESP32, the video came back alright and running for a while without the error messages.

What's Next

After 2-3 hours, the config/setting on ESP32 was done. Next step is to install ESP3D to remote monitoring my 3D printer.  Until next time, see you!



References:




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

前言

最近,我購買了ESP32-CAM Wi-Fi +藍牙+ OV2640相機模組。 本來是打算學習如何使用新的Arduino ESP32 相容模組。 後來我發現它可以搭配ESP3D,用ESP32-CAM遠程監視和控制Ender 3 Pro 3D打印機,這真是太好了!

這是我的個人筆記本,歡迎您繼續閱讀並希望它能對您有所幫助!


本篇目的

設定及使用ESP32-CAM以將其用作網絡服務器以及串流視訊。
長期目標是使用ESP32-CAM和ESP3D製作3D印表機遠端監控及控制設備。


ESP32-CAM 規格

  • ESP32 32bit dual core 600 DIMPS
  • 520KB SRAM + 4MB PSRAM
  • I/O: UART, SPI, I2C, PWM
  • MicroSD: Up to 4GB
  • Baud Rate: Default 115200 bps
  • Photo format: JPEG( OV2640 only), BMP, GRAYSCALE
  • Wi-Fi: 802.11 b/g/n/d/e/i/k/r 
  • Bluetooth: V4.2 BR/EDR and BLE
  • Power: 5V/2A
  • Built-in flash light
  • Camera module: OV2640, 200 Mega pixels


接線方式

由於ESP32上沒有USB孔,因此我使用CP210x USB至UART轉接器進行上傳。
您可以使用FTDI USB至UART來上傳程式。

請注意:
  • 啟用ESP32上載模式:將ESP32 IO0連接到GND
  • ESP32正常運行模式:拔開ESP32 IO0到GND的連接
  • 電源:必須將ESP32 VCC(5V)連接到VCC
  • 連接:
    • ESP32 GND <-> ESP32 IO0 (只有上傳需要連接!)
    • ESP32 GND <-> CP210x GND
    • ESP32 VCC(5V) <-> CP210x VCC
    • ESP32 U0R <-> CP210x TXD
    • ESP32 U0T <-> CP210x RXD

接線完成後,把模組及CP210x接到 PC USB 插槽
  • 相機模組接上 ESP32-CAM
  • 把CP210x 接到 PC USB 孔





下載Arduino IDE版本大於V1.8.9版本

ESP32-CAM需要版本1.8.9或更高版本。 如果沒有此版本,請到Arduino官方網站下載版本。
安裝後,請執行以下步驟:

1. 點擊文件 -> 偏好

 




2. 點擊Additional board manager URL後面的小方框:

  • 輸入:https://dl.espressif.com/dl/package_esp32_index.json 按 OK
  • 這可以讓 Arduino IDE下載ESP32相關程式。 如果您有兩個URL,請用一個',' 將它們分開,再按 OK。 一般來說,第一個是用於ESP8266相關程式。





3. 選擇Boards Manager來安裝ESP32版子相關程式



4. 在搜索框中輸入“ ESP32”,然後按Enter

  • Board Manager 將開始搜索ESP32程式庫。 當找到“ Espressif Systems esp32”時,點擊“安裝”。



5. 等到安裝過程完成



6. 安裝ESP32程式後,點擊“Close”。

7. 從Arduino IDE中,選擇 Tools,選擇 Board,然後選擇“ ESP32 Wrover Module”

  • 另外,將“上傳速度”更改為ESP32默認傳輸速率“ 115200”。 (這張沒有截圖)




8. 從“Tools”中,選擇“Partition Scheme”,然後選擇“Huge App”(3MP No OTA / 1MB SPIFFS)
  • 由於ESP32-CAM的程式很大,因此請選擇此項目以將程式憶空間保持為ESP32的最大容量

  • 至這裡,Arduino IDE設定完成。


9. (選項)只有你確認 PC / Mac中沒有FTDI / CP210x USB驅動程式時才需要做


10.將CP210x USB 連接到PC USB

  • 在Arduino IDE中,選擇 Tools,  Serial Monitor
  • 傳輸速率更改為115200以搭配默認ESP32認傳輸速率


11. 打開測試程式 File, Examples, WiFi, WiFiScan

  • 打開WiFiScan程式來測試 硬體及軟體設置是否正確

12.  上傳程式到 ESP32

  • 只需點選下面圓圈的小箭頭,即可上傳到ESP32



如果遇到錯誤, 上傳失敗:  "Timed out waiting for packet header"

  • 原因:此錯誤表示ESP32 IO0未連接到GND。 上面有提到過了, ESP32上載模式需要此連接!。
  • 當你看到 ....._____....._____.....____ 訊息時, 按一下 ESP32 Reset 鈕!



把ESP32 IO0到GND的連接成功後,就能上傳成功。

  • Serial port 顯示“writing at 0x00000800....... 100%” 表示上傳已完成!




13. 查看Serial Monitor內容

  • 在這裡,ESP32將掃描附近的可用Wi-FI AP並將其顯示
  • 如果遇到錯誤:“Waiting for download! 該錯誤表明您需要移除ESP32的IO0至GND連線(上面提到必須移除此連接才能使ESP32正常工作!)


把ESP32的IO0至GND連線拔掉後, ESP32在附近發現了幾個Wi-Fi AP




14.加載CameraWebServer草圖

  • 現在來測試ESP32 Web服務器及試試串流傳輸影像
  • 從“文件, File, Example, ESP32, Camera, then 點選 CameraWebServer



15. 更改Wi-Fi AP SSID和密碼以成為您自己家裡的Wi-FI SSID /密碼





16. 將相機型號更改為AI_THINKER

  • 相機模組是ESP32隨附的相機模組, 所以選擇了內定的“ AI_THINKER”



17. 取得 ESP32 IP 地址

  • 如果一切順利,相機的IP地址將顯示在 Serial Monitor 上面
  • 複製顯示的IP地址



18. 打開瀏覽器並輸入上面指定的IP地址

  • 以下屏幕顯示ESP32 Web服務器運行成功
  • 選擇頂部的解析度
  • 點擊"Start to stream",開始串流, 影像將顯示在右側




19. 瀏覽器中的實時攝像機串流

  • 你可以更改解析度, 並且更改OV2640不同參數。
  • 解析度越大,每秒顯示的幀率越少。


如果您遇到錯誤訊息“Brownout detector was triggered”,則表明原因的許多文章可能是:
  • USB電線品質不良
  • USB電線太長
  • USB端電量不足


我改用專用的USB連接ESP32之後,視訊又恢復正常並運行了一段時間,就再也沒有出現錯誤訊息。




接下來?

經過2-3小時後在ESP32上的配置/設置已完成也測試成功。 下一步是安裝ESP3D以遠程監視我的3D打印機! See you next time!