One message can consist of multiple parts. One part can consist of one label, one label and a value or only a value.
End of message symbol | \n |
Part separator symbols | ' '(space), '\t'(tab), ','(comma) |
Label-value separator symbol | : |
Label : Value | \n | ||||
Label 1 : Value 1 | \t | Label 2 : Value 2 | \n | ||
Label 1 : Value 1 | \t | Label 2 : Value 2 | ... | Label n : Value n | \n |
Label: | \n | ||||
Label 1 : | \t | Label 2 : | \n | ||
Label 1 : | \t | Label 2 | ... | Label n: | \n |
There is a special case, the CSV header style.
Label 1 | \t | Label 2 | ... | Label n | \n |
Note that in this format, labels consisting of only numbers are not recognised as labels.
It is safer to just use the normal label only message.
This is not recommended if you use a board with USB to UART converter. Because when the label is sent, before you had the SerialPlotter opened, then the label/labels get/gets never set.
Value 1 | \t | Value 2 | \n | ||
Value 1 | \t | Value 2 | ... | Value n | \n |
This example plots on line on serial plotter without setting a label
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue1 = analogRead(A0);
Serial.println(sensorValue1);
delay(100);
}
The output looks like this
10\n
11\n
12\n
13\n
14\n
This example sends the label once in the setup routine. Afterwards only the value is sent.
void setup() {
Serial.begin(9600);
Serial.println("Label 1:");
}
void loop() {
int sensorValue1 = analogRead(A0);
Serial.println(sensorValue1);
delay(100);
}
The output looks like this
Label 1:\n
10\n
11\n
12\n
13\n
14\n
This example sends the label every time together with the value.
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue1 = analogRead(A0);
Serial.print("Label 1:"); Serial.println(sensorValue1);
delay(100);
}
The output looks like this
Label 1:10\n
Label 1:11\n
Label 1:12\n
Label 1:13\n
Label 1:14\n
This example sends two values together with the labels.
void setup() {
Serial.begin(9600);
}
float avg = 0;
void loop() {
int sensorValue1 = analogRead(A0);
// send lable and value seperated by ':'
Serial.print("Value:"); Serial.print(sensorValue1);
avg = (avg * 4 + analogRead(A0)) / 5.0;
// send part devider '\t'
Serial.print("\t");
// send the second lable and value
Serial.print("AVG5:"); Serial.println(avg);
delay(100);
}
The output looks like this
Value:377 AVG5:431.01
Value:338 AVG5:408.81
Value:392 AVG5:395.85
Value:583 AVG5:427.28
Value:221 AVG5:383.42
Value:195 AVG5:343.74
Value:202 AVG5:314.19
Value:209 AVG5:292.15