Mysterious characters at Monitor page

Sometimes there are few lines of extra characters above on the Arduino Monitor page. They may look like remnants from previous runs, more or less garbled.

How to prevent them coming there?

This is not a major problem, not even a serious nuisance, but I am curious how they end up being there. When I send the output of Arduino to a host computer via usb for automatic analysis, and the host finds extra characters at the start, there is some extra work to bypass them. Better them not being there at all.

Thanks in advance!

The Serial-to-USB chip has a small buffer on it. When the ATmega328 resets, there's no way that buffer can get reset.

So when you connect the board to your PC, the characters left in the Serial-to-USB buffer gets emptied.

[quote author=James C4S link=topic=138864.msg1043443#msg1043443 date=1356367004] The Serial-to-USB chip has a small buffer on it. When the ATmega328 resets, there's no way that buffer can get reset.

So when you connect the board to your PC, the characters left in the Serial-to-USB buffer gets emptied. [/quote] Thanks! I'll try to disconnect and then reconnect Arduino to see, whether the garbled characters disappear. Merry Christmas!

Probably not. Keep in mind that when you connect power the code starts running. Then when you open the serial monitor it restarts the ATmega328. So if the code sends characters at power up, you'll still see the garbage.

One way to stop it is to include "while (!Serial.available());" at the end of setup(). Then the code Will wait until the PC (you) send something over serial before starting.

Edit: Oops.

I use that method on many of my sketches to announce what they are may maybe and to prompt the user to hit any key before leaving the setup function:

void setup()
{
  Serial.begin(57600);
  Serial.println ("Hit a key to start");     // signal initalization done
  while(Serial.available() == 0){}
  // other stuff needed to do in setup
}

Lefty

[quote author=James C4S link=topic=138864.msg1043539#msg1043539 date=1356374172] Probably not. Keep in mind that when you connect power the code starts running. Then when you open the serial monitor it restarts the ATmega328. So if the code sends characters at power up, you'll still see the garbage.

One way to stop it is to include "while (!Serial.available);" at the end of setup(). Then the code Will wait until the PC (you) send something over serial before starting. [/quote] Ok, now I understand that better. The idea to test Serial.available() sounds good. It also prevents the program doing perhaps astounding things before the monitor is open and the programmer is well aware of the execution (e.g. opening , writing sd-files and leaving them open at reset). Thanks Retrolefty also.

"while (!Serial.available);" try calling the function, not just testing to see if the function pointer is or isn't zero (I pretty much guarantee it'll be non zero)

Did you mean while ( ! Serial.available() ); ?

Edit: Argh! Beaten by AWOL!

No problem :). It is sympathetic that also very experienced programmers make such errors sometimes. Anyhow, after this intermezzo it is easier to remember, when to to have those parenthesis and when not. Thanks :wink: