ESP32-C3 framework arduino Serial.print USB

Hello,
I can’t find how to use USB to send messages (Serial.print () → framework arduino).
I read that with “menuconfig” you had to add:
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG

I also read that “menuconfig” was only accessible with the ESP-idf framework.

Is there a solution to send by USB with the arduino framework?

It works in arduino V2 IDE, but I prefer to use platformIO.

Thank you for your answers.

Whether the Arduino-ESP32 framework uses hardware UART or USB-CDC as Serial depends on the value of the macros

So ARDUINO_USB_MODE can either be 0 or 1 (for either hardware USB-CDC or TinyUSB) but ARDUINO_USB_CDC_ON_BOOT must be 1.

Some board = ... selections preselect the value for you,

while others do not.

So as a first try, add

board_flags =
   -DARDUINO_USB_CDC_ON_BOOT=1

in the platformio.ini and reupload the firmware.

It works, thanks.
Quick, clear, explained, effective response.
Thanks.

Once I set the flags in my pio.ini file I am unable to reflash the same project.
“-DARDUINO_USB_MODE=1”,
“-DARDUINO_USB_CDC_ON_BOOT=1”

I have to flash a different project that does not have the two flags from above. Is there a workaround or any clean way to leave these in and retain the ability to reflash the project?

I am pretty sure that you can flash a new sketch without these flags. However, the Serial object will then no longer output via the native USB port but via the UART pins. Therefore you will not see the serial output.

You can test it with a sketch that flashes an LED instead of Serial.println().

See also ESP32-S3 native USB interface and Serial Monitor missing first messages - #10 by sivar2311

Thank you for the quick response!
The chart you linked is helpful but I am having trouble reading it. Is there a comb0 of the two values that will let me flash my device and retain usb debugging? I have never run into this before. It is only ever an issue with my Lilygo AMOLED board. I figure it has to do with the pins that go to the screen or something.

To be able to give an exact answer, it is necessary to know the board used.

The two macros control which peripheral is used for the Serial object (UART or native USB).