Skip to content

Serial monitor gives corrupted output #1031

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

Closed
3 tasks done
cmaglie opened this issue Apr 23, 2025 · 1 comment · Fixed by #1032
Closed
3 tasks done

Serial monitor gives corrupted output #1031

cmaglie opened this issue Apr 23, 2025 · 1 comment · Fixed by #1032
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@cmaglie
Copy link
Member

cmaglie commented Apr 23, 2025

Describe the problem

Image

To reproduce

This is very difficult to reproduce and, after a lot of trial and error, we found a combination of HW and SW that is more likely to reproduce it:

  • A macOS machine
  • A board that mounts a CP2102 chip as a USB-2-serial converter

Here are the instructions to reproduce:

  1. Upload the following sketch to the board (note it is configured for 9600 baud):
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      Serial.println("Hello, world!");
      delay(1000);
    }
  2. Open the Cloud Editor Serial Monitor
    ✅ The serial output is printed without corruption (Cloud Editor Serial Monitor always starts configured for 9600 baud).
  3. Select "115200" from the baud rate menu.
  4. Select "9600" from the baud rate menu.
    ❌ The serial output is corrupted with swapped or missing characters, as described by the users.

The fault only occurs when changing the baud rate in the Serial Monitor. It is not specific to the 9600 baud rate. For example, I can also reproduce the fault with this more simplified procedure:

  1. Upload the following sketch to the board (note that I configured it for 115200 baud instead of 9600 this time):
    void setup() {
      Serial.begin(115200);
    }
    void loop() {
      Serial.println("Hello, world!");
      delay(1000);
    }
  2. Open the Cloud Editor Serial Monitor.
    ✅ The serial output is corrupted as expected because the Serial Monitor is configured for 9600 baud.
  3. Select "115200" from the baud rate menu.
    ❌ The serial output is corrupted with swapped or missing characters, as described by the users.

Expected behavior

The Serial Monitor shows uncorrupted output.

Arduino Create Agent version

1.7.0

Operating system

macOS

Operating system version

Sequoia

Browser

Chrome

Browser version

135.0.7049.115

Additional context

Additional reports

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest version
  • My report contains all necessary details
@cmaglie cmaglie added the type: imperfection Perceived defect in any part of project label Apr 23, 2025
@cmaglie
Copy link
Member Author

cmaglie commented Apr 23, 2025

Other information from @per1234:

When I examine the commands that are produced by the above procedure in the Cloud Agent Debug Console, I notice that the 3rd step causes multiple open commands, instead of a single open step as we would expect:

open /dev/cu.usbserial-0001 9600 timed

{
  "Cmd": "Open",
  "Desc": "Got register/open on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 9600,
  "BufferType": "timed"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "\u0000��\u0000�\u0000���\u0000 \u00017\u0017$Nu%���n9�\u0018�\b�"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "�"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "["
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "+"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "�"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "K"
}

close /dev/cu.usbserial-0001

Closing serial port /dev/cu.usbserial-0001

Shutting down reader on /dev/cu.usbserial-0001

{
  "Cmd": "Close",
  "Desc": "Got unregister/close on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 9600
}

Shutting down writer on /dev/cu.usbserial-0001

writerBuffered just got closed. make sure you make a new one. port:/dev/cu.usbserial-0001

open /dev/cu.usbserial-0001 115200 timed

open /dev/cu.usbserial-0001 115200 timed

{
  "Cmd": "Open",
  "Desc": "Got register/open on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200,
  "BufferType": "timed"
}

{
  "Cmd": "Open",
  "Desc": "Got register/open on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200,
  "BufferType": "timed"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "�\u0003\u0000]�R\u001ep51��7q!\u00185�`x400805cc\r\n"
}

open /dev/cu.usbserial-0001 115200 timed

{
  "Cmd": "OpenFail",
  "Desc": "Error opening port. Serial port busy",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "H\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, world!"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "H"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "H"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "H"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hworld!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "world!\r\n"
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "ello, "
}

{
  "P": "/dev/cu.usbserial-0001",
  "D": "Hworld!\r\n"
}

The third of those open commands (the second redundant command) correctly failed:
open /dev/cu.usbserial-0001 115200 timed

{
  "Cmd": "OpenFail",
  "Desc": "Error opening port. Serial port busy",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200
}

but the first two (the expected command, and the first redundant one) went through:

open /dev/cu.usbserial-0001 115200 timed

open /dev/cu.usbserial-0001 115200 timed

{
  "Cmd": "Open",
  "Desc": "Got register/open on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200,
  "BufferType": "timed"
}

{
  "Cmd": "Open",
  "Desc": "Got register/open on port.",
  "Port": "/dev/cu.usbserial-0001",
  "Baud": 115200,
  "BufferType": "timed"
}

I was not able to reproduce the fault by sending the same commands manually via the Cloud Agent debug console. The redundant open commands always correctly failed, no matter how fast I tried to send the sequential commands.

  • I reproduced the fault on a macOS Sequoia machine
  • I am using the native macOS support for the CP2102. I have never manually installed any drivers on the machine.
  • I am not able to reproduce the fault on a Windows 11 machine
  • I am not able to reproduce the fault with an Adafruit Feather ESP32 board that has the related Silicon Labs CP2104 chip.
  • I am not able to reproduce the fault with a Nano derivative board that has the CH340.
  • I am not able to reproduce the fault with an official UNO R3.
  • I am able to reproduce the fault if I use 57600 baud instead of the 115200 arbitrarily selected for the demonstration procedures I described above.
  • I am able to reproduce the fault with the board connected directly to the USB socket on the computer, and with it connected via a USB hub.

@cmaglie cmaglie self-assigned this Apr 24, 2025
@per1234 per1234 added topic: code Related to content of the project itself conclusion: resolved Issue was resolved labels Apr 24, 2025
@cmaglie cmaglie mentioned this issue Apr 24, 2025
2 tasks
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 type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants