MegunoLink gets data for plotting from special commands sent by your Arduino. A typical command looks like this:
Using these special commands means MegunoLink can easily separate the different kind of data you want to send it.
You don’t have to remember the special commands though. We’ve made a library to send them.
An Arduino Sketch to Plot Data
Here’s an Arduino sketch to read a sensor value and send it to MegunoLink for plotting. In this example, the sensor is attached to analogue port 0.
Serial.println("Analog Sensor Plotter");
int SensorValue = analogRead(0);
MyPlot.SendData("My Sensor", SensorValue);
The first line of the sketch loads in the MegunoLink library, which contains support for easily sending data to MegunoLink.
Next up, we create a
TimePlot variable named
MyPlot. This represents a plot in MegunoLink. When you send data to this variable, it will take care of sending the right information down the serial link to MegunoLink. Check out the reference material on plotting for sending data to different plots.
Most of the rest of the sketch is standard Arduino code to initialize the serial port and read data from an analogue sensor.
The next interesting bit is on line 14, where we use the
SendData function sends the value measured by the
analogRead function (
SensorValue) to MegunoLink. It uses a series name of
MegunoLink can plot data from many different measurements on one graph. Each one will get drawn with a different colour and name. These are called series. So you could plot battery voltage, temperature and humidity all on one graph.
Plotting the data in MegunoLink
When you build and run the analogue plot sketch it will start spitting out serial messages like this:
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:
- To open a time plot, select
Time Plotfrom the visualizers’ menu on the toolbar, the start page or visualizer dock.
- Select the connection you want to use from the source selector. If you don’t have a connection yet, choose
Edit sources…and setup a new source with the Connection Manager.
In the plot visualizer, you can change axis labels, the chart title and edit the colours and styles used by each series. For more information on plotting and serial communication check out:
- Plotting Reference: plotting multiple series, changing plot properties, sending plot properties from the Arduino, exporting a graph, exporting graph data
- Connection Manager: connecting to multiple devices, using UDP communication with MegunoLink, preventing reset when connecting to your Arduino sketch.
- Reporting: save graphs to files periodically