An Arduino library for easy graphing on host computer via serial communication
by: Devin Conley
Features
Quickstart
Documentation
- Continuous multi-variable plots against time
- 2-variable "x" vs "y" plots
- Display multiple graphs within single resizable window
- Support for any data type that can be cast to a double
- Simply pass a reference to your variables when the graph is added, no need to update each value explicitly
- Control number of data points displayed on each graph
- Auto-scaling to fit all data on graph
- Configurable line color per variable
- Stand-alone listener application, written with Processing, is provided
Search for "Plotter" in the Arduino Library Manager.
or
Install manually with the ZIP file of Plotter.
Download one of the following stand-alone listener options. Keep the folder intact so the application can access the library and source folders. (Java Runtime Environment 8 required)
or
Download the source directory from this repository ( listener/ ) and run that with the Processing IDE.
Include library
#include "Plotter.h" Declare global variables. Any variable that you want plotted should have global scope. You will also likely want the Plotter object to be accessible globally.
double x; Plotter p; Create the Plotter object and add graphs as desired. When adding graphs, the first argument is a String with the title of the graph and the second argument is an int with the number of points displayed at any given time. These two arguments are followed by a String and your corresponding variable.
void setup() { p = Plotter(); p.AddTimeGraph( "Some title of a graph", 500, "label for x", x ); } Update variables as you normally would and call plot whenever you are ready. This example simply assigns arbitrary sine data.
void loop() { x = 10*sin( 2.0*PI*( millis() / 5000.0 ) ); p.Plot(); // usually called within loop() } Once the Arduino is running, start the listener application that you setup above.
The application will configure itself and your data should be plotted appropriately.
Add a 1-variable graph vs. time
- title: String with title of graph
- pointsDisplayed: number of points to be shown at a given time. Used to control time-scaling
- label1: String with label of the plotted variable
- variable1: global variable that will be updated throughout program
void AddTimeGraph( String title, int pointsDisplayed, String label1, Variable1Type variable1, String label2, Variable2Type variable2, ... )
Add a multi-variable graph vs. time
- title: String with title of graph
- pointsDisplayed: number of points to be shown at a given time. Used to control time-scaling
- label1: String with label of the plotted variable
- variable1: global variable that will be updated throughout program
- label2: String with label of the plotted variable
- variable2: global variable that will be updated throughout program
- ...
void AddXYGraph( String title, int pointsDisplayed, String labelX, VariableTypeX variableX, String labelY, VariableTypeY variableY )
Add an X vs Y graph
- title: String with title of graph
- pointsDisplayed: number of points to be shown at a given time. Used to control time-scaling
- labelX: String with label of variable to be plotted along X-axis
- variableX: global X-variable that will be updated throughout program
- labelY: String with label of variable to be plotted along Y-axis
- variableY: global Y-variable that will be updated throughout program
Send most recent values for all plotted variables to the listener application
Removes the graph at the specified position with zero-indexing. (ie passing 0 would remove the first graph added)
- index: position of graph to remove
- bool: true if successful
Sets the line colors for each variable in the graph at the specified position with zero-indexing. (ie passing 0 would set colors for the first graph added)
Options: "red", "green", "blue", "orange", "yellow", "pink", "purple", "cyan"
- index: position of graph to remove
- colorA: color for first variable
- colorB: color for second variable
- ...
- bool: true if successful. returns false when incorrect number of colors have been passed.


