DIY Projects

ESP32-CAM. Migrate CameraWebServer project from Arduino IDE to PlatformIO

how to build esp32-cam project platformio web-server-camera

The CameraWebServer sample for the ESP32-CAM was developed with the Arduino IDE. PlatformIO is much more fluid and efficient than the Arduino IDE. While waiting for the Pro version of the Arduino IDE to finally easily support other development boards (including the ESP32), PlatformIO is an alternative to absolutely test.


PlatformIO is not a code editor, is a tool-chain, ie a set of software tools available as a plugin for most (open) code editors. The best known is Microsoft’s Visual Studio Code (or VSCode). Before starting, you will therefore need to install the PlatformIO plugin on the code editor of your choice. For VSCode, follow the steps in this detailed tutorial.

If you haven’t already (if you’re new to ESP32 development boards), you will also need to install the development kit for ESP32 boards from manufacturer Espressif. The easiest way is to go through the Arduino IDE whatever your environment (Windows PC, macOS, Linux or Raspberry Pi OS). Follow the instructions in this tutorial

There are many ESP32-CAM development boards ( M5Stack , generic , TTGO …). Whatever development board you purchased, you must use the AI ​​Thinker ESP32-CAM sample and then choose the board from the source code before compiling and uploading. In fact, each manufacturer has opted for different pins from the ESP32 but the source code remains the same.

Retrieve the Camera Server source code from the ESP32 SDK installed on the Arduino IDE

A (single) sample application comes with the ESP32 SDK for the ESP-32 Ai Thinker Development Board. To find the folder, the easiest way is to go through the Arduino IDE.

Select the Ai Thinker ESP32-CAM development board from the Tools -> Development board -> ESP32 Arduino menu.

Then, open the CameraWebServer example from the File -> Examples -> ESP32 -> Camera menu.

To find the CameraWebServer project folder, you now just have to go to the Sketch menu -> Show sketch folder.

On macOS, It should be here

Macintosh HD ▸ Users ▸ Your Username ▸ Library ▸ Arduino15 ▸ packages ▸ esp32 ▸ hardware ▸ esp32 ▸ 1.0.4 ▸ libraries ▸ ESP32 ▸ examples ▸ Camera

Get the CameraWebServer project from GitHub

The other method is to go directly to retrieve the Arduino project file on GitHub. It is not possible to individually retrieve files from GitHub.

You will need to create a text file and paste the Arduino code for each file. To do this, click on raw , to display the code as text and retrieve it more easily.

Create an ESP32-CAM project with PlatformIO

Open VSCode or the code editor of your choice and open the PlatformIO home panel (normally it opens on startup). If not, you have a shortcut in the option bar in the lower right corner of the screen.

Click on Import Arduino Project

An important wizard opens:

Start the Import. Unfortunately, it is not (yet) possible to indicate the destination folder. PlatformIO automatically creates a project in the Documents -> PlatformIO -> Projects folder.

The name of the folder takes the form date_hour_esp32cam. You can rename it and move it later.

Prepare the ESP32-CAM board

The ESP32-CAM AI Thinker development boards, as well as most other development boards for that matter, do not come with a UART to serial converter. You will therefore need to purchase a separate FTDI module (UART / USB converter).

Everything is explained in detail in this tutorial, but here is the wiring diagram for the record.

Remember that whenever you want to upload firmware (compiled Arduino code) you need to connect the IO0 and GND pins together then plug in the power supply on the 5V pin.

After uploading a new firmware, disconnect the IO0 and GND pins then reset the board.

Edit the platformio.ini configuration file

To function, PIO uses a configuration file named platformio.ini located at the root of the project.

How the platformio.ini file works is explained in detail in this article.

The only (important) thing to change is the speed of the serial port because by default PIO uses a speed of 9600 baud.

Open the platfrmio.ini file and add the monitor_speed attribute to change the serial port speed to 115200 baud used in the source code of the example

monitor_speed = 115200

Check that the ESP32 module is in bootloader mode

Open serial monitor

Connect IO0 and GND together and power on the module by connecting the 5V power supply. Immediately you should receive the message waiting for download. The ESP32 module is ready to receive the new firmware.

> Executing task: pio device monitor <

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at
--- Miniterm on /dev/cu.usbserial-A50285BI  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

waiting for download

Configure the camera module and WiFi connection

Now open the CameraWebServer.ino file. Uncomment the camera module that corresponds to your board. Comment out all other boards (//).


Then enter the parameters for connecting to the WiFi network. Only one WiFi network can be configured.

In this project, there is no AP mode which allows later configuration of the WiFi parameters. It also means that if the password or the network identifier change, you will have to re-compile the firmware with the new parameters!

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

Upload the firmware to the ESP32-CAM

Everything is ready, click on the shortcut to compile and upload the firmware. What’s great about PIO is the speed with which the code is compiled (except the first time which is almost identical to the Arduino IDE).

Click on the Upload icon and let PIO do it.

Access the HTML interface

One Disconnect the IO0 and GND pins then disconnect / reconnect the 5V pin to restart the ESP32.

As the serial port is still connected to the board, we can follow the restart and directly recover the IP address. Hold down the Ctrl key on the keyboard along with the IP address of the ESP32-CAM module.

After authorizing access, you arrive directly at the interface you already know.

That’s it, nothing very complicated to use PlatformIO and VSCode.

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version