Arduino Graphing Libraries

Introduction

I believe strongly in plotting the data that I obtain, because plots tell you a story and they don’t mislead you like summary statistics can.

Often I want to plot data the arduino has acquired, but I find existing solutions don’t suit my needs. So I went out and made my own solution which writes a GNUPlot script in response to plot commands. I integrated the library with my general Arduino Toolbox (WDArduinoLib) and am releasing it under the GNU 2.0 License.

Goals

  • Professional graphics
  • Graphs manually editable after plotting for change colours etc.
  • Arduino outputs data that  other people can defiantly grab and use (just paste into a cloud based GNUPlot terminal)
  • Allow embedded linux system to offload the plotting of graphs from arduino collected data
  • Easy straight forward API
  • Linux, Windows and Mac compatible.
  • Quality API documentation

Features

  • Configurable output
    • You can use a Serial Port, SD-Card,  Telnet, TCP-IP, IrDA, whatever. So long as it derives from the Arduino Print class (ie has Print and Println()) this library can output a graph to it
  • Uses GNUPlot as a server to execute the plot script this API outputs.
    • GNUPlot is the standard for scientific publication, it outputs presentable graphics ready for both websites, and software manuals.
    • GNUPlot has been around forever (1986) and is still actively developed.
    • GNUPlot can run on the Raspberry pi, PC, Mac or even online via http://plotshare.com/
  • Extensible
    • Easily over-rideable classes to add new plot types or different output terminal (eg Matlab)
  • Built in quality colour palettes designed for graphing.
    • Sample palettes for showing importance, of keeping different coloured categories at the same intensity.
    • Spectral palettes , optimised for on-white graphing.
    • Colour-blind compatible palettes .
    • Can still use arbitrary 24bit RGB colours if you like.
  • Unit tested library to support quality software development
  • Template driven code designed for maximum data flexibility
  • Memory Efficient.
    • Use of progmem strings supported throughout.
  • Useful, stable data format that does not rely on someone’s pet project still existing in 5 years time.
  • All input, including text, is validated.

 

Examples

This library is simple to use and produces clean results with minimal configuration. I present several basic examples that show the API in use and the results obtained.


Example: Basic Line Graph

Line plots of time series data are probably the most important feature any graphing API targeted for micro-controllers can offer. This code creates such a plot. It demonstrates the use of multiple line styles.

Damped Sine Wave

 


Example: Plotting Points (Scatter Plot)

A scatter plots, with styles colours and trimmings.

Sine Wave with Noise

 


Example: Plotting Arbitrary Lines

Sometimes your not using time series data, and need to plot lines between arbitrary x/y positions. Many solutions for the arduino breakdown at this point. Here I demonstrate such a plot (based on the logarithmic spiral). Note I am using lines with point markers to show the actual points plotted.

Logarithmic Spiral


Example: Multi Column Bar Graph.

Bar graphs, for histograms and such are easy in this API. The example below shows support for multi column graphs, Note: negative values are also supported. The labels for the X-Axis are plotted as standard x values (the plot command is template driven and can support many different types of data).

Google Results for Instruments

Installation

 

  1. Get the library from its github repository.
  2. See the official guide on how to install libraries https://www.arduino.cc/en/Guide/Libraries
  3. Run the provided example sketch
  4. Install GNUPlot v5.0 or later (here).
  5. Using the com port viewer, copy the output of sketch into GNUPlot.
  6. Enjoy!

It is very possible to get the output generated by this library to GNUPlot automatically. How you achieve this is up to you.

It is possible to direct the output to a SD card. See the arduino help page on the file class, to create you own file on a SD card. Then pass the open file object in to the constructor for your plotting class (where I used Serial in the examples).

Documentation

Full documentation available here.

 

License

GNU 2.0

State

Most Features are well tested, but I don’t warrant or accept liability for any of the functionality in any way.

NB: some dynamic memory usage , refrain from using malloc during plotting operations to prevent possible heap fragmentation.

  • Dynamic memory usage is a design decision I made weighing pro’s and con’s of the situation.
  • Given ‘typical usage’ scenarios of the API it should not cause heap fragmentation.

 

Road-Map

May happen:

  • Second x/y axis support
  • Matlab support
  • 3d plots
  • Spectrogram
  • Support for cloud based rendering for graphs
  • Sage support
  • Thousands separator (right now I could not deploy it because of a bug in the windows version of GNUPlot).

Won’t Happen:

  • Real-time visualisation (plenty of other projects to do that already)