Clearing the Serial Monitor screen

Hello!
I think that there should be a way in software to clear the Serial Monitor screen. The next version of the Arduino IDE should have that feature. I think that because sometimes, I don't need a million lines of text scrolling through the screen at once. For example, if I want a temperature reading, I don't need a million lines of text printing every 0.1 seconds, but a single line of text that changes. Who else agrees?

Window's Command Prompt has a cls command to clear the screen. That way, this program will print the time and date on the command prompt screen:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
void wait ( int mseconds )
{
  clock_t endwait;
  endwait = clock () + mseconds;
  while (clock() < endwait) {}
}
int main(){
  while(1){
    system("cls");
    time_t now;
    struct tm *time_info;
    time(&now);
    time_info = localtime(&now);
    printf("Current date/time: %s", asctime(time_info));
    wait(1000);
  }
  return 0;
}
1 Like

If you used a proper terminal emulator, you'd find this feature and many more.

AWOL:
If you used a proper terminal emulator, you'd find this feature and many more.

That means that the terminal emulator will work just like Serial Monitor? Which one should I use? So I can do something like this in the sketch:

Serial.clear(); //clear the screen

to clear the screen?

The Serial object doesn't have a clear method, so no.
Depending on the emulation you've chosen, you'd send the appropriate escape sequence as a string.

For example, if I want a temperature reading, I don't need a million lines of text printing every 0.1 seconds, but a single line of text that changes. Who else agrees?

Good suggestion. I agree this would be a nice feature.

2 Likes

sounds to me like a good idea to add as a method
don't know how to do it,

but what harm would it do ?

lets have it

1 Like
size_t HardwareSerial::clear() {
    return write(0x0C);
}

and this code for the IDE in app/src/processing/app/SerialMonitor.java near the bottom.

  public void message(final String s) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        if (s.charAt(0) == 0x0C) {
            textArea.setText("");
            return;
        }
        textArea.append(s);
        if (autoscrollBox.isSelected()) {
        	textArea.setCaretPosition(textArea.getDocument().getLength());
        }
      }});
  }

No idea if that will work, since the IDE can't see my serial port. It should be a start, though.

@WizenedEE: What do you mean by the code you posted? Do you think that there is a way to clear the Serial Monitor using the sketch?

dkl65:
@WizenedEE: What do you mean by the code you posted? Do you think that there is a way to clear the Serial Monitor using the sketch?

Well the first set should be added to HardwareSerial.cpp (with the appropriate modification to HardwareSerial.h) and the second set should be changed in the arduino source code in SerialMonitor.java

I tested the SerialMonitor.java code and it works! With this sketch:

void setup() {
  Serial.begin(115200);
}
void loop() {
  static int i=0;
  Serial.println("Sup dude");
  Serial.println(i);
  delay(2000);
  Serial.write(0x0C);
  i++;
}

I do not know where SerialMonitor.java is. Is it in the Arduino Application Folder (i.e. arduino-1.0.1)?

Here:
http://code.google.com/p/arduino/wiki/BuildingArduino

Apply the change after you download it but before you build it.

What does that have to do with clearing the Serial Monitor screen?

dkl65:
What does that have to do with clearing the Serial Monitor screen?

To clear the serial monitor, you have to modify the source code to let it be cleared. To do that, you must download the arduino source, apply the change I gave you, compile it, and then run it. Then you must upload a program to the arduino to send the right code to clear it.

The instructions in the link you gave me is confusing. So I downloaded the Cygwin Terminal setup.exe. I selected all the defaults. When it told me to select a link to download the software from, I had no idea what that was, so I just chose a random link. The Cygwin thing had sucessfully installed. What next?
I currently using Arduino 1.0.1.
So much for clearing the screen!

It would be a lot easier to just download PuTTY, and use that instead.

Yup, reply #1.