Programming ESP32-CAM With ESP8266

Introduction: Programming ESP32-CAM With ESP8266

So here is the situation. You have ordered an ESP8266 and excited about the possibility of having an ESP32 with a camera for less than 10$ you have added the ESP32-CAM to your basket. Now your order has just been delivered and everything is just fine. Except it's not. In your excitement you overlooked the fact that the ESP32-CAM does not have a USB port and you need a FTDI programmer to program it. Unfortunately you don't have a FTDI programmer at hand. So what can you do? If you are like me and you hate waiting, you can always use your ESP8266 board to do the trick.

Step 1: Connecting the Pins

First of all, we connect the Enable pin (labeled "EN") of the ESP8266 to the ground (labeled "GND") as shown by the yellow connection. This keeps the ESP8266 from turning on.
Then we connect the RX, TX, 3V3 and GND from the ESP8266 to the ESP32-CAM.
Note that unlike using a FTDI programmer where we swap RX and TX, here we connect the ESP8266 TX to the ESP32-CAM TX (as denoted by the red connection) and the ESP8266 RX to the ESP32-CAM RX (as denoted by the blue connection).
Important: To be able to upload code to the ESP32-CAM and not just communicate with it, you have to connect GPIO0 on the ESP32-CAM to the GND on the board (as denoted by the orange connection).

Step 2: Testing With an Example From the Arduino-esp32 Library

Note: As a prerequisite to this step you need to have Arduino IDE installed as well as the ESP32 add-on.

After you've successfully connected all the pins from the first step it's time to plug the USB cable into the ESP8266 and into your PC.

First, you have to locate which port is the serial connection to the ESP8266, and by extension the ESP32-CAM, established on. Then go to Tools > Port in the Arduino IDE and select that port.
You also have to choose a board by selecting Tools > Board > ....
Most Chinese ESP32-CAM boards correspond to "AI Thinker ESP32-CAM" but yours may be different so make sure you select the right option here.

Now let's open an example from the esp32 library. To do this go to File > Examples > ESP32. There my favorite example (and the most impressive one) is the Camera > CameraWebServer.

After the example has opened locate the line where it says "Select camera model". There you should comment all models except the one that comes with your ESP32-CAM. Again on most Chinese ESP32-CAM boards with OV2640 camera that is the line:

#define CAMERA_MODEL_AI_THINKER<br>

Then you should change the lines

const char* ssid = "*********";
const char* password = "*********";

to contain the ssid and password for your Wi-Fi.

After that upload the code to your board by clicking the Upload button (looks like a right arrow). Don't worry if the compiling is taking a lot of time. After compiling you should see output from esptool.py printed in red showing that connection was established and if everything is alright showing upload progress.
After you see the lines

Leaving...
Hard resetting via RTS pin...

you can safely remove the connection between GPIO0 and GND on the ESP32-CAM to exit writing (uploading) mode so that you can run your code and communicate freely using the serial connection through the ESP8266.
Use Tools > Serial Monitor to open the serial monitor in Arduino IDE. Set the baud rate to 115200 baud on the dropdown next to the "Clear output" button, then push the RST button on your ESP32-CAM. You should see some output from your board and after a few seconds something similar to

WiFi connected
Starting web server on port: '80'
Starting stream server on port: '81'
Camera Ready! Use 'http://192.168.100.7' to connect

should be printed on the serial monitor window. Then just open the link in any modern browser and enjoy your ESP32-CAM Video Streaming Server :).

Be the First to Share

    Recommendations

    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest
    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge

    10 Comments

    0
    Vijay4567
    Vijay4567

    10 months ago

    Leaving...
    Hard resetting via RTS pin...Mine showing as following, don't understand and serial monitor blinking

    ets Jun 8 2016 00:22:57
    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:9720
    ho 0 tail 12 room 4
    load:0x40080400,len:6352
    entry 0x400806b8

    After Leaving...
    Hard resetting via RTS pin... I pulled the loop to GPIO0 other connection left as it is and pushed the RESET button...
    what is possibly wrong?

    0
    Svilen Grigorov
    Svilen Grigorov

    Reply 10 months ago

    What your ESP32-CAM is saying with "rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)" is just that it has been restarted. As long as you see the "Wi-Fi connected\n Starting web server..." text after that, everything should be fine. If there is any problem, please explain it in more details and I will try to help you.

    0
    Ghoond
    Ghoond

    Reply 1 day ago

    Mine also like that, even after push the reset button only showing rst:0xc (SW_CPURESET), boot:0x13 (SPI_FAST_FLASH_BOOT)
    not even showing IP Address

    0
    IS
    IS

    Question 23 days ago


    esptool.py v2.6
    Serial port COM3
    Connecting........_____....._____....._____....._____....._____....._____.....____An error occurred while uploading the sketch
    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

    I have followed you every step of the way. But it's still wrong, is there any way to fix it?

    0
    Mohammed El-amineB
    Mohammed El-amineB

    2 months ago

    Thanks for the article.
    I tried to program my ESP32-CAM, but I get this error :
    A fatal error occurred: This chip is ESP8266 not ESP32. Wrong --chip argument?


    Did I miss something ?

    0
    Svilen Grigorov
    Svilen Grigorov

    Reply 8 weeks ago

    Tbh, I'm not sure what is happening there. My best guess would be that the ESP8266 turns on and is not transferring the signal to the ESP32. Are you sure that the ESP8266 is not turning on? Is the EN pin connected to the GND pin on the ESP8266 as denoted by the yellow connection?

    0
    Mohammed El-amineB
    Mohammed El-amineB

    Reply 8 weeks ago

    That's what's happening actually, I used a led blink code to test the ESP8266 and when I connect everything like your instructions, the led starts blinking.
    But I tried with an Arduino Uno and it worked.

    0
    jhklaxmi
    jhklaxmi

    5 months ago

    A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0xC4)

    0
    jhklaxmi
    jhklaxmi

    5 months ago

    Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "AI Thinker ESP32-CAM, 240MHz (WiFi/BT), QIO, 80MHz"
    Sketch uses 2594098 bytes (82%) of program storage space. Maximum is 3145728 bytes.
    Global variables use 56280 bytes (17%) of dynamic memory, leaving 271400 bytes for local variables. Maximum is 327680 bytes.
    esptool.py v3.0-dev
    Serial port COM4
    Connecting........_____....._____....._____....._____....._____....._____....._____
    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet content
    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet content
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.