Pages: [1]   Go Down
Author Topic: HOW-TO: Serial.print() to cpecific row & collu  (Read 1761 times)
0 Members and 1 Guest are viewing this topic.
Ādaži, Latvia
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Debugging applications I often have to monitor many parameters at once. It's very hard with Arduino built in java terminal. Output is scrolling continuously, it's almost impossible to spot anything especially when monitoring changes in values.

It is possible to output values you need to specific places of the screen.

Like x,y position. All you need is terminal application capable of displaying "Xterm"  command sequences. I'm using iTerm (http://iterm.sourceforge.net/) for MacOS X and for Windows you have free Putty app.

The only trade off is that you have to use external program instead of pressing nice shiny button in Arduino IDE. But it pays off in terms of visibility and ease of debugging.

All you have to do is to incorporate Xterm control sequences in your code like this

Code:
void setup() {
  Serial.begin(9600);
  Serial.print("\eSP F");  // tell to use 7-bit control codes
  Serial.print("\e[?25l"); // hide cursor
  Serial.print("\e[?12l"); // disable cursor highlighting
  }
This is all needed to tell terminal application that you will use Xterm commands. An that you don't nee pesky bold cursor running like mad across the screen when values are updating.

Now how to output text on row; column coordinates

Code:
Serial.print("\e[1;1HTank hardware test console");
sens_fRng =analogRead(fRng);
Serial.print("\e[5;1HRangefinder: \e[5;16H");
Serial.print(sens_fRng);
Now what does "\e[1;1H"  means?
\e[-  This is so called escape sequence. It tells Xterm that next text will be command.
1;1 - row and column. Just put there cursor coordinates you desire. Text will be every time outputted there.
H - I think this is positioning command itself, but I don't care.



Code:
// I'm reading my sensor  
sens_fRng =analogRead(fRng);
// I'm putting text "Rangefiders"  at row 5, col 1. And moving cursor
// to column 16 to output next text there.
Serial.print("\e[5;1HRangefinder: \e[5;16H");
// Guess what? next text is my sensor reading value. It will be
// outputted where I told before.
Serial.print(sens_fRng);

So remember that you have to move cursor to position you need before outputting some text.

How to view it on computer

On MacOS X just open iTerm (http://iterm.sourceforge.net/)  application and type there
Code:
screen /dev/name_of_your_arduino_port
My Arduino port is named tty.usbserial-A900ad3P. SO my command is screen /dev/tty.usbserial-A900ad3P

Conclusion
I'm sure there are many way to make this faster and more user friendly. For example Arduino Xterm library like Xterm.print("text",x,y)

And it should be possible to put and icon on your screen opening terminal application with all settings needed. I really hope this guide will be useful to some beginners struggling with lack of other means of debugging your running code as many-many variables output.




« Last Edit: August 01, 2010, 10:19:38 am by janisj » Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for that info !

I found that I also needed  
Code:
 Serial.print("\e[2J");
in the setup() routine to clear the screen, otherwise I had some garbage in there.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome, just what I was looking for. That scrolling screen is annoying. Hopefully it can be included at some point in the released code.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13915
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a VT100 (or VT52) emulation code. You can probably set the emulation mode of the iTerm. If you search for VT100 codes you will find many of them also to make values BOLD etc
Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  String OFF = "\033[0m";
  String BOLD = "\033[1m";
  
  Serial.print(BOLD);
  Serial.println("Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  while(1);
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: