I had the same question yesterday and found a link to this:
println()
Description
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or ‘\r’) and a newline character (ASCII 10, or ’
'). This command takes the same forms as Serial.print().
Syntax
Serial.println(val)
Serial.println(val, format)
Parameters
val: the value to print - any data type
format: specifies the number base (for integral data types) or number of decimal places (for floating point types)
Returns
size_t (long): println() returns the number of bytes written, though reading that number is optional
Example:
/*
Analog input
reads an analog input on analog in 0, prints the value out.
created 24 March 2006
by Tom Igoe
*/
int analogValue = 0; // variable to hold the analog value
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog input on pin 0:
analogValue = analogRead(0);
// print it out in many formats:
Serial.println(analogValue); // print as an ASCII-encoded decimal
Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal
Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal
Serial.println(analogValue, OCT); // print as an ASCII-encoded octal
Serial.println(analogValue, BIN); // print as an ASCII-encoded binary
// delay 10 milliseconds before the next reading:
delay(10);
}
[Get Code]
I couldn’t believe it was that easy so I tried it.
I created and int on one Arduino, sent it to the other over I2C, then printed it to the serial monitor on the receiving
UNO.
Note that it says (ANY DATA TYPE).
If you want to print a floating point number I found this:
void setup()
{
Serial.begin(9600);
Serial.println(PI, 4); // should print 3.1416 (4 means four decimals)
float x = 2.12345;
Serial.println(x);
}
void loop() {}
Haven’t test that yet but I will tonight.
Hope that helps.