Clearing the terminal screen?

Eugen picture Eugen · Apr 11, 2012 · Viewed 138.9k times · Source

I'm reading data from 9 different sensors for my robot and I need to display them all steadily, in the same window so I can compare the values and see if any of the readings is off.

The problem I'm having with both Serial.print and lcd.print is that the values are constantly moving and I can't really have a good look at them while moving the robot.

I was thinking to call something like Serial.clear() before displaying anything else and that would just keep things steady and in one place, changing only the values.

From what I found so far, Serial.print(17,BYTE) for instance is no longer supported (Calling the ESC key).

So...for those with a bit more Arduino experience...what is the proper way to do this?

Answer

jjz picture jjz · Mar 21, 2013

The Arduino serial monitor isn't a regular terminal so its not possible to clear the screen using standard terminal commands. I suggest using an actual terminal emulator, like Putty.

The command for clearing a terminal screen is ESC[2J

To accomplish in Arduino code:

  Serial.write(27);       // ESC command
  Serial.print("[2J");    // clear screen command
  Serial.write(27);
  Serial.print("[H");     // cursor to home command

Source:
http://www.instructables.com/id/A-Wirelessly-Controlled-Arduino-Powered-Message-B/step6/Useful-Code-Explained-Clearing-a-Serial-Terminal/