there is a screenshot in my post. I put 9600 in the serialmonitor and also Serial.begin(9600).
I figured out, that if i put a delay between Serial.begin and the Serial.println which is greater then 1099 ms it works well. but of course thats not what i want.
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
What happens if you remove the delay(), upload the code, wait a couple of seconds then press reset on the Arduino ? This will not solve anything but may provide more evidence of what is happening
Please confirm that you are using and Arduino Mega board
if i remove delay(), upload the code (squares appear), and wait for a couple of seconds and press the reset button on the arduino, the squares dissapear
This is what i found in another forum, does it make sense?
"This happens to everyone, but it is normal.
It is the same serial port for programming and serial monitor and cannot be opened for both at the same time.
The IDE automatically closes the port for the serial monitor while programming the Arduino and reopens when it finishes. This 800 ms is the time your computer needs to reopen the port, meanwhile all data send by Arduino are lost (this not happens if you reset the Arduino).
In the Arduino Nano (not Every) when the serial monitor opens the port, a reset is sent to the Arduino, but this does not happens with Every."
It’s commonplace that the first line or two of printing is corrupted like that. I’ve found that a delay of 200 fixes it. Why would a brief pause in setup() - even a full second as in your example - trouble you?
During debugging, just ignore the squares.
With your final product, use a terminal program; I've tested cutecom and minicom (both under linux) and the problem does not show.
I can not tell you what the root cause is.
Notes:
It's not related to upload. If you close serial monitor, disconnect the board, reconnect the board and start serial monitor again the same issue happens.
I suspect that the 'squares' are leftovers from the bootloader. Getting rid of the bootloader (you will need a programmer to upload your code) will probably also get rid of them.