Skip to content

Spurious output in Serial Monitor after upload #927

Open
arduino/serial-monitor
#32
@per1234

Description

@per1234

Describe the problem

The first output printed to Serial Monitor after an upload is some "garbage" characters.

image

To reproduce

Equipment

  • Arduino board that uses the ATmega16U2 USB chip:
    • Arduino Uno
    • Arduino Uno Mini
    • Arduino Mega

Steps

  1. Upload a sketch to your board that prints to Serial:
    void setup() {
      Serial.begin(9600);
      Serial.println("hello world");
    }
    void loop() {}
  2. 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

c3adde5

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

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions