The Arduino IDE has a handy tool to plot numbers generated by your code directly in the IDE. Great in principle, but the use of this feature is tricky since the documentation is nearly non existing. Here we'll look at the little documentation available we'll look at a basic example.

TLDR: Use this hidden documentation

Documentation

If you are reading this post, it is likely because there doesn't seem to be any good documentation to start with. I'm not alone in this feeling, someone reported this issue on Github. If you share this feeling I suggest you vote on that issue and/or actually help them out.

The Github issue also point to some actual documentation on this feature from the Arduino team.

Takeaway

Some things I took away from this hidden documentation:

First of, a message is a single line delimited by a newline. A message corresponds to a vertical slice in the plotter. So each vertical slice is done by writing <message>\n.

Secondly, you can plot basic numbers, or they can be labelled. Labels can either be set once in the setup, OR you can pass them along each line. I found the label variant to work best, so temp:30\n.

Now, if you use labels, don't add a space after the ":"!

So write:

temp:20

Do NOT write:

temp: 20

The latter does not work as expected and is hard to find if you don't recognize it!

If you want to plot multiple values, use a space, tab or comma delimiter. e.g.:

temp:30 humid:20\n

Finally, there does not seem to be a way to clear the plotter or only capture part of the serial output. So if you want to plot data and use log some other data, you are out of luck.

Plot something

A convenient way to plot a value with label is by writing this "one liner"

Serial.print("{{label}}:"); Serial.print(variable); Serial.print(", ");

Track as many variables as you want and finish with a newline:

Serial.println();

The following code shows how we can use this to display three labelled graphs:

int t = 0;

void setup() {
    Serial.begin(38400);
}

void loop() {
    double a = sin(t / 100.0);
    double b = cos(t / 110.0);
    double c = sin(t / 50.0) + 1.0;
    Serial.print("a:"); Serial.print(a); Serial.print(", ");
    Serial.print("b:"); Serial.print(b); Serial.print(", ");
    Serial.print("c:"); Serial.print(c); Serial.print(", ");
    Serial.println();
    t++;
    delay(40);
}

Upload the code and open the serial plotter (Tools > Serial Plotter).

Multi value labelled serial plotter example
Multi value labelled serial plotter example

Final words

Hopefully this will aid in your programming quest. Some closing tips:

  • If you get to many and/or garbled labels, try closing the serial plotter and opening it again. It may be that the plotter grabbed some garbage serial data.
  • As always, if uploading fails, reset the Arduino with your little reset button (if it's there). Close the serial plotter and maybe decrease the load on the serial line. You can for example increase the delay between the loop iterations.