I have seen a few different ways to 'wait' for the Serial monitor to be ready, from simple delays after the begin to a couple of explicit functions. Here is my favourite, who has some other ideas?
Serial.begin(115200); // Remember to set Serial monitor to 115200 as well
while (!Serial && (millis() < 5000)); // Wait up to 5 secs for Serial to be ready
if (!Serial) {
for (;;) {} // failed, loop forever
}
else
Serial.println("Serial READY");
That construct is only useful for boards / processors whose main Serial port is native USB. If it's a UART followed by a discrete UART / USB converter, then it's pointless.
Is this way longer than necessary? I guess I am an A-type when it comes to startup/reboot delays... I go so far as to remove the boot loader from a final final deployment.
It's not like you are giving a human enough time to fix anything that might need it.
use precompiler defines for the platform and use exactly that whats needed for the particular platform. Either none, wait, !Serial or what ever is needed.
Just remember to remove that if the project is independently powered without connection to PC USB. I can't even count how many times someone has showed up here with a (native USB Arduino) project that stopped working as soon as they used an extern power supply without a PC connection.
I do not think that you will ever find a list of defines that are used during the compile process. The system is flexible and allows everybody to build board packages to their liking.
I think that your best bet is to analyse the verbose output of the compiler when you're compiling for the specific board. The defines depend on the core, the board and all kind of options that you have selected before compiling.
No waiting. It just checks over and over grabbing bytes as they come available. When it sees a '\n', or whatever else the user chooses, it passes back the competed c string for the user to process.
Think about it. How happy would you be if you hired someone by the hour to do job x, and they spent 99.9999% of the time loafing about smoking cigarettes?
You have to purge the idea of stopping things from your mind.
I do set timers, so when mrs employee comes by, they can check to see if it's time to do something. Although I don't think this code uses any.
Ok, sorry but that has nothing to do with the Topic, this is about the setup code waitig to make sure the Serial port is ready. Your code sounds interesting for other uses though, what is the nae of the lbrary?
Oh! I missed the point entirely. Sorry about that. I'm so used to people asking to stop the processor. Oh well, it was fun while it lasted.
And yes, this waiting for Serial can be a pain. I don't know if you ever run Teensys, but their serial stuff seems to run on it's own timeline. That can make debugging a real trick.