I'm working on a project where my Arduino (I'm using a Nano) will be connected to a computer via USB. On my computer I then run the Software that interprets the input from the Arduino. In my setup() function, I establish a Serial connection to the computer by calling Serial.begin(38400); Unfortunatley, I'm not sure of the way the begin() function works. Does it block until it has received some kind of signal from the PC? And if that be the case: Does it wait till my program has connected to it? Or is this not the case at all?
I need to figure this out, because after establishing the Serial connection I will do some more setup-stuff and it is crucial that the Arduino does not send any stuff out into the Ether while I'm still busy starting up my program on the PC. Starting it beforehand is only a temporary solution, but cannot be final.
While working with the Serial Monitor of the Arduino IDE I noticed that the messages I send seem to be only send after I opened the Monitor. But I'm suspicious and don't really trust it, so it would be really great if you guys could help me out with this, it would be much appreciated.
While we're already at it, I've got another question: What exactly is the use of Serial.flush()? I need to be sure my loop() doesn't start before all information was send, and currently just put a flush() at the end of loop(). But is this necessary? And if not: what IS the use of flush()?
Thanks in advance for your help