Serial monitor question

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 :slight_smile:

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.

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()?

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.

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... :slight_smile:

Serial.print("1.854365775829.52");

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? :slight_smile:

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.

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?

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.

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 :slight_smile:

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.

Cause i want display 2 waveforms on Labview (Graphical Programming)....

O ya, sorry i made a mistake....Serial.print(", ") command will print the comma.... :stuck_out_tongue:

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? :slight_smile:

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.

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 :slight_smile:

The first statement prints the value without a carriage return/line feed. The second statement prints the value and a carriage return/line feed.

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

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