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
<p>nice </p>
<p>nice </p>
This is nice! <br> <br>This is probably really clear, but arduino's API changed over time, <br>the correct way of doing this would be: <br> <br>void clearAndHome() <br>{ <br>Serial.write(27); <br>Serial.print(&quot;[2J&quot;); // clear screen <br>Serial.write(27); // ESC <br>Serial.print(&quot;[H&quot;); // cursor to home <br>} <br> <br>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. <br>Zterm any good? and goSerial? Thanks!
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
New version!<br><br>I have updated the code so that a Serial.println-type function can be used with &quot;inline&quot; FLASH-stored strings. So, basically, you have code that has a print function and strings where you would expect them in the code, only at compile time they get stored in FLASH and read-from FLASH at execution-time via PROGMEM.<br><br>Perhaps at some point Serial.print/println will be rewritten to use prog_uchar instead of char, and then PSTR will be able to provide a pointer it can use directly. But, this method works fine.
Wow nearly all the RAM?<br><br>You need to use flash memory more. It looks like you know how but you are still using the &quot;Serial.print&quot;, which is going to eat up a lot of RAM.<br><br>Use stdio.h , so you can use printf_P<br><br>http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html<br><br>together with avr/pgmspace.h, you can call functions such as<br><br>printf_P(PSTR(&quot;This string will take no RAM at all&quot;));
These are good comments. The great thing about the Arduino platform is you can succeed right from the start with what's on the arduino.cc website and then later move on to standard avr libraries once you have more experience.
There's a much better way of storing different data types into EEPROM<br><br>take a look at http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html<br><br>It provides functions for most common datatypes. And for custom datatypes like a struct, simply pass in a pointer to eeprom_write_block, and the length should just be &quot;sizeof&quot; the struct<br><br>

About This Instructable


49 favorites


Bio: You know, I think we're all Bozos on this bus
More by uhclem: Squareinator - A SN76489 Monosynth 2014 Chevy Camaro Disable OnStar The Tnychron Clock
Add instructable to: