Description
Describe the problem
The first output printed to Serial Monitor after an upload is some "garbage" characters.
To reproduce
Equipment
- Arduino board that uses the ATmega16U2 USB chip:
- Arduino Uno
- Arduino Uno Mini
- Arduino Mega
Steps
- Upload a sketch to your board that prints to
Serial
:void setup() { Serial.begin(9600); Serial.println("hello world"); } void loop() {}
- Open the "Serial Monitor" view.
🐛 The output starts with some unexpected content:
□□□□□□□□□□□hello world
Expected behavior
Serial monitor output always reflects the data sent by the board.
Arduino IDE version
Original report
2.0.0-rc5-snapshot-4de7737
Last verified with
Operating system
Windows
Operating system version
- 10
- 11
Additional context
The number of □
in the demonstration matches the number of characters that are printed by the sketch.
The spurious output does not occur when the output is triggered by resetting the board, so it is specific to the upload operation.
The issue does not occur when using Arduino IDE 1.x
I have only been able to reproduce this issue with the Arduino boards that use an ATmega16U2 USB to serial adapter chip.
I could not reproduce it when using boards with other USB interfaces:
- Native USB (Leonardo, Nano 33 IoT)
- FTDI FT232R (Nano, Pro Mini)
- WCH CH340 (3rd party boards)
Originally reported at https://forum.arduino.cc/t/serial-monitor-contains-garbage-after-upload/972312
Additional reports
- https://forum.arduino.cc/t/serial-monitor-confusion/1111552
- https://forum.arduino.cc/t/serial-monitor-prints-boxes-when-opened/1102169
- https://forum.arduino.cc/t/boxes-before-0-in-serial-monitor/1126046
- https://forum.arduino.cc/t/2-1-1-spits-out-garbage-to-serial-monitor-then-proper-output/1152950
- https://forum.arduino.cc/t/ide-2-adruino-uno-serial-monitor-prints-garbage-when-sketch-starts/1299299
- https://forum.arduino.cc/t/squares-appearing-in-serial-monitor/1300361
Related
Workaround
Add a delay before the first Serial.print
(etc.) call:
void setup() {
Serial.begin(9600);
delay(2000);
}
void loop() {
Serial.println("hello");
delay(1000);
}
ⓘ The choice of 2000 ms for the delay in the snippet above is somewhat arbitrary. You might find that a shorter delay will also serve (1000 ms works for me). Or you might even find that 2000 ms is not sufficiently long. You can do some experimentation to determine the shortest delay that will reliably prevent the garbage output on your system.
Issue checklist
- I searched for previous reports in the issue tracker
- I verified the problem still occurs when using the latest nightly build
- My report contains all necessary details