Instructables

A Wirelessly Controlled, Arduino-Powered Message Board

Step 6: Useful Code Explained - Clearing a Serial Terminal


It does what it says - clears the screen and sends the cursor to home. Note that the Arduino serial monitor is not really a terminal. It does not support the control characters necessary for this to work. You need to use a real terminal emulator program with this project.

// function clearAndHome()
// clear the terminal screen and send the cursor home
void clearAndHome()
{
Serial.print(27, BYTE); // ESC
Serial.print("[2J"); // clear screen
Serial.print(27, BYTE); // ESC
Serial.print("[H"); // cursor to home
}
supermaggel2 years ago
This is nice!

This is probably really clear, but arduino's API changed over time,
the correct way of doing this would be:

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

Anyone has a tip on which terminal (for OSX) program actually understands these commands? I've tried coolTerm, which doesn't seem to understand this.
Zterm any good? and goSerial? Thanks!
yadoo862 years ago
If you use Arduino 1.0 and you want to clear the screen -like the step 6-, I highly recommend this article: http://www.whatisarduino.org/bin/Tutorials/How+to+clear+Arduino+Serial