I’m trying to get Serial communication working over the ESP32-C3’s built in JTAG/CDC interface but can’t seem to get it working. I’m just using a basic program to print “Hello World” to the serial monitor repeatedy. I can upload the code without issues, but the serial print statements in my code are not showing up in the serial monitor.
When I upload the same code from Arduino IDE after setting the “USB CDC on Boot” option to “Enabled”, everything works perfectly. However, I can’t figure out how to enable this setting in platformio. Below is the platformio.ini file that I’ve been using, and that seems like it should work based on other posts I’ve read here:
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
upload_port = COM6
monitor_port = COM6
monitor_speed = 9600
board_flags =
-DARDUINO_USB_CDC_ON_BOOT=1
What do I need to add/change in my config file to get serial output to work properly? If it’s possible in Arduino IDE, I’m sure it’s possible using platformio, I’m just not sure what to do at this point. Any help would be greatly appreciated. Thanks.
4 Likes
I know this is a bit old, but I was struggling with this exact issue on my ESP32-C3-Devkit-M1. I went through a dozen posts over several days before I came across the solution.
For me, the critical addition appeared to be the change in monitor speed. I had been operating at 115200, but it did not work. The specific use of 460800 was noted here and that’s what made it work for me.
I hope this helps the next person!
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
upload_port = /dev/cu.usbmodem323101
monitor_speed = 460800
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
4 Likes
Thanks!
I found “ -D ARDUINO_USB_MODE=1” is the key of the problem.
Here is my code
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
upload_speed = 921600
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
Hi,
I have the same concern but I’m using the LILYGO T-DISPLAY-S3 with PlatformIO and framework ESP-IDF.
When I upload and monitor, the monitor doesn’t work.
Do you know why?
I tested the two ways:
Your program code will only output “Hello World” once at boot. It can very well be that PlatformIO only connects to the created serialport after it has already output the text. To make a fair comparison, you should at least print the text continously.
while(1) {
printf("Hello, world!\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
Please note that your build_flags
are invalid and will be ignored!
You need to indent the build_flags by 2 spaces:
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
Hi,
OK now doesn’t appear the warning but still not working.
I’m using the framework ESP-IDF.
These build_flags are for framework arduino and won’t effect esp-idf.
Please see USB Device Stack - ESP32-S3 - — ESP-IDF Programming Guide latest documentation
Hi,
I found the concern.
It was on menuconfing, I had selected Default: UART0, after change to USB CDC it start to works:
Thank you sivar2311
2 Likes