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!

1 comment:

  1. I tried this today and I can't upload the sketch....the Error message says "A fatal error occurred: Timed out waiting for packet header".

    It turned out, I connected ESP32-CAM to the 3.3V pin instead of 5V pin.
    Just in case you run into the same error... Ha..

    ReplyDelete