Pages: [1]   Go Down
Author Topic: Serial port prints on one line! How to solve?  (Read 1285 times)
0 Members and 1 Guest are viewing this topic.
New York, NY
Offline Offline
Full Member
***
Karma: 2
Posts: 142
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Arduino Forum! I've been trying to fix a problem were the Serial Monitor keeps on writing on the same line. I tried to fix the settings (No line ending, New line etc..) at the bottom but nothing helps. Is it caus of the code? Please HELP!


* Screen Shot 2012-09-02 at 7.56.34 PM.png (30.04 KB, 529x314 - viewed 40 times.)

* Screen Shot 2012-09-02 at 7.56.20 PM.png (42.74 KB, 614x714 - viewed 38 times.)
Logged

Arduino Uno R3
Teensy 3.0
Mac OSX Yosemite

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well perhaps you could try using:

Serial.println(reading); instead of Serial.print(reading);

Lefty
Logged

New York, NY
Offline Offline
Full Member
***
Karma: 2
Posts: 142
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well perhaps you could try using:

Serial.println(reading); instead of Serial.print(reading);

Lefty

Thanks for the post, exactly what I needed! smiley
Logged

Arduino Uno R3
Teensy 3.0
Mac OSX Yosemite

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

alternative is the use of \n

Serial.print("first line\n second line\n");

Besides \n the \t (tab is also interesting as it allows to columnize numbers and text in the output (copy to Excel is a breeze;).

snippet
Code:
void loop()
{
   Serial.print(millis());
   Serial.print("\t");
   Serial.print(analogRead(A0));
   Serial.print("\t");
   Serial.print(analogRead(A1));
   Serial.print("\t");
   Serial.print(analogRead(A2));
   Serial.print("\n");
}
Logged

Rob Tillaart

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

New York, NY
Offline Offline
Full Member
***
Karma: 2
Posts: 142
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

alternative is the use of \n

Serial.print("first line\n second line\n");

Besides \n the \t (tab is also interesting as it allows to columnize numbers and text in the output (copy to Excel is a breeze;).

Thanks robtillaart! In fact I was doing a temperature logging project a while ago and I couldn't understand what "/n" means in other people's code examples. I worked with Excel as well in my project so your comment is very useful to me.
I didn't know nothing about "\t" at all, I always was searching for something similar to it.
Appreciate your help!
Logged

Arduino Uno R3
Teensy 3.0
Mac OSX Yosemite

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

I prefer the \t (tab) as separator as it also formats the output nice in the serial port monitor.
Further more dependant on the locale the comma is a decimal separator in floating point numbers (e.g. in Dutch Excel it is) which causes problems.

If you have more questions, just ask ! - but first search the forum as it contains already a zillion answers smiley-wink
« Last Edit: March 21, 2013, 05:33:45 pm by robtillaart » 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: