The serial plotter

Graph the numbers your sketch prints, in the Plot tab beside Serial.

What it cannot see: only what the sketch prints. The x axis is the simulated time of the frame a line arrived in, so two lines printed in the same frame share a timestamp; nothing is interpolated, smoothed or filtered; and a line the current rule cannot read stays in the Serial tab rather than becoming a point. That line is the first thing on the panel, above the graph, and it does not scroll away.

Printing something to plot

Anything a board with a serial monitor prints. A bare number is a curve:

Serial.println(analogRead(A0));

Several numbers on one line are several curves, separated by a space, a comma or a tab:

Serial.print(reading);
Serial.print(',');
Serial.println(target);

And a label:value pair names its curve, which is what puts a word in the legend instead of #1:

Serial.print("temp:");
Serial.print(celsius);
Serial.print(" humidity:");
Serial.println(humidity);

That is the Arduino IDE's plotter format, on purpose: a sketch written for the IDE's Serial Plotter plots here without a line changed, and a sketch written here plots there.

The two rules, and why there are two

The button in the panel's head switches between them.

Numbers anywhere is the default. Every number on a line becomes a point and every word is ignored, so a sketch written before anybody thought about plotting plots as it stands. The weather station prints

reading 3: 23.4 C, 48 %RH

and two curves appear, 23.4 and 48. The cost is honest and is worth knowing: a banner with a number in it (DHT22 on pin 2) is a point too, and it lands on the first curve. Press Clear after the banner, or switch rules.

Whole line only is the Arduino IDE's rule: the line plots only if every token on it is a number or a label:value. Nothing spurious ever gets in, and a sketch that mixes prose with its numbers plots nothing at all. The status line under the graph says how many lines were left to Serial, so an empty graph always has a reason on the screen.

Either way, 0x1f is not 31 and an empty token is not nought: a number has to look like one (12, -0.5, +3, .25, 1e-3) or it is not one.

Reading the graph

The y axis is auto-scaled over the curves that are switched on and the window that is showing, with a tenth of the swing of air above and below, snapped out to a 1-2-5 step so the gridlines are on readable numbers. A flat line gets a box around it rather than being drawn as a curve of noise.

The window picker chooses how much time is on screen, from one second to five minutes. Older points are kept, not thrown away: widen the window and they are there again, and the CSV has all of them.

The legend is a button per curve. Click one to take that curve off the graph, which also takes it out of the scaling, so one curve that swings from 0 to 1023 cannot flatten the four beside it. The number on each key is that curve's latest value.

Pause stops adding points. The board keeps running and keeps printing, and the Serial tab keeps filling: this is a pause on the graph, not on the circuit, and the status line says so while it is on.

CSV hands over every point as a file: one row a moment, one column a curve. A curve that printed nothing at that instant gets an empty cell rather than a zero, because "did not say" and "said nought" are different things.

What it holds

Twelve curves and twenty thousand points each, oldest dropped first. A sketch that prints a fresh label on every line is a bug rather than data, so the thirteenth name is refused and the status line says so.

A plot belongs to one run. Pressing Run again starts an empty graph, because a curve carried across a restart would be two different circuits drawn as one.

Two examples to open

Weather station prints a temperature and a humidity every two and a half seconds, in a line with words in it: the default rule plots both, and the first reading's failure is a gap rather than a zero.

Knob dimmer on the ATtiny85 prints the reading it is dimming with, which is one curve that follows the knob as you drag it.

Both are in the editor's Examples menu.

See also