glv
September 10, 2022, 12:57pm
14
Hello @maro ,
Arduino Code
void setup() {
Serial.begin(9600);
Serial.println();
Serial.println("0123456789ABCDEF");
}
void loop()
{
}
Processing Code
// Example by Tom Igoe
import processing.serial.*;
int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // The serial port
void setup() {
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[4], 9600);
myPort.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
//myString = myPort.readStringUntil(lf); // glv - I commented this
myString = null;
}
void draw() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
//println(myString); // glv - I commented this
//******************************************
// glv - I added this:
int sl = myString.length();
println(sl);
for(int i = 0; i < sl; i++)
print(hex(myString.charAt(i), 2));
println();
//******************************************
}
}
}
Console output directly after:
Uploading Arduino code to Arduino Uno R3
Running Processing 4.0.1 sketch the first time
The zeroes are not there after an upload followed by a USB disconnect\connect (power off\on) of the board and then running the Processing sketch.
The zeroes are not there on subsequent runs of of the Processing sketch which resets the Arduino.
Related:
This is what I see: This only seems to happen right after an upload, only on a UNO, using IDE 2.0 RC5. But not after a reset or when I unplug and replug the USB. While it means little functionally, it is cosmetically ugly.
opened 08:23AM - 24 Mar 22 UTC
topic: code
type: imperfection
topic: serial monitor
criticality: low
### Describe the problem
The first output printed to Serial Monitor after an … upload is some "garbage" characters.
![image](https://user-images.githubusercontent.com/8572152/159872636-d8e0c920-e628-4c91-9c91-65611fcfcaaa.png)
### 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`:
```cpp
void setup() {
Serial.begin(9600);
Serial.println("hello world");
}
void loop() {}
```
1. Open the "**Serial Monitor**" view.
🐛 The output starts with some unexpected content:
```text
□□□□□□□□□□□hello world
```
### Expected behavior
Serial monitor output always reflects the data sent by the board.
### Arduino IDE version
2.0.0-rc5-snapshot-4de7737
### Operating system
Windows
### Operating system version
10
### 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 spurious output still occurs even if you add a delay before the print, so it is not a matter of timing from initialization as is sometimes the cause of corrupted serial output.
---
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
### Issue checklist
- [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-ide/issues?q=)
- [X] I verified the problem still occurs when using the latest [nightly build](https://github.com/arduino/arduino-ide#nightly-builds)
- [X] My report contains all necessary details
Related but not exactly ? the same issue…
Consider opening an issue that is specific to your observations.
:)
1 Like