Skip to content
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

Serial Monitor sends spurious data #375

Closed
per1234 opened this issue May 16, 2021 · 15 comments · Fixed by #1703
Closed

Serial Monitor sends spurious data #375

per1234 opened this issue May 16, 2021 · 15 comments · Fixed by #1703
Assignees
Labels
conclusion: resolved Issue was resolved 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 May 16, 2021

Describe the bug

🐛 Spurious data is sent by the Serial Monitor over the connected serial port.

To Reproduce

Equipment

  • One of the following Arduino boards:
    • Arduino Uno
    • Arduino Mega
    • Arduino Due

Steps

  1. Paste the following simple serial echo sketch into the Arduino IDE:
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
      if(Serial.available()){
        Serial.println(Serial.read());
      }
    }
  2. Upload to the Arduino board.
  3. Open Serial Monitor
  4. Set the baud rate menu to 115200.

🐛 The Serial Monitor's output field shows unexpected data is being received by the Arduino board and echoed back by the sketch. Something like this:

240
240
240
240
240
240

... and so on

Expected behavior

Data is only sent over the serial port by Serial Monitor when the user sends it via the input field.

Desktop

  • OS: Windows 10
  • Version: Version: 2.0.0-beta.6-nightly.20210515
    Date: 2021-05-15T03:10:15.375Z
    CLI Version: 0.18.2 alpha [7b5a22a4]

Additional context

I have only been able to reproduce this on my Arduino Mega, Arduino Uno, and Arduino Due (via Programming Port only). Based on the commonality of their ATmega16U2 USB chip, I expected to also be able to reproduce it on my Arduino Uno Mini LE, but I was not able to.

On my Leonardo and Micro boards, the RX LED flashes at 1 Hz while the Serial Monitor is connected, indicating unexpected data is being received, but I don't get any output from the echo sketch.


I notice that the ~1 Hz frequency of the spurious data appears to match the frequency of the notification displayed repeatedly after the board is disconnected while Serial Monitor is open (#314):

Reconnecting Arduino Mega or Mega 2560 to COM18 in 1 seconds...

This makes me wonder if already open ports are constantly being reopened at 1 Hz the whole time Serial Monitor is running. Further evidence supporting this is that I get the RX blink on the Leonardo whenever I do a manual StreamingOpen gRPC request to the port.


It appears the data is sent at 115200 baud.


As reported at at #1297, changing the selection in the line ending menu triggers the immediate sending of additional spurious data in addition to the regular periodic data reported above.

I notice the same happens when you toggle the "Toggle Autoscroll" or "Toggle Timestamp" icons.

None of these should result in any data being sent to the board.


Originally reported at: https://forum.arduino.cc/t/serial-monitor-sends-random-f0/850819

@cmaglie cmaglie removed the type: bug label Sep 16, 2021
@rsora rsora added type: imperfection Perceived defect in any part of project topic: serial monitor Related to the Serial Monitor labels Sep 22, 2021
@per1234 per1234 added the topic: code Related to content of the project itself label Oct 25, 2021
@NazariiBoichuk
Copy link

I faced similar problem with Arduino Due on Arduino IDE 2.0.
The problem disappeared when I used usual Arudino IDE 1.8.16.
More about my issue here:
https://forum.arduino.cc/t/serial-read-and-serial-available-are-working-not-as-expected-in-the-code/925823

@hemmikall
Copy link

Still seems to be an issue.

Using Arduino UNO on COM3, the serial monitor sends out two bytes of 0xF0 (hex value of each byte) every second.
As soon as I close the serial monitor, the transmission stops.

@BlueBles
Copy link

BlueBles commented Mar 3, 2022

Still a problem.
Baud rate 115200
Arduino Mega on IDE 2.0 each 1-2 seconds appear some weird random data on serial.
On old IDE, no problem, all text from serial is the only that I have sended.

@PaulStoffregen
Copy link
Sponsor

Maybe switching to new API (#769) will help? Or at least should be done first, so testing and troubleshooting is done with new pluggable serial monitor?

@sterretjeToo
Copy link

Some additional information that might help; with the given sketch

  1. SparkFun RedBoard (FTDI) and clone Nano (CH340) do not show activity on the RX led and no data is displayed in the serial monitor.
  2. The RX LED flashes on an Arduino Leonardo / Micro as well as on a SparkFun ProMicro; nothing is displayed in serial monitor. Specifically on the ProMicro this can be disturbing as the RX LED is used is often used as a heartbeat to detect if a sketch might be hanging or not.

@nhatnamt
Copy link

I faced a similar problem with Arduino Due at 9600 baud. The same code works fine on 1.8

@MikeGWem
Copy link

MikeGWem commented Sep 6, 2022

Still an issue with RC9.3
Simple program attached. Works as expected in V1 IDE but collects spurious data when the baud rate is set to 115200 in V2 IDE
Workaround is to set a baud rate of 9600. [Note when testing, "No Line Ending" should be set on Serial Monitor. Tested board - Uno
HelloWorld2.zip

@palazzol
Copy link
Contributor

palazzol commented Nov 8, 2022

Hello,

I am currently having this issue with an Arduino Uno R3. It looks like the IDE is sending redundant changes in configuration data every second, and even more when you select the pulldowns on the serial monitor. (Not sure exactly what, but it could be like setting the baud rate, stop bits, etc.) For some boards, this has no ill effects. But for the ones with an ATMEGA16U2 at least, this can cause the firmware to momentarily reset the UART, putting spurious pulse out on the Serial receive to the 328P, in my case. I can clearly see the pulses on an oscilloscope. Note, the RXD light driven by the ATMEGA16U2 is not flashing - it's not "received data" being sent, it's something else causing spurious pulses. This is why they oddly seem to show up as mostly 0xf0 at 115200 baud - It's just the luck of the timing. Strangely, the only time it seems to stop is when you select 57600, which I can see is a special case in the ATMEGA16U2 firmware.

Anyway, my Javascript is rusty but I think this could be fixed by finding and eliminating the redundant config information being sent by the Serial Monitor. Alternatively, I bet you could also update the ATMEGA16U2 firmware to check the incoming state changes to see if they are needed, and not reset the UART unless required.

I want to learn how to build the new IDE, and then I can try to work on this some more. I'd also be happy to test any updates you may be evaluating.

@palazzol
Copy link
Contributor

palazzol commented Nov 8, 2022

By the way, the pulses seem to come in pairs. Both of which usually, but not always, decode as an 0xf0 at 115200 baud. It may be the UART being turned off, and then turned back on? My guess is that this code is being triggered on the ATMEGA16U2:

https://github.com/arduino/ArduinoCore-avr/blob/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial.c#L204

@MikeGWem
Copy link

MikeGWem commented Nov 8, 2022

This is entirely a problem associated with the IDEv2 implementation of the Serial Monitor. Version 1 IDE - all is fine. I even built my own implementation of a Serial Monitor in C#/Windows Forms and had none of the issues we are seeing here. No issue when using putty either.

@palazzol
Copy link
Contributor

Well, I've made some more progress. The Arduino-IDE program uses a component named arduino-cli.exe, which in turn uses another component named serial-monitor.exe to talk to the ATMEGA16U2 on the Arduino Uno. I have run serial-monitor.exe by itself, and after it executes the OPEN command, the 1Hz glitch pairs start appearing on the Uno's RXD line. There does not appear to be any command being executed every second, however. I am going to dig into the firmware on the ATMEGA16U2 next, and try to figure out what is really going on there. The IDE isn't completely off the hook, because it is still sending too much data to the board, especially when using the Line Endings pulldown - which shouldn't even affect the serial port. But the root cause of the periodic corruption has been narrowed down to an interaction between serial-monitor.exe and the ATMEGA16U2 firmware.

palazzol added a commit to palazzol/go-serial that referenced this issue Nov 14, 2022
Remove unnecessary code, originally for checking for disconnects when using non-overlapped I/O.  getOverlappedEvent() returns all required error codes.  Calling getCommState()/setCommState() every second in some applications contributes to other downstream issues.  For examples:
bugst#60 (comment)
arduino/arduino-ide#375
@palazzol
Copy link
Contributor

palazzol commented Nov 15, 2022

  1. The root cause of the periodic corruption is inside the go serial library used by serial-monitor.exe. I submitted a pull request above which I believe takes care of it. I'm not sure how long it will take for that to be accepted and then used by arduino serial-monitor though. The Arduino project may want to fork it if the fix is not adopted quickly.
  2. The extra corruption caused by the flurry of comm updates when various pulldowns are used has been reduced with another pull request. This limits the flurry to only the baud rate pulldown. I still couldn't figure out how to change only the baud rate, without changing all the other serial parameters, but I hope someone who reads that pull request will be able to help there.
  3. I still want to do one more fix to the ATMEGA16U2 firmware, to mask any glitches due to legitimate reconfiguration. It looks like the original LUFA USB-serial example had that feature, but it didn't make it into the 16U2 code for some reason.

@MikeGWem
Copy link

Well done Frank Palazzolo. A solution in sight.

@kittaakos kittaakos self-assigned this Nov 22, 2022
kittaakos pushed a commit that referenced this issue Nov 22, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Nov 23, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
cmaglie pushed a commit to cmaglie/go-serial that referenced this issue Nov 24, 2022
The old code is no more needed when using overlapped I/O,
getOverlappedEvent() returns all required error codes.

Calling getCommState()/setCommState() every second in some
applications contributes to other downstream issues. For examples:

bugst#60 (comment)
arduino/arduino-ide#375
kittaakos pushed a commit that referenced this issue Nov 28, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Nov 28, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Nov 28, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Nov 29, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Nov 29, 2022
Closes #375

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
@kittaakos
Copy link
Contributor

I am reopening as the #1703 only partially fixes the issue: #1703 (review)

Per, please close it if you think this is resolved. Thank you!

@kittaakos kittaakos reopened this Nov 29, 2022
@per1234 per1234 assigned per1234 and unassigned kittaakos and AlbyIanna Nov 29, 2022
@per1234 per1234 added the status: in progress Work is in progress on this label Nov 29, 2022
@per1234
Copy link
Contributor Author

per1234 commented Dec 1, 2022

Fixed by bugst/go-serial#147 + arduino/serial-monitor#31.

These fixes are in the serial-monitor 0.11.0 release, which will be automatically installed the next time the user starts Arduino IDE 2.x.

@per1234 per1234 closed this as completed Dec 1, 2022
@per1234 per1234 added conclusion: resolved Issue was resolved and removed status: in progress Work is in progress on this labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved 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.