New Arduino Serial Plotter


With the release of Arduino IDE v1.6.6, a new tool was given to the users called the Serial Plotter. The idea of it is to be able to visualize the data you return, beyond just seeing numbers spit out onto the serial monitor. I’m a big fan of anything that lets people conceptualize the data their receiving in intuitive ways, so having a convenient graph generator in your IDE should be great.

What The Arduino Serial Plotter Is

The Arduino Serial Plotter is, as the name suggests, a software utility within the IDE that takes incoming serial values over the USB connection. Instead of just displaying the raw values to a TTY monitor, it graphs them against an X/Y axis. The vertical Y axis auto adjusts as the value of your output increases or decreases, and the X axis is a fixed 500 point axis with each tick of the axis equal to an executed serial println command.

Arduino Serial Plotter Axes Description

The plotter updates each time the serial line pops with a new value, which is to say, it updates slowly. Well, slow from a microprocessor standpoint.

Testing the Serial Plotter

We’ll start off by copying the example sketch that was displayed in the promo graphic for the release of v1.6.6.

Upload that sketch using v1.6.6 and then open the serial plotter by either clicking on Tools / Serial Plotter or pressing CTRL+SHIFT+L (on windows).

After the plotter opens up, you’ll see the sine wave begin to be drawn between -1.0 and 1.0 and back again. The function used in the sketch describes 20 values on the way up to to 0.84 and 20 values on the way back down to -0.84… 40 points to be plotted per duty cycle.

Arduino Serial Plotter Sine Wave

As soon as the plot hits the right edge of the window, it starts scrolling from right to left, and this is the first problem I have with it… there’s no way to stop it. There’s no “uncheck autoscroll” to buffer the values outside the display like there is in the serial monitor. If Serial.println(); keeps hammering away, your data scrolls off the left side of the graph without you able to do a thing about it.

Serial Plotter X Axis

The X axis is a fixed axis with each value representing one output of the Serial.println(); function. There is no time scale to speak of, really.

Ok, there is a time scale I suppose, if you use the baud rate of the serial monitor that you’ve set, but measuring time by how many serial outputs you received is a pretty crude way to measure anything

Along with that limitation, is the fact that the displayed axis is fixed at 500 points. It doesn’t matter how large or small you make your window, it’s still 500 points. Period. Sort of like a shift registers, when data point 501 shows up, data point 1 is lost. And since there’s no way to stop the plot from scrolling, you’ll need to compensate for this in your code.

To show what I mean, this sketch will generate a square wave from 100 to 50 to 100 to 50, and do it 5 times. Note that all the work happens in Setup as a crude way of ensuring it only executes once.

It doesn’t matter how the window is resized, the same 500 data points display regardless.

Arduino Serial Plotter 500 Point Limit

A particularly annoying issue that arises from having this fixed axis with no tick marks or indicating lines, is that you have no reference as to when something was measured. Look closely at the transition between 100 to 50. You can tell from the code that there is no middle value… no 75, no 94. But if you expand the graph…

Arduino Serial Plotter Value Transition

Without knowing when the values were measured, it’s not really possible tell from the plot if the transition was sharp and digital, or if it was fuzzy and analog.

Another problem is that the serial monitor and the serial plotter cannot be run simultaneously. It’s either one or the other.

Serial Plotter and Serial Monitor Not Compatible

Plotting Real World Data

So how can this be used in the real world?

In the I2C and SPI Education Series, I cover using the ADC to measure audio input signals at various sample rates.

So by hooking up the I2C and SPI Education Shield to an audio source, and loading up some of that code again, I should be able to plot the values using the serial plotter, instead of having to copy them out of the serial monitor and into Excel as I did when I wrote those tutorials back in April.

In a moment of glorious serendipity, it turns out the final code I wrote for measuring a 660Hz signal grabbed 500 data points by default, so we should be able to graph this without any overflow or scrolling.

I encourage you to go check out those links above to understand exactly how everything was setup, but essentially it’s a 660Hz signal source, connected through a very simple biasing circuit to allow the Arduino to measure the signal in a 0-5V range instead of chopping off all signal below 0V.

Of note, this is the code that records the 500 samples first, then sends the output to the serial lines, rather than chopping up the sampling rate with a bunch of clunky and slow Serial.println(); commands. It also makes use of PORT commands instead of digitalWrite(); to generate as many samples as fast as possible.

The end result, is actually pretty cool. Connect the Education Shield (or the MCP3008 Breakout Board) as described in those tutorials linked above to the signal source, upload this sketch and open the serial plotter.

Because the sampling rate is significantly high, the output on the serial plotter looks appropriately gorgeous…

Arduino Serial Plot of 660 Hz Signal

Unfortunately, because there’s no time scale listed, and no detail on the y-axis, you can’t really see into that signal to understand that it is a 660Hz representation. For all you know, it could be a 1Hz representation measured very slowly, since each tick represents not the sine wave, but a print command value.

Serial Plotter Bottom Line

Well, I think that it’s definitely a first version of what could eventually become a very useful utility. Using it right now requires a few items to be kept foremost when writing code to use the plotter.

  • Strangely, they released a feature they thought was so cool that they used it in their promotional blog announcement, but published zero documentation for it that I can find. There’s nothing in the official language reference for certain, and the release notes only state that it exists.
  • Only output numerical values. Non-number values (ie: text) aren’t displayed.
  • Be mindful of the 500 point limit. If necessary, build support into your sketch that will allow you to halt / pause execution so you can see a specific plot at a specific time. The most definitive way to do that would be with an interrupt service routine.
  • Remember that there’s no time scale, so the elapsed time between plot point 98 and plot point 99 could be 6.25ms or it could be 6.25 days. There’s no way to tell.
  • You can’t open the serial monitor simultaneously with the serial plotter. It’s one or the other. You won’t be able to keep both open to read the exact value being displayed on the plotter.
  • Since the plotter uses the USB to Serial Subsystem, that means your Arduino will reset each time you open it.