Starting Monitor automatically when program starts

My program prints important information to serial monitor immediately after establishing a serial connection. By the time I’ve started the Monitor, it’s already too late. It is not acceptable for this application to simply insert a delay before printing to Monitor (the boss cares a lot about time till TFT screen lights up).

How can I get the Monitor to start as early as possible, automatically, when program starts.

Note: The program was originally developed in Arduino IDE. There, it was possible to keep the serial monitor connected from on program upload to the next, so I could always catch the initial output.

1 Like

Is Upload and Monitor too slow also?

1 Like

I didn’t even realize that was there!!
It is almost fast enough, but not quite. If I insert delay(200) soon after the Serial connection is established,I can see everything I need to. I think that will suffice for my current situation.

Where does this script reside?
Is it possible to add the Monitor startup functionality to my Debug task?

1 Like

:slight_smile:

I don’t think it’s a script, but a variation of the pio run command… specifically pio run -e your_env -t monitor will will auto-launch the serial monitor if the build is successful.

1 Like

How would I accomplish this from the IDE (VSCode)?

You mean in relation to the debug task? I don’t know… the above mentioned behavior is the Upload and Monitor task.

btw, if you do an upload with the serial montior open, it seems to reload quicker… but that could be smoke and mirrors.

1 Like

You need your program to wait until the USB monitoring is ready, like this:

Serial.begin(9600);
while (!Serial);

Don’t forget to remove the second line in your final code, otherwise your program won’t start.

Please google while (!Serial) to learn more.