How to upload the code to ESP32 CAM using Arduino or programmer

How to upload the code to ESP32 CAM How to upload the code to ESP32 CAM

In this quick tutorial, learn how to program or upload the code to ESP32CAM board through Arduino IDE with the help of Arduino UNO board, USB to TTL or FTDI converters.

Overview: What is ESP32CAM, how it works, What are its applications?

ESP32-CAM AI-Thinker is ESP32 based development board which is compact, small in size with integrated OV2640 camera. It also has few best features like GPIO pins to connect it with few modules, On board flashlight for camera picture quality and Micro SD card slot to read and save images and data.

The ESP32-CAM AI-Thinker board has integrated WiFi, Bluetooth and low-power BLE, with 2 high-performance 32-bit LX6 CPUs. It is designed in 7-stage pipeline architecture, with Hall sensor, temperature sensor and few other sensors on board. It’s main frequency setting ranges from 80MHz to 240MHz and computing power upto 600DIMPS(Dhrystone Million Instructions per Second). This board supports interfaces such as I2C/SPI/UART/PWM/ADC/DAC and camara units such as OV2640 and OV7670.

Fully compliant with WiFi 802.11b/g/n/e/i and Bluetooth 4.2 standards, it can be used as a master mode to build a standalone network controller or as a slave to other host MCUs to add network capabilities to existing devices.

It is suitable for smart home devices, industrial wireless control, wireless monitoring, QR codes identification, wireless positioning system signals, and other IoT applications. It is an ideal solution for prototype builds, and DIY projects.

ESP32-CAM pinout diagram:

Below is the image of ESP32-CAM AI-Thinker development board pinout

esp32 cam module pinout diagram

As you can see from the above image it has the support for 3.3v and 5Volts power supply input pins, Few GPIO pins, Tx and Rx pins, and few other pins.

Add external antenna to ESP32-CAM to increase the range(Optional)

It has an inbuilt antenna at the top as you can see from the above image, If the distance from the router to the board increases the signal strength decreases, as a solution to increase the range it has a support to add external antenna with IPEX connector. It is very easy just get an external antenna online or from store and plug it to the slot given on the ESP32-CAM board and realign the resistor beside it as shown in the below image.

how to attach external antenna to ESP32-CAM boardTo attach an external antenna first desolder the resister carefully as it is very small and resolder it in the opposite position as in the above image. If you feel soldering the resistor again is hard then just connect the points with solder without resistor. It works as long as the points are connected.

ESP32-CAM on board antenna works good with in 10-15 meters range and sometimes it may disconnect so get an external antenna for strong and stable connectivity and range.

Note: ESP32-CAM AI-Thinker board does not have a display, microphone, motion sensors, battery connector, built-in programmer, grove connectors, or function buttons, so you need to find solutions to these if you need them.

Related article: Interfacing OLED display with ESP32

How to Upload the code to ESP32-CAM using Arduino UNO

As we already learnt ESP32-CAM doesn’t have an inbuilt programmer to upload the code directly to it using Arduino IDE, so in this method we are using Arduino UNO board, which works as a programmer to upload the code to ESP32-CAM module instead of using converters such as FTDI programmer. Follow the below detailed steps to do so.

Components required:

  • ESP32CAM module
  • Arduino UNO
  • Few connecting wires.

Circuit Diagram to interface ESP32CAM with Arduino UNO

Connect the above required components according to the below circuit diagram.

Interfacing Esp32 CAM with arduino uno to upload the code

From the above schematic diagram you can see that there are two jumper cables connected one is for ESP32CAM connected between GND and IO0, and another is for Arduino UNO GND and RESET pins. ESP32CAM module is powered from the Arduino UNO 5v and GND pins connected to same on ESPCAM. The data transfer pins UOT and UOR from the ESP32CAM are connected to TX and RX pins of Arduino respectively.

Thats it for connections now you can connect the Arduino UNO board to PC and follow the below steps to upload the code.

Related post: Live stream with ESP32 camera module over internet with Face Recognition

Setting up Arduino IDE.

Download and install Arduino IDE on your PC, where Arduino UNO board is connected.

Now add ESP32 board manager by opening File -> Preferences and paste the below URL in the Additional boards manager URLs field.

https://dl.espressif.com/dl/package_esp32_index.json

Now open Tools -> Board:xxxxx -> ESP32 Arduino -> select : ESP32 Wrover module

Set the Tools menu settings as shown below

  • Board: “ESP32 Wrover Module” >
  • Upload Speed: “115200” >
  • Flash Frequency: “80MHz” >
  • Flash Mode: “Q10” >
  • Partition Scheme: “Huge APP (3MB No OTA/1 MB SPIFFS)” >
  • Core Debug Level: “None” >
  • Port: “COMx’ > According to your port connection

arduino ide tools settings for esp32cam module

Uploading the code: ESP32CAM webserver

As an example lets use the code from the ESP32 Examples library by opening File -> Examples -> ESP32 -> Camera -> CameraWebServer. An example ready made code will be loaded, you just need to change the WiFi credentials in the code and click on Upload button.

esp32 code uploading dots

After clicking on upload icon you can see the connecting dots as the above image, when you see them press the RST(Reset button) on the board which leads to code upload, with in few seconds you will see the message “Done uploading” on status bar of Arduino IDE means code uploaded successfully.

Now remove the jumper connection between GPIO1(IO0) and GND on ESP32 CAM module. Open serial monitor and set the baud rate to the value which we mentioned in the code i.e., 115200 and press RST button on the ESP cam board.

Now you can see the IP address of the webserver from where we can access the ESP32 CAM features, camera etc. as shown in the serial monitor image below.

esp32 cam webserver ip address Now Open the address in a web browser to access the ESP32CAM dashboard.

esp32-acam local server stream

How to Upload the code to ESP32-CAM using USB to TTL/FTDI programmer

In this method a special board is used to upload the code to ESP32 CAM named USB to TTL or FTDI converter. This boards will provide the connectivity between USB and UART interfaces. There are wide varieties of FTDI programmers are available with different output voltages like 3V, 5V.

In this method we are using FT232RL USB TO TTL Converter.

FTDI PROGRAMMER pinout diagram

Features and Specifications of FT232RL USB TO TTL Converter

This section mentions some of the features and specifications of the FT232RL USB to TTL Converter:

  1. Operating Voltage: 5V/3.3V DC
  2. Connector: Mini USB
  3. Max Current Draw: 5V – 500mA; 3.3V – 50mA
  4. Data transfer rates from 300 baud to 3 Mbaud (RS422, RS485, RS232) at TTL levels
  5. Fully integrated 1024 bit EEPROM storing device descriptors and CBUS I/O configuration
  6. 128 byte receive buffer and 256 bytes transmit buffer

Components required:

  • ESP32CAM module
  • FTDI Programmer/USB to TTL programmer
  • Few connecting wires.

Circuit Diagram to interface ESP32CAM with USB to TTL programmer

Connect the above required components according to the below circuit diagram.

INTERFACING esp32 cam WITH usb TO ttl FTDI CONVERTERAs you can see from the above schematic diagram GND and GPIO0 pins are connected with a jumper on ESPCAM board. ESPCAM board is powered from the VCC and GND from FTDI to 5V and GND respectively, The transfer and receive pins TX and RX pins from FTDI are connected to UOR and UOT pins of ESPCAM respectively.

Setting up Arduino IDE

This is same as the Above Arduino UNO method, Please refer the above method to setup Arduino IDE.

Upload and execute the Code:

This is same as the Above Arduino UNO method, Please refer the above method to setup Arduino IDE.

After uploading the code remove the jumper between GPIO0 and GND pins on ESPCAM.

Errors while uploading:

Failed to connect to ESP32: Timed out waiting for packet header

Solution: Check the wiring connections between the Arduino/FTDI programmer and ESP32CAM board, if everything is ok Press the RST button when dots are processing after clicking on upload icon.

Brownout detector was triggered

This error occurs for the following reasons: when the quality of the USB cable is poor, cable is very long for the data to reach, Voltage is not sufficient to ESP32 CAM board.

Solution: If there is voltage problem use external 5v power supply to power the ESP board as Arduino UNO sometimes cannot provide 5v , use short USB cable for data transfer.

14 comments
  1. FTDI TX should connect to ESP32 UOR (RX), not UOT (TX) and
    FTDI RX should connect to ESP32 UOT (TX), not UOR (RX)

    1. Hi Kerrence, This is regarding ESP32 CAM board. When down loading web camera , Some programme menu having
      Advance Settings as well as the picture frame with save button for still picture storing, and in some cases only the basic adjustment .My question how to get advance setting on the menu programme down loaded.
      Thanks.
      Ranraj

  2. I’m having a problem with an error that always mentions, “no serial data received”. I had been following the overall steps. Any suggestion?

  3. i got a problem !!
    onnecting…….._____….._____….._
    Chip is ESP32D0WDQ5 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: 24:a1:60:c5:50:84
    Uploading stub…
    Running stub…
    Stub running…
    Configuring flash size…
    Warning: Could not auto-detect Flash size (FlashID=0x0, SizeID=0x0), defaulting to 4MB
    Compressed 8192 bytes to 47…
    Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 993.0 kbit/s)…

    A fatal error occurred: Timed out waiting for packet header
    A fatal error occurred: Timed out waiting for packet header

    what’s wrong with me please ?

      1. same error but not solved by your reply..
        Failed to connect to ESP32: Timed out waiting for packet header

  4. hi
    i have problem in end step

    in windows Output after upload code show “Leaving…
    Hard resetting via RTS pin…”
    after btn reset show in Serial Monitor ”
    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1216
    ho 0 tail 12 room 4
    load:0x40078000,len:10944
    load:0x40080400,len:6388
    entry 0x400806b4

    [E][camera.c:1113] camera_probe(): Detected camera not supported.
    [E][camera.c:1379] esp_camera_init(): Camera probe failed with error 0x20004 “

      1. The camera modules are created by different manufacturers. These models can be selected in the initial part of the code loaded in Arduino IDE. For me, commenting the line #define CAMERA_MODEL_WROVER_KIT (line 11) and un-commenting #define CAMERA_MODEL_AI_THINKER (line 17) took care of the issue.

  5. Sketch uses 2594790 bytes (82%) of program storage space. Maximum is 3145728 bytes.
    Global variables use 56248 bytes (17%) of dynamic memory, leaving 271432 bytes for local variables. Maximum is 327680 bytes.
    esptool.py v3.0-dev
    Serial port COM3
    Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    Failed uploading: uploading error: exit status 2

    1. Have you tried pressing the Reset button on your board when you see:
      Connecting…….._____….._____….

      Also double check the wiring.
      The diagram I saw had TX-TX
      and RX-RX but;

      FTDI TX should connect to ESP32 UOR (RX), not UOT (TX) and
      FTDI RX should connect to ESP32 UOT (TX), not UOR (RX)

Leave a Reply

Your email address will not be published. Required fields are marked *