How do I clear the screen (cls) in the Serial Monitor?

Here is my code (from an Arduino Uno):

int photo = A4;

int val = 0;

int secs = 0;
int mins = 0;
int hours = 0;
int days = 0;

void setup() {

 pinMode(photo, INPUT); //pin A4 is a photoresistor, which detects light
 Serial.begin(9600);

}

void printTime(int secs, int mins, int hours, int days) {
  Serial.print(days);
  Serial.write(" days, ");
  Serial.print(hours);
  Serial.write(" hours, ");
  Serial.print(mins);
  Serial.write(" minutes, ");
  Serial.print(secs);
  Serial.print(" seconds");
  Serial.write("\n");
}


void loop() {

 val = analogRead(photo);

 delay(1000);

 if (val > 512) {
  secs = secs + 1;
  if (secs == 60) {
    mins = mins + 1;
    secs = 0;
    if(mins == 60) {
      hours = hours + 1;
      mins = 0;
      if(hours == 24) {
        days = days + 1;
        hours = 0;
      }
    }
  }
 
  
 }
 
 
 
 //TODO: reverse order of units of time (days first, etc)
 Serial.print("12");
 if (val > 512) {
   

   Serial.println(" ");
   printTime(secs, mins, hours, days);
   Serial.println(" ");
   Serial.println("========================");
 } else {

   Serial.println(" ");
   Serial.println("STOPPED AT");
   printTime(secs, mins, hours, days);
   Serial.println(" ");
   Serial.println("========================");
   
   delay(1000);
   
 }




}

I am doing a science project for school testing generic vs brand-name battery life.

Print a whole bunch of blank lines to clear your SM screen.

Reboot windows. It works like a charm.

1 Like

Reboot windows. It works like a charm.

Indeed.

How do I clear the screen (cls) in the Serial Monitor?

I don't think you can beyond closing/reopening the serial monitor. You could try printing a string of characters to indicate end of data, something like =============================.

The whole point of serial monitor is that it's a tool, to tell you what has been received over the serial port. It's not really intended as a user interface.

There are some ASCII characters (such as backspace and linereset) that other serial applications will honour. Serial monitor doesn't. If it did, it could reduce it's value as a debugging tool.

You can download realTerm totally free and this will allow you to use those characters to delete items on the current line. There's still no "clear screen" control though.

1 Like

If you use a "real" terminal emulator (minicom, putty, realterm, etc) instead of the Arduino IDE's built-in serial monitor, you will gain the ability to clear the screen (and do all sorts of other things) using "escape sequences."
Most terminals these days support Ansi-standard (DEC Vt100) escape sequences, and the string "\033[0H\033[0J" will clear the screen. (escape [ 0 H escape [ 0 J)

3 Likes