The Arduino library bundled with MegunoLink provides classes to send data to our visualizers. There is one visualizer class for each visualizer, as shown in the table below. The classes provide methods for sending the data in the right format.
Using the Library
To use a visualizer class in your Arduino sketch:
- Install the MegunoLink library into your Arduino library folder
#include "MegunoLink.h"— to make the library available to the sketch
- Create an instance of the visualizer class. This just means creating a variable such as
- Call methods on the instance variable when you want to send data. For example:
MyPlot.SendData("ADC Value", analogRead(0));
The visualizer class variable can be in the global scope (at the top of your sketch), or in the function right before you use it. Generally it is easier to place it in the global scope, especially if you are using channels.
Data sent using the visualizer classes is sent to the Arduino’s
Serial port by default.
The destination can be changed when you create the visualizer class variable by using the two argument constructor:
ClassName(ChannelName, Destination). Here,
ClassName is one of the visualizer classes;
ChannelName is the name of the channel that data will be sent to (see below) and
Destination is the variable where the data will be sent. For example:
TimePlot MyPlot("", Serial2); will create a variable to send data to the default plot channel using
Serial2 on an Arduino Mega.
Any object based on the
- Other hardware serial ports such as
Serial3on the Arduino Mega.
WiFiClientcreated by a
WiFiServerfor TCP communications on a wireless network.
WiFiUDPconnection used to send UDP packets.
MegunoLink’s channels let you send data to different visualizers in your project. For example, if you had two graphs: one for temperature and one for battery voltage. You can use channels to send the temperature data to one graph and battery voltage to a different graph.
Visualizer classes send data to the default channel by default. To select a different channel, include it when you create the visualizer class variable. This example sends the data to a channel named
SetPoints. Refer to Message Channels documentation for information on selecting and managing channels in MegunoLink.
Visualizer Class Reference Pages
|Visualizer||Class Name||Library Reference|
|Time Plot||Time Plot Library|
|X-Y Plot||X-Y Plot Library|
|Interface Panel||Interface panel Library|
|Message Monitor||Message Monitor Library|
Here is a simple example that generates a cosine function and sends it to a time plot.
double t = millis();
double y = cos(2 * 3.141 * t/1000.0);