Skip to content

Spurious output in Serial Monitor after upload #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
per1234 opened this issue Mar 24, 2022 · 5 comments · Fixed by arduino/serial-monitor#32
Open
3 tasks done

Spurious output in Serial Monitor after upload #927

per1234 opened this issue Mar 24, 2022 · 5 comments · Fixed by arduino/serial-monitor#32
Assignees
Labels
criticality: low Of low impact topic: CLI Related to Arduino CLI topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Mar 24, 2022

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
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project topic: serial monitor Related to the Serial Monitor labels Mar 24, 2022
@fstasi fstasi added the criticality: low Of low impact label Mar 24, 2022
@woolseyj
Copy link

woolseyj commented May 4, 2022

I am seeing similar issues with version 2.0.0-rc6 of the IDE running on macOS 12.3.1 with an Arduino Uno WiFi Rev2 board. If I upload via the IDE, I get mostly garbled output in the Serial Monitor, however, if I upload via the arduino-cli tool, the output is correct whether it is viewed through the screen command or with arduino-cli monitor.

@cmaglie
Copy link
Member

cmaglie commented Feb 8, 2023

Reopening because the fix has been reverted: arduino/serial-monitor#39

We need to investigate this issue further and find a better solution.

@cmaglie cmaglie reopened this Feb 8, 2023
@per1234 per1234 removed the conclusion: resolved Issue was resolved label Feb 8, 2023
@ubidefeo
Copy link

ubidefeo commented Feb 9, 2023

@per1234
I have noticed that the number of characters is equal to the ones printed, but the line ending is missing.
For "hello world" it should be 12 chars, rather than 11 when println() is used.

I am wild-guessing here, but it could be that on some Windows (not int'l English systems) the character encoding plays a role (ISO-8859-12 vs 8859-1 or other encoding).
As I climb the conspiracy theory ladder I might say that how that particular text output view handles the text is to be further investigated.

The flow of operations is as follows, and it causes a chopping of the output printed, but it shouldn't grant the replacement of valid characters with squares.

  • upload recipe
    • reset board
    • upload
    • reset board
  • board is reset and runs through its setup, starting to print the string
  • serial monitor opens serial port, resetting the board again
  • board has not finished to print the output
  • new output from second reset is printed after anything that was already printed before

shortening the string might produce a different output

these are our findings for now

@SimonArrowhead
Copy link

SimonArrowhead commented Aug 27, 2023

@ubidefeo @per1234 I have the same issue but number of squares is deafferent than number of characters:

image

I tried switching system, keyboard and regional settings from polish to united states and number of squares was the same.
I switched arduino to usb 2.0 and squares disappeared but hello word was printed two time in serial monitor. Before uploading it to arduino and after uploading. The first one has some strange characters in it.

image

Tried this on my old mac (MacBook Air 13 inch, Early 2015, macOS Monterey 12.6.5) and at the beginning it looked like it was also printing two times in one run but after I ran it twice it worked just fine (printed just once every run without any squares). I supposed something was left in the memory from previous tests.

image

edit: delay (on windows 10) at the beginning of the setup fixed it for me. It looks like new run catches some data from previous run and it is unable to parse it.

image

When I change baud to 115200 it is able to parse it and with one run I get two hello worlds

image

If my analyze is not helpful please delete it. I'm new to arduino and above might be just normal behavior.

@aliphys
Copy link

aliphys commented Sep 1, 2023

I am able to partially replicate this issue on my laptop (Windows 11) with a Arduino Uno with IDE 2.1.1 as well as the latest nightly build

Steps

  1. Upload Blink.ino sketch. Wait at least two seconds.
  2. Upload the following sketch, provided in OP. Wait until hello world is printed in the Serial Monitor
  3. Repeat

Output with IDE 2.1.1

image

Zoomed in image on the Serial monitor. Red numbers indicate number of boxes. I cannot copy and paste into, the boxes shrink into a single � symbol.

image

On line 4, the Serial Monitor displays hhello world. This suggests that the board was going to print hello world, but then reset before finishing the output. The output is consistent with @ubidefeo 's hypothesis.

Output with Nightly Build Version: 2.2.1-nightly-20230901

image

The square boxes are more consistent in the nightly build, alternating between 30 and 31


Note: I am using a USB hub to connect the Uno to my laptop.
image

@Xayton Xayton assigned cmaglie and unassigned umbynos Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
criticality: low Of low impact topic: CLI Related to Arduino CLI topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants