I have tried almost everything to get even a simple program to run on an ESP32-CAM (AI Thinker). Anything that I compile and run with Arduino IDE will work fine, including a streaming web server as found in the ESP32-CAM tutorial. When troubleshooting this problem I created a simple sketch that prints out successive numbers continuously. It runs fine when compiled under Arduino IDE, but not in PlatformIO. The code compiles and uploads using platformio, but just doesn’t run! Note that this sketch only uses the <Arduino.h> include, so there is nothing special going on here, i.e., no library inconsistencies to worry about.
The platformio.ini file is:
[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
monitor_speed = 115200
There is no problem with any code that I have used, because it all works when compiled and uploaded by Arduino IDE.
Also, the number-printing code works on platformIO when uploaded to a DoIT ESP32 DEVKIT V1 board. It’s just the ESP32-CAM board on PlatformIO that doesn’t run (although it compiles and uploads fine).
So there’s no problem with the boards, or code, or serial monitor settings. I used two different ESP32-CAM boards with the same results, both work with any code compiled in Arduino, but not on platformIO.
I did a complete uninstall / re-install of platformio to no avail. All the above suggests that there is a problem with the esp32cam board profile in platformio. As I want to do many projects with the CAM board using platformio I’m hoping there is a solution.
Is there something I can try to solve this???
Partial Success. I found a fix from the PlatformIO forum, which was to turn-off RTS and DTR control lines on the serial port (I’m using the ESP32-CAM MB for uploading). The following lines are added to the platformio.ini file:
monitor_rts = 0
monitor_dtr = 0
According to the PIO forum,
Well a few ESP32 boards have a mechanism that connects RTS/DTR to the EN/GPIO0 lines – if these are driven the wrong way when the serial monitor opens, it might shut down the ESP32.
This fix allowed my program that prints sequential numbers to the serial monitor to work, but the camera web server program does not work yet completely. It prints the sensor readings from the BME280 sensor, but the camera’s web page will not load.
It could be due to a library incompatibility because I used a different version of ESPAsyncWebServer in PlatformIO. The PlatformIO registry did not have the same version as the one in Arduino IDE. I’ll have to connect those libraries manually.
I will work on this issue and report back to this post.
FYI: I found the fix in the following link. There is more info and links in this web page that may be helpful.
https://community.platformio.org/t/noob-stuck-on-esp32-cam-mb-with-pio-vscode/19117/8
Hi.
Thank you for providing those details.
I didn’t know about that issue with the ESP32-CAM and platformio.
Then, let us know your findings
Regards,
Sara
SUCCESS! I managed to get the software running after erasing the flash memory before uploading and specifying the same Arduino libraries. In the Arduino IDE in the “Tools” menu, I had enabled the “Erase All Flash Before Sketch Upload” option. PlatformIO erases sections of the memory, but I don’t believe it is erasing it completely. I ran the following command in the PIO CLI terminal to completely erase the flash before uploading:
pio run –target erase
This assumes that the correct upload/monitor serial port is selected in VS Code.
Also, I manually included the libraries that Arduino IDE was using by adding the following lines in my platformio.ini file:
;libraries
lib_compat_mode = strict
lib_ldf_mode = chain
lib_deps =
mathieucarbou/ESPAsyncWebServer @ 3.3.22 ;same as Arduino IDE
mathieucarbou/AsyncTCP @ ^3.2.14 ;same as Arduino IDE
sparkfun/SparkFun BME280 @ ^2.0.9
There is no upload_flag option available in platformIO to erase the flash. However, if a custom upload command is used then erasing all the flash can be specified as an option. To do this:
In the platformio.ini file, specify:
upload_port = COM7 ;of course, specify your own port and speed
upload_speed = 460800 ;same as Arduino IDE
upload_protocol = custom ;this option is required in order to use a custom upload command
upload_command = python C:\Users\name\.platformio\packages\tool-esptoolpy\esptool.py –chip esp32 –port “$UPLOAD_PORT” –baud “$UPLOAD_SPEED” –before default_reset –after hard_reset write_flash –erase-all 0x1000 “$BUILD_DIR/bootloader.bin” 0x8000 “$BUILD_DIR/partitions.bin” 0x10000 “$BUILD_DIR/firmware.bin”
Replace C:\Users\name\.platformio\packages\tool-esptoolpy\esptool.py with the specific location of your esptool.py file. The above is for a typical Windows 10 installation. The option that erases the flash is
write_flash –erase-all
This method also allows using all the available options for esptool.py, as platformIO does not seem to support them all. I added the options necessary to make the platformIO build equal to the Arduino build. For reference/comparison, this is Arduino IDE’s build command for my project:
esptool_py\4.6/esptool.exe” –chip esp32 –port “COM7” –baud 460800 –before default_reset –after hard_reset write_flash -e -z –flash_mode keep –flash_freq keep –flash_size keep 0x1000 “C:\Users\bruce\AppData\Local\Temp\arduino\sketches\28224D92ACC168C9E58C8DE2AD4BCBA9/Video_Streaming_Web_Server_Sensor_Readings_Arduino.ino.bootloader.bin” 0x8000 “C:\Users\bruce\AppData\Local\Temp\arduino\sketches\28224D92ACC168C9E58C8DE2AD4BCBA9/Video_Streaming_Web_Server_Sensor_Readings_Arduino.ino.partitions.bin” 0xe000 “C:\Users\bruce\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7/tools/partitions/boot_app0.bin” 0x10000 “C:\Users\bruce\AppData\Local\Temp\arduino\sketches\28224D92ACC168C9E58C8DE2AD4BCBA9/Video_Streaming_Web_Server_Sensor_Readings_Arduino.ino.bin”
Also, if there are still problems using ESPAsyncWebServer, then from the GitHub page of mathieucarbou/ESPAsyncWebServer 3.3.22, ( https://github.com/mathieucarbou/ESPAsyncWebServer ) read the following:
====================================================================================
Important recommendations
Most of the crashes are caused by improper configuration of the library for the project. Here are some recommendations to avoid them.
- Set the running core to be on the same core of your application (usually core 1)
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
- Set the stack size appropriately with
-D CONFIG_ASYNC_TCP_STACK_SIZE=16384
. The default value of16384
might be too much for your project. You can look at the MycilaTaskMonitor project to monitor the stack usage. - You can change if you know what you are doing the task priority with
-D CONFIG_ASYNC_TCP_PRIORITY=10
. Default is10
. - You can increase the queue size with
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
. Default is64
. - You can decrease the maximum ack time
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000
. Default is5000
.
I personally use the following configuration in my projects because my WS messages can be big (up to 4k). If you have smaller messages, you can increase WS_MAX_QUEUED_MESSAGES
to 128.
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000 -D CONFIG_ASYNC_TCP_PRIORITY=10 -D CONFIG_ASYNC_TCP_QUEUE_SIZE=128 -D CONFIG_ASYNC_TCP_RUNNING_CORE=1 -D CONFIG_ASYNC_TCP_STACK_SIZE=4096 -D WS_MAX_QUEUED_MESSAGES=64
=====================================================================================
The above Defines are included in the platformio.ini file with the option:
build_flags = -D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000
for example.
Hi.
Thanks for sharing such a detailed solution.
Definitely might be useful for other readers with similar issues.
I’m still not sure what’s the reason why it doesn’t work out of the box for you.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara