Wednesday, June 26, 2019

ESP32-CAM with OV2640 camera

Flashing the example application


Prerequisites

ESP32-CAM with OV2640 camera (USD 5.59 + 1.98 shipping)
A serial programmer with 3.3V (e.g. CH341 or CH341A work fine)
Arduino IDE, version 1.9.8
5V (or 3.3V) power supply
Wifi Access Point
Six jumper wires
Windows-PC with an USB port

Setup Arduino IDE

File -> Preferences -> Additional Boards Manager URLs
Add these URLs (URLs are comma separated):
http://arduino.esp8266.com/stable/package_esp8266com_index.json, https://dl.espressif.com/dl/package_esp32_index.json
(Note: package_esp8266com_index is not needed for the ESP32-CAM)

Tools -> Board -> Boards Manager
Search for esp32 in the Boards Manager windows, select it and click Install to install it.

Tools -> Board -> ESP32 Wrover Module


Tools -> Partition Scheme -> Huge App (3MB No OTA)

Tools -> COM Port -> COMxyz
(Select the COM port of your programmer)

Tools -> Serial Monitor
This starts a serial monitor on the selected COM port (not active during flashing, set it to 115200 baud.

Tools -> Programmer -> AVRISP mkII
File -> Examples -> ESP32 -> Camera -> CameraWebServer
In line 14 insert // at the beginning and in line 18 remove // at the beginning defining the camera as CAMERA_MODEL_AI_THINKER.
Enter the SSID and password of your Wifi Access Point editing lines 22 and 23 of the file CameraWebServer and save it as MyCameraWebServer.





Wiring the ESP32-CAM

PINs o the ESP32-CAM board:
3.3V - IO16 - IO0 - GND - VCC - U0R - U0T - GND
IO4 - IO2 - IO14 - IO15 - IO13 - IO12 - GND - 5V 

Connections to be made:
ESP32-CAM pin GND -> GND of the 3.3V serial programmer
ESP32-CAM pin U0T -> RX of the 3.3V serial programmer
ESP32-CAM pin U0R ->  TX of the 3.3V serial programmer
ESP32-CAM pin GND -> GND of the power supply
ESP32-CAM pin 5 V    -> 5V of the power supply(*)

(*):When using a 3.3V power supply wire the pin 3.3V to the 3.3V power supply instead.

Press the RST button and you should see the log output of the pre-installed firmware in the Arduino IDE serial monitor.


Flashing ESP32-CAM 

To flash the software connect the last jumper cable:
ESP32-CAM pin GND <-> ESP32-CAM pin IO0

Then press RST to enter flashing mode.

In Arduino IDE press the upload button (Sketch -> Upload)
During flashing the output should be like this:


Global variables use 52696 bytes (16%) of dynamic memory, leaving 274984 bytes for local variables. Maximum is 327680 bytes.
esptool.py v2.6
Serial port COMxyz
Connecting........
Chip is ESP32D0WDQ5 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 12:34:45:56:9a:bc
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47...

Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 7281.7 kbit/s)...
Hash of data verified.
Compressed 16832 bytes to 10888...

Writing at 0x00001000... (100 %)
Wrote 16832 bytes (10888 compressed) at 0x00001000 in 1.0 seconds (effective 140.3 kbit/s)...
Hash of data verified.
Compressed 2242064 bytes to 1795618...

Writing at 0x00010000... (0 %)
Writing at 0x00014000... (1 %)
[...]
Writing at 0x001c0000... (99 %)
Writing at 0x001c4000... (100 %)
Wrote 2242064 bytes (1795618 compressed) at 0x00010000 in 158.1 seconds (effective 113.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 134...

Writing at 0x00008000... (100 %)
Wrote 3072 bytes (134 compressed) at 0x00008000 in 0.0 seconds (effective 1536.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Then disconnect the last jumper wire and press the RST button. The output shall be (in the Arduino IDE serial monitor):
00:00:07.879 -> ets Jun  8 2016 00:22:57
00:00:07.879 ->
00:00:07.879 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
00:00:07.913 -> configsip: 0, SPIWP:0xee
00:00:07.913 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
00:00:07.913 -> mode:DIO, clock div:1
00:00:07.913 -> load:0x3fff0018,len:4
00:00:07.913 -> load:0x3fff001c,len:1100
00:00:07.913 -> load:0x40078000,len:9232
00:00:07.913 -> load:0x40080400,len:6400
00:00:07.913 -> entry 0x400806a8
00:00:09.951 ->
00:00:11.373 -> .....
00:00:13.375 -> WiFi connected
00:00:13.375 -> Starting web server on port: '80'
00:00:13.375 -> Starting stream server on port: '81'
00:00:13.375 -> Camera Ready! Use 'http://192.168.43.125' to connect
Copy the URL given in the last line, http://192.168.43.125 in this example, to your web browser.

When getting an image the output shall be:

00:01:52.537 -> JPG: 3461B 43ms
When getting an stream the output shall be:
00:02:32.723 -> MJPG: 3454B 3ms (333.3fps), AVG: 3ms (333.3fps), 0+0+0+0=0 0
00:02:32.757 -> MJPG: 3441B 30ms (33.3fps), AVG: 16ms (62.5fps), 0+0+0+0=0 0
00:02:32.791 -> MJPG: 3468B 49ms (20.4fps), AVG: 27ms (37.0fps), 0+0+0+0=0 0
When disconnecting power the output shall be (also happens when using a weak power supply):
00:03:36.486 -> 
00:03:36.486 -> Brownout detector
If you receive the following lines during startup of the module remove power from the module, reconnect power and press the RST button. Pressing the RST button while powered on will not fix this issue:
00:00:44.576 -> [E][camera.c:205] skip_frame(): Timeout waiting for VSYNC
00:00:44.576 -> [E][camera.c:1270] esp_camera_init(): Camera init failed with error 0x20003

Done

The camera stream in the browser looks like this:













TLDR

The video quality is really bad, it has a lot of noise. And for me the camera module crashes rather often, even when using a stabilized power supply. Might be a software issue, or whatever. Having two modules with the same issue I'm about to drop the camera module to the waste bin and keep the ESP32 as micro-controller with Espruino.

3 comments:


  1. Bereit für mehrere IDE: Arduino und ESP-IDF
    USB-programmierbares industrielles ESP32 mit OLED-Display und DIN-Schienenmontage
    Es ist nicht nur ein ESP32 in einem Industriegehäuse, sondern wurde auf Schutz und Zuverlässigkeit ausgelegt.
    Besuchen Sie uns - https://norvi.lk/norvi-iiot-industrial-iot-node-esp/

    www.norvi.lk

    ReplyDelete
  2. I get the error
    00:00:44.576 -> [E][camera.c:205] skip_frame(): Timeout waiting for VSYNC
    00:00:44.576 -> [E][camera.c:1270] esp_camera_init(): Camera init failed with error 0x20003

    I have tried your instructions for this, but it does the same..

    Disconnect power
    Press and hold reset
    reconnect power
    Let go of reset button

    any other ideas?

    ReplyDelete