Clear display on serial monitor

When I'm running a new sketch the serial monitor may have stuff already, or be printing stuff when I open it.
Is there a simple way to run in setup that would clear the current display?
What I do now is put a delay so that I can click on the "clear display" button.

1 Like

Because the Serial monitor does not support control code such as clear screen the best that you can do is to put a Serial.println() in a for loop to print numerous blank lines which will cause whatever is on the screen to scroll out of sight

A proper terminal emulator will allow you to use control sequences to clear the screen, position the cursor, etc

2 Likes

Try this: Serial.print(F("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); the "n" is the new line character. When it reaches the bottom it scrolls the onscreen data off the top. You can do it in a loop if you want.

2 Likes

Given ESC-H/ESC-J is "home/clear screen" from VT100 days:

void setup() {
  Serial.begin(9600);
  Serial.print("\n"); // CRLF
  Serial.print("\h"); // HOME
  Serial.print("\j"); // CLRSCR
}
void loop() {}

The IDE protests the unknown (unsupported) escape sequences.

C:\...\sketch_mar12a.ino:4:16: warning: unknown escape sequence: '\h'
   Serial.print("\h");
                ^~~~
C:\...\sketch_mar12a.ino:5:16: warning: unknown escape sequence: '\j'
   Serial.print("\j");
                ^~~~
1 Like

Could we move this to the IDE2 section as a suggestion?

As the question is not specific to either IDE it has been moved to Project Guidance

I’m glad nobody has suggested CLS yet :clown_face::sunglasses:

1 Like

Maybe

void setup() {
  Serial.begin(9600);
  Serial.print("\n"); // CRLF
  Serial.print("\033h"); // HOME
  Serial.print("\033j"); // CLRSCR
}
void loop() {}

?

Two tiny "boxes" for unknown character.

I see the Serial Monitor like a printer... without "home" or "clrscr"

On serial monitor, yes. Like @UKHeliBob said above, serial monitor doesn't understand these codes and there is no way to clear it except clicking the clear button. But these codes should work on a terminal emulator app (set to vt52 mode).

I have used similar (vt100) codes in Arduino sketches before. They never work in serial monitor, but when I use terminal window in Ubuntu and the screen command, it worked great.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.