XIAO ESP32S3 Serial.print() commands when no USB cable connected

On the ESP32S3 Sense, if I populate a program with a lot of Serial.print() commands, the program wont run if the USB cable is not plugged in and with the Serial monitor open.

I can work around this by disabling all Serial. commands thus;

#define DEBUG false //set to true for debug output, false for no debug output
#define DEBUG_SERIAL if(DEBUG)Serial

And then changing all the Serial.prints() to

DEBUG_SERIAL.print(F("Waiting "));

The program is a working GPS tracker using an SX1278 LoRa module.

If I want to see the Serial.print() commands I just set DEBUG to true.

Is there away around this fix that would allow all the Serial.print() commands to stay in place as is ?

Hi there,
Without seeing any code,
Do you have the !(while) serial thing in there, comment it out and leave the rest.
GL :slight_smile: PJ

I found the problem.

There were quite a few Serial.print() commands and to keep it all in order, after a block of Serial.print() commands I added a Serial.flush() commands.

Serial.print() will work OK when there is no USB cable connected and Serial monitor open.

However when there is no USB cable connected and Serial monitor open a Serial.flush() command will hang the program.

1 Like