Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Serial.println cause an extra CR+LF line when Monitor contents copied to a texteditor

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    3

    Serial.println cause an extra CR+LF line when Monitor contents copied to a texteditor

    A simple program outputs THREE 'Serial.println' lines to the Serial Monitor.
    Using an Arduino Uno, three lines are shown and when 'Copy/Pasted' into a Text Editor (Notepad++), there are still three lines.
    Using a Teensy 3.5, same three lines are shown, but when 'Copy/Pasted' into the Text Editor, there are instead SIX lines! An extra, empty line (only CR+LF) is added after each "text" line! So, they don't show on the Serial Monitor, only when 'Copy/Pasted'!

  2. #2
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    I've found a way to avoid the extra CR+LFs!
    If I add a single LF character at the end of the string, moving the Null String byte (ASCII Zero) 1 step to the "right", and then use 'Serial.print' rather than 'Serial.println', will still show correctly on the Teensy Monitor AND won't create the extra CR+LFs when 'Copy/Pasted'...

    BUT, I do think that these extra CR+LFs are a Serial Monitor BUG, rather than an "undocumented(?) feature"!

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,821
    The workaround in post #2 is what I tend to do. Add '\n' to the string or .print('\n');

    @KurtE made a point of this some time back. It only happens on copy from IDE SerMon - at least Teensy SerMon - not all Serial Monitor programs like TyCommander. It does not seem to happen on MAC.

    It is because println() sends both CR and LR chars and they are maintained on copy to clipboard

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,366
    Or use printf. Instead of
    Code:
    Serial.println("stuff");
    use
    Code:
    Serial.printf("stuff\n");
    Pete

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,114
    Yes, it’s a bug. This was one of many small details which were not clear (at least to me) in the Java documentation when I wrote the FifoDocument class that speeds up the serial monitor to handle sustained max speed printing from Teensy 4.0. Now I know the rest of the system expects \r chars to be filtered out. Planning to fix this eventually, but the reality is I consider this bug to be low priority.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •