We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › overwriting/updating serial monitor
Page Index Toggle Pages: 1
overwriting/updating serial monitor (Read 834 times)
overwriting/updating serial monitor
May 4th, 2009, 11:13am
 
I want to print out output from a sensor to the arduino serial monitor continuously. So, I have this while loop

while(1){
 Serial.print("Temperature: ");
 Serial.println(sensor);  //sensor is the output value for the sensor
}

Here's my question: How can I improve this so that it prints temperature only once and continuously updates "sensor".
So instead of this:

temperature: 10
temperature: 12
temperature: 11

you would have
temperature: 10 (12,11)// so it's just one line of output but 10 changing to 12 and then 11

Pls help!!! Thanks!
Re: overwriting/updating serial monitor
Reply #1 - May 4th, 2009, 12:22pm
 
Move the first print statement to just before the loop.
Re: overwriting/updating serial monitor
Reply #2 - May 5th, 2009, 9:30am
 
I assume you are trying to do this using the Arduino serial monitor (running arduino.exe) , and not from Processing (running processing.exe).

In days of yore,  if you wrote "Temperature: xxx" to the console, you could simply overwrite the 'xxx'  portion by sending 3 backspaces and then sending the new 'xxx' portion. In ASCII, the backspace character value is 8. To send a backspace with Arduino, you would do Serial.print(8,BYTE); Unfortunately, I tried this and the serial monitor doesn't handle the backspace correctly.

If you switch to Processing to monitor the serial port, you can, of course, use graphical text and draw over the 'xxx' portion every time.
Within Processing, another possibility is to access the console window of Processing and do:
   char bs =8;
   print(bs); //once for each character to overwrite

This doesn't work in the popup window that Processing automatically opens for graphical drawing. You need to get to the console window where you would type in command lines, and then bs should work.

P.S.: I haven't figured out how to get to the console window from within Windows.
Re: overwriting/updating serial monitor
Reply #3 - May 5th, 2009, 2:43pm
 
Here is a simple example that works if you use a communications program to monitor the serial output from the Arduino. (I found the freeware Tera Term Pro, version 2.3 works great. google it.  Do 'new connection' 'serial' 'yourComPort'.)

I wasn't sure about the interaction between the arduino.exe and TeraTerm so I closed arduino.exe after uploading the sketch and then started TeraTerm.

The program calculates the length of the number output then backspaces that length before refreshing the number.

Unfortunately, you lose all the goodies of 'Processing' if you were using that.

//Example overwrite monitor output
int counter;
void setup() {
 counter =0;
 Serial.begin(9600);
}

void loop() {

 int len;

 Serial.print("Counter: ");
 while (true) {
   Serial.print(counter);

   len = getLength(counter);
   backSpace(len);
   counter++;
   delay(10);
 }
}
int getLength(int counter) {
 int len=0;  // default value, indicates too long
 if (counter <10) len = 1;
 else if(counter<100) len = 2;
 else if(counter<1000) len = 3;
 else if(counter<10000) len = 4;
 return len;
}
void backSpace(int length) {
 char bs=8;
 int i;
 for (i=0;i<length;i++) {
   Serial.print(bs);
 }
}
Page Index Toggle Pages: 1