waiting for serial port to open; Arduino IDE

radolf
Posts: 2
Joined: Thu Mar 23, 2023 6:46 am

waiting for serial port to open; Arduino IDE

Postby radolf » Thu Mar 23, 2023 6:52 am

Is there a way for the ESP32 (S3) to wait until a serial port/monitor has been started? I’m using the Arduino IDE. On non-ESP32 boards, I’ve used something like this:

while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("*****************************************************");
Serial.println(" Com port is open");

This code doesn’t work with the ESP32. Any other suggestions? I need to print out a message to the serial port, but need to wait until the serial port and terminal/console are open/ready. Since the code currently isn’t able to wait, I lose the first few serial port prints as it takes a few seconds to manually open up the serial monitor program.

User avatar
corz.org
Posts: 80
Joined: Fri Feb 03, 2023 10:44 pm
Location: Aberdeen
Contact:

Re: waiting for serial port to open; Arduino IDE

Postby corz.org » Fri Mar 24, 2023 12:27 pm

Why not just have it wait until it receives serial input?

radolf
Posts: 2
Joined: Thu Mar 23, 2023 6:46 am

Re: waiting for serial port to open; Arduino IDE

Postby radolf » Sat Mar 25, 2023 6:12 pm

I need to output to the serial monitor first before receiving input. I have a while(serial.available) in the code which works fine, but the Serial.println prior to that is dropped, because the connection isn't open at that point.

User avatar
corz.org
Posts: 80
Joined: Fri Feb 03, 2023 10:44 pm
Location: Aberdeen
Contact:

Re: waiting for serial port to open; Arduino IDE

Postby corz.org » Sun Mar 26, 2023 2:52 am

I don't know of any way to do this on ESP32.

Why do you need to output data to the serial line before it receives input? Just curious. And why not just have the serial line connected when it boots, so you can see all output?

At any rate, what you seek might be possible on the new chips with built-in USB UART, but I haven't tested this.

blahblah
Posts: 1
Joined: Sun Sep 17, 2023 8:55 am

Re: waiting for serial port to open; Arduino IDE

Postby blahblah » Sun Sep 17, 2023 9:01 am

My resolution was to wait for 5 seconds as I couldn't find another way

void setup() {
Serial.begin(115200);
delay(5000);
Serial.println("Ready.");
...
}

Who is online

Users browsing this forum: Majestic-12 [Bot] and 75 guests