Skip to content

Serial Monitor content after null character not copied by "Copy Output" feature #2827

@per1234

Description

@per1234

Describe the problem

The "Copy Output" icon on the Serial Monitor toolbar copies the content from Serial Monitor's output panel to the clipboard (#2718).

Under certain conditions (e.g., #927), non-textual content may be received by Serial Monitor.

🐛 If a null character (ASCII code 0) is received by Serial Monitor, the "Copy Output" feature will not work for any content received after that character.

To reproduce

Required equipment

  • Any Arduino board.

Instructions

  1. Create a sketch with the following code:
    void setup() {
      Serial.begin(9600);
      while(!Serial) {}
      delay(750);
      Serial.println("content before null");
      Serial.println("more content before null");
      Serial.write(0);  // Print a null character
      Serial.println();
      Serial.println("content after null");
      Serial.println("more content after null");
    }
    
    void loop() {}
  2. Upload the sketch to the board.
  3. Open Serial Monitor.
  4. Select "9600 baud" from the menu in Serial Monitor.
    This baud rate was picked arbitrarily when writing the demo sketch. The fault will occur with sketches that use any baud rate.
  5. Click the "Clear Output" icon near the top right corner of the Serial Monitor panel.
  6. Press and release the reset button on the board.
    • This, and the previous step, are included to avoid the presence of irrelevant content in Serial Monitor
    • You should see the following content in Serial Monitor:
      content before null
      more content before null
      ☐
      content after null
      more content after null
      
  7. Click the "Copy Output" icon near the top right corner of the Serial Monitor panel.
  8. Paste the copied output into any text editor.

🐛 The content after the null character was not copied:

content before null
more content before null

Expected behavior

All content in Serial Monitor is copied.

Arduino IDE version

93d27ea

Operating system

Windows

Operating system version

Windows 11

Additional context

For the sake of simplicity, the demo used a sketch that explicitly prints a null character. This is unlikely to be present in any real world sketch, though it is entirely possible for a real sketch program to produce null characters in output. For example:

  • due to a bug in the code
  • echoing textual data received from a peripheral device, which is producing null characters

The far more common cause of null characters in Serial Monitor is a bug that causes the upload process to consistently produce these characters:

#927

This will cause the "Copy Output" feature to be very unreliable for anyone using one of the affected official Arduino boards on a Windows machine (and this is very common in the Arduino IDE user base).

Workaround

If the source of the null characters is #927, you can use the workaround provided there:

#927 (comment)

alternatively, you can use the following procedure as a workaround:

  1. Upload a sketch.
  2. Click the "Clear Output" icon near the top right corner of the Serial Monitor panel to remove the problematic content that was added by the upload.
  3. Press and release the reset button on the board to restart the sketch program.

Keywords

  • "garbage"

  • "gibberish"

  • "spurious"

  • "trash"

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

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftopic: serial monitorRelated to the Serial Monitortype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions