The Arduino library bundled with MegunoLink provides classes to send data and commands to our visualizers using MegunoLink’s brace protocol. There is one visualizer class for each visualizer, as shown in the table below.
By default, messages are sent through the Arduino’s
Serial port, though this can be changed. Data and commands are generally received and processed by all visualizers. Use channels to direct commands and data to specific visualizers.
Visualizer Reference Pages
The methods available for sending data and commands to a visualizer are described in detail, with examples, on the following pages.
|Visualizer/Component||Class Name||Library Reference|
||Time Plot Library|
||X-Y Plot Library|
||Interface panel Library|
||Message Monitor Library|
||Record Table Library|
|Device Test Result||
||Test monitor library|
|Audio clip playback||
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.
Flashstrings are commonly used to save RAM, and you can certainly use flash strings with the MegunoLink library. However, the trick that the handy
F("...") macro uses to place text in flash memory doesn’t work for global variables. You’ll get a confusing compiler error instead. Use this pattern for placing strings in flash memory when creating a global visualizer variable with a channel:
const char PlotDestination PROGMEM = "Voltage";
TimePlot Plot((const __FlashStringHelper*)PlotDestination);
PROGMEM keyword forces the string
Voltage to be placed (only) in flash memory and the
(const __FlashStringHelper*) cast makes sure the compiler uses the
TimePlot constructor that expects the destination to be in flash memory.
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);