MegunoLink has two Visualizers for plotting data:
- Time-Plot: each data point is a single value used for the vertical axis; time is plotted on the horizontal axis
- XY-Plot: each data point has two values: one for the horizontal axis; one for the vertical axis.
The library sends data using special serial messages. MegunoLink decodes these messages to plot the data. A typical serial message looks like this:
The Arduino code to send the data would be:
The serial messages are created automatically by the library.
Sending Data from an Arduino Sketch for Plotting
In this example, we are plotting the value from a sensor attached to analogue port 0.
The Arduino sketch will read the sensor value and send it to MegunoLink. MegunoLink will plot the data on a Time Plot Visualizer in a series named “My Sensor”.
The 3 lines required to send the data to MegunoLink are highlighted.
int SensorValue = analogRead(0);
The key steps are:
- Line 1:
#include "MegunoLink.h"— loads the MegunoLink library, which includes support for easily sending data to MegunoLink.
- Line 3:
TimePlot MyPlot;— creates a
MyPlot. This variable represents a plot in MegunoLink. Its methods take care of sending the right messages down the serial link to MegunoLink.
- Line 13:
MyPlot.SendData("My Sensor", SensorValue);— the
SendDatamethod value in the
SensorValuevariable to MegunoLink. MegunoLink will plot the data in a series named
SensorValueholds the last sensor measurement, which was made using the
analogReadfunction on the previous line. (
SensorValue) to MegunoLink. It uses a series name of
When you build and upload the analogue plot sketch to your Arduino it will start sending serial messages like this:
Plotting the data in MegunoLink
To see this data plotted in MegunoLink, all you need to do is open a Time Plot visualizer and attach it to the serial port your Arduino is connected to:
Time Plotfrom the Visualizers’ menu to add a plot visualizer to your MegunoLink project.
Connection Managerfrom the Visualizer’s menu to configure the serial connection for your Arduino.
- Select the connection you want to use from the source selector on the Time Plot’s toolbar.
Plot Multiple Series on One Graph
MegunoLink can plot data from many different measurements on one graph. Each one will get drawn with a different color and name. These are called series. So you could plot battery voltage, temperature and humidity all on one graph using: