system
November 22, 2010, 9:52am
1
Guys, my question is similar to liabilityquek's post.
I understand that Serial.println() command allows one to print data on the serial monitor.
Take for instance, when i used 2 analog inputs, my serial monitor looks like this :
1.8543657758
29.52
1.8543657758
29.52
I need to use two Serial.println() commands to display the above statements on serial monitor.
I used Serial println (voltage, DEC); and Serial println (Celcius);
However if i want my serial monitor to look something like this :
1.854365775829.52
1.854365775829.52
1.854365775829.52
That is like printing both voltage and celcius on the same line of the serial monitor.
Is that possible?
Can one Serial.println( ) do the job?
Thanks peeps. Awaiting and appreciate your replies
system
November 22, 2010, 9:55am
2
The ln on the end of the function name says to add a carriage return/line feed combination after print()ing the value. So, learn when to use Serial.print() and when to use Serial.println().
Why do you want the output jammed together with no spaces? You can print spaces and descriptive text as well as values.
system
November 22, 2010, 1:39pm
3
how do we print both the voltage and the temperature values at the same time?
For instance, i want the serial monitor to print the values shown like this
1.89234,29.8
And what is the differences between Serial.println() and Serial.print()?
system
November 22, 2010, 1:52pm
4
And what is the differences between Serial.println() and Serial.print()?
Reread the 1st sentence in my last reply.
how do we print both the voltage and the temperature values at the same time?
If you mean how do we print both values in one call, the answer is that you don't.
You can do this:
Serial.print(valOne);
Serial.print(", ");
Serial.println(valTwo);
This will work for both integer and float values.
Or you could do this:
char buf[24];
sprintf(buf, "%d, %d", valOne, valTwo);
Serial.println(buf);
Note that this only works for integer values.
system
November 22, 2010, 4:09pm
5
wow very nice answers...i know how to use the Serial.println() and Serial.print() commands.
I want to print:
1.854365775829.52
1.854365775829.52
1.854365775829.52
with no spaces on the serial monitor. How do i do that?
If i use these commands below,
Serial.print(valOne);
Serial.print(", ");
Serial.println(valTwo);
I will not get what i want...
system
November 22, 2010, 4:17pm
6
Serial.print("1.854365775829.52");
system
November 22, 2010, 4:24pm
7
Umm no....i dont think u got wad i meant....i m using two analog inputs...so my voltage and temperature readings on the serial monitor will keep changing
i used Serial.println(voltage, DEC);
followed by Serial.println(celcius);
I get this on the serial monitor
1.8543657758
29.52
1.8543657758
29.52
These values will keep changing
I want get this on my serial monitor:
1.854365775829.52
1.854365775829.52
i want them to be on the same line...how should i do it?
I don't think you can with the serial monitor - you alwys get a new line.
Try a terminal emulator, and make sure you don't send a newline, just a carriage-return.
system
November 22, 2010, 4:29pm
9
I knew what you meant. You said that you knew how to use Serial.print(0 and Serial.println(). If that is really the case, you should be able to look at
Serial.print(valOne);
Serial.print(", ");
Serial.println(valTwo);
and see what each statement is doing.
If you don't want the action of one of the statements to be performed, don't include that statement.
Although, if you jam the two number together, how are you going to tell where one ends and the next one begins?
system
November 22, 2010, 4:30pm
10
you alwys get a new line.
You only get a new line if you call Serial.println() or explicitly include \n in the string being printed.
system
November 22, 2010, 4:37pm
11
Serial.print(voltage);
Serial.print(", ");
Serial.println(celcius, DEC);
Those commands above will do this right?
1.854365775829.52
1.854365775829.52
1.854365775829.52
1.854365775829.52
I will try that tmr n let u guys know if it works
Sorry PaulS for the misunderstanding
system
November 22, 2010, 5:01pm
12
Those commands above will do this right?
1.854365775829.52
No, they will do this:
1.8543657758, 29.52
Please explain why you want the two numbers jammed together.
system
November 22, 2010, 5:07pm
13
Cause i want display 2 waveforms on Labview (Graphical Programming)....
O ya, sorry i made a mistake....Serial.print(", ") command will print the comma....
PaulS, if my voltage and temperature values keep changing, can i still stick to those commands to display them on the same line of the serial monitor?
system
November 22, 2010, 5:14pm
14
can i still stick to those commands to display them on the same line of the serial monitor?
Yes.
What does displaying them on the Serial Monitor jammed together have to do with displaying waveforms in LabView?
If you are sending the data to LabView, LabView needs to know where one value ends and the next value begins.
system
November 22, 2010, 6:11pm
15
PaulS, with those commands, serial monitor will look this :
1.854365775829.52
1.854365775829.52
1.854365775829.52
1.854365775829.52
OR
1.854365775829.521.854365775829.521.854365775829.521.854365775829.52??
hehe
system
November 22, 2010, 6:53pm
16
The first statement prints the value without a carriage return/line feed. The second statement prints the value and a carriage return/line feed.
system
November 23, 2010, 2:08am
17
I beleive that with the code like this;
Serial.print(voltage);
Serial.println(celcius, DEC);
You will get an output like this;
1.854365775829.52
1.854365775829.52
1.854365775829.52
1.854365775829.52
With a code like this;
Serial.print(voltage);
Serial.print(celcius, DEC);
You will get an output like this;
1.854365775829.521.854365775829.521.854365775829.521.854365775829.52
system
November 23, 2010, 3:38pm
18
Thank guys...it worked...the commands display the values on serial monitor exactly the way i want it to look like........
Thank peeps, especially PaulS