[terminal] Clearing the terminal screen?

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?

This question is related to terminal arduino refresh erase

The answer is


I made this simple function to achieve this:

void clearscreen() { 
    for(int i=0; i<10; i++) {
        Serial.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    }
}

It works well for me in the default terminal


If one of you guys are using virtual terminal in proteus and want to clear it just add Serial.write(0x0C); and it gonna work fine


ESC is the character _2_7, not _1_7. You can also try decimal 12 (aka. FF, form feed).

Note that all these special characters are not handled by the Arduino but by the program on the receiving side. So a standard Unix terminal (xterm, gnome-terminal, kterm, ...) handles a different set of control sequences then say a Windows terminal program like HTerm.

Therefore you should specify what program you are using exactly for display. After that it is possible to tell you what control characters and control sequences are usable.


imprime en linea los datos con un espaciado determinado, así tendrás columnas de datos de la misma variable y será más claro

Print all data in line, so you have rows with the data you need, i just solve the same problem like this, just make sur you had asignad a constant data size and spacement between, I made this

Serial.print("cuenta q2: ");
Serial.print( cuenta_pulsos_encoder_1,3);
Serial.print("\t");
Serial.print(q2_real,4);
Serial.print("\t");
Serial.print("cuenta q3: ");
Serial.print( cuenta_pulsos_encoder_2,3);
Serial.print("\t");
Serial.print(q3_real,4);
Serial.print("\t");
Serial.print("cuenta q4: ");
Serial.print( cuenta_pulsos_encoder_3,3);
Serial.print("\t");
Serial.println(q4_real,4);

If you change baudrate for example back and forth it clears the Serial Monitor window in version 1.5.3 of Arduino IDE for Intel Galileo development


the best way I can think of is using processing there are a few introductions on the net like displaying serial data, arduino graph and arduino radar
Since Arduino is based on processing its not that hard to learn


You could try:

Serial.write(13);

Which will provide a carriage return, returning to the start of the line every iteration - which should do what you're chasing? (Especially if everything is fixed width).


/*
As close as I can get to Clear Screen

*/


void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

}

void loop() {

Serial.println("This is Line ZERO ");

// put your main code here, to run repeatedly:

for (int i = 1; i < 37; i++)
{

 // Check and print Line
  if (i == 15)
  {
   Serial.println("Line 15");
  }

  else
   Serial.println(i);  //Prints line numbers   Delete i for blank line
  }

  delay(5000);  

  }

It's not possible to clear the Serial Monitor window based on incoming serial data.

I can think of a couple of options, the simplest (and cheatiest) is to use println() with a fixed width string that you've generated that contains your sensor data.

The Arduino IDE's Serial Monitor's Autoscroll checkbox means if you persistently send the fixed width string (with 500ms delay perhaps) this will give the impression that it's updating once it gets to the bottom and starts scrolling. You could also shrink the height of the window to make it look like it only has one line.

To accomplish a fixed width string that's suitable for serial println() you'll need functions to convert your sensor values to strings, as well as pad/trim them to a persistent size. Then concatenate the values together (including separators if it makes the data easier to read)

An output of something similar to this is what i'm hinting at:

| 1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 |

All things considered, this isn't a great solution but it would get you a result.

A far smarter idea is to build another program outside of Arduino and it's IDE that listens to the com port for sensor values sent from the Arduino. Your Arduino program will need to send a message your external program can unambiguously interpret, something like 1=0.5; where 1 = sensor ID and 0.5 = sensor value. The external program would then keep these values (1 for each sensor). The external program can then display this information in whatever way you'd like, a nice console output would be relatively easy to achieve :-)

C# has .NET's serialport class which is a pleasure to use. (most of the time!)

Python has a module called pyserial, which is also easy great.

Either language will give you much greater control over console output, should you choose to proceed this way.


Another kick at the can:

void setup(){     /*123456789 123456789 123456789 123456789 123*/
  String newRow="\n|________________________________________";
  String scrSiz="\n|\n|\n|\n|\n|\n|\n|\n|\n|\t";
  Serial.begin(115200);  
       // this baudrate should not have flicker but it does as seen when
       // the persistence of vision threshold is insufficiently exceeded
       // 115200 baud should display ~10000 cps or a char every 0.1 msec
       // each 'for' loop iteration 'should' print 65 chars. in < 7 msec
       // Serial.print() artifact inefficiencies are the flicker culprit
       // unfortunately '\r' does not render in the IDE's Serial Monitor

  Serial.print( scrSiz+"\n|_____ size screen vertically to fit _____"  );
  for(int i=0;i<30;i++){
     delay(1000); 
     Serial.print((String)scrSiz +i +"\t" + (10*i) +newRow);}
}
void loop(){}

I have found that ASCII 12 make a Form feed, that is a new page. here is a wikipedia definition

"Form feed is a page-breaking ASCII control character. It forces the printer to eject the current page and to continue printing at the top of another"

The code is

Serial.write(12);

Arduino Terminate doesn't support the character but Putty a light open source telnet client can do it

An Example of the code

void setup() {
  Serial.begin(9600);//Initializase the serial transmiter speed

}

void loop() {
    //Code tested with Putty terminal

    Serial.write(12);//ASCII for a Form feed
    Serial.println("This is the title of a new page");// your code

    delay(500);//delay for visual
    }

There is no way to clear the screen but, a really easy way to fake it can be printing as much Serial.println(); as you need to keep all the old data out of the screen.


You could just do:

Serial.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

or if you want:

for (int i=0; i<100; i++) {
   Serial.print("\n");
}

Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to arduino

Arduino Nano - "avrdude: ser_open():system can't open device "\\.\COM1": the system cannot find the file specified" python to arduino serial read & write how to stop a loop arduino Arduino Sketch upload issue - avrdude: stk500_recv(): programmer is not responding avrdude: stk500v2_ReceiveMessage(): timeout Arduino Tools > Serial Port greyed out Arduino error: does not name a type? Transform char array into String How do I remove a library from the arduino environment? Arduino COM port doesn't work

Examples related to refresh

How to Refresh a Component in Angular Angular + Material - How to refresh a data source (mat-table) How to Update a Component without refreshing full page - Angular How to reload page the page with pagination in Angular 2? Swift: Reload a View Controller Button that refreshes the page on click Update data on a page without refreshing How to refresh or show immediately in datagridview after inserting? Gradle project refresh failed after Android Studio update Refresh Part of Page (div)

Examples related to erase

HTML how to clear input using javascript? Clearing the terminal screen? Erase whole array Python C++ Erase vector element by value rather than by position? Erase the current printed console line How do I erase an element from std::vector<> by index? Erasing elements from a vector