Go Down

Topic: Serial port prints on one line! How to solve? (Read 1 time) previous topic - next topic

mixania

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!
Arduino Uno R3
Mac OSX Lion

retrolefty

Well perhaps you could try using:

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

Lefty

mixania


Well perhaps you could try using:

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

Lefty


Thanks for the post, exactly what I needed! :)
Arduino Uno R3
Mac OSX Lion

robtillaart

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: [Select]
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");
}

Rob Tillaart

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

mixania


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!
Arduino Uno R3
Mac OSX Lion

robtillaart

#5
Mar 21, 2013, 11:28 pm Last Edit: Mar 21, 2013, 11:33 pm by robtillaart Reason: 1
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 ;)
Rob Tillaart

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

Go Up