This page describes the functions and methods supported by the TimePlot
class for sending data, setting properties and controlling the Time Plot visualizer from your Arduino sketch. Check out our getting started with Arduino plotting guide for an introduction to plotting data in MegunoLink.
The TimePlot visualizer shows numerical data on a graph with time as the x-axis. Your computer’s time is used to time-stamp each value received from your Arduino sketch. Custom time strings can be sent using the raw message format.
Data is grouped in series for plotting. The series are identified with a Series Name and new values are appended to the series and shown on the plot as they arrive. You can assign different marker, line and axes to each series.
By default, all the data sent for plotting is shown in the visualizer. You can create multiple plots and control which data is shown on each using message channels. To use channels, supply a channel name in the TimePlot constructor.
Methods
The following methods are specific to Time Plots:
- TimePlot(ChannelName — optional, Destination — optional ) (constructor)
- SendData(SeriesName, YValue, SeriesProperties — optional )
- SendData(SeriesName, YValue, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendData(SeriesName, YValue, RGBColor, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendData(SeriesName, TimeStamp, YValue, SeriesProperties — optional )
- SendData(SeriesName, TimeStamp, YValue, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendData(SeriesName, TimeStamp, YValue, RGBColor, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendFloatData(SeriesName, YValue, DecimalPlaces, SeriesProperties — optional )
- SendFloatData(SeriesName, YValue, DecimalPlaces, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendFloatData(SeriesName, YValue, DecimalPlaces, RGBColor, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, SeriesProperties — optional )
- SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, RGBColor, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SetXRange(TimespanHours)
- Run(Enable)
- Stop()
The following methods, common to all plot visualizers, can be used to control the plot’s appearance:
- SetTitle(Title)
- SetXLabel(Label)
- SetYLabel(Label)
- SetY2Label(Label)
- SetSeriesProperties(SeriesName, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SetSeriesProperties(SeriesName, SeriesProperties)
- Clear()
- Clear(SeriesName)
- SetYRange(LowerLimit, UpperLimit)
- SetY2Range(LowerLimit, UpperLimit)
- SetYVisible(Visible — optional)
- SetY2Visible(Visible — optional)
Detailed Descriptions
The parameters and functions for Time Plot methods are given. Optional parameters are surrounded by []
‘s. Text parameters support memory strings and flash strings (where available).
Time Plot Constructor
Constructs a time plot variable, which can be used to send data, format and control Time Plot visualizers.
TimePlot([ChannelName], [Destination])
Name | Type | Required? | Description |
---|---|---|---|
ChannelName |
Text |
No | sets the channel used for all methods called on the variable. If missing, data is sent to the default channel |
Destination |
Print |
No | the stream used for all methods called on the variable. If missing, data is sent to the standard Serial port |
1 2 3 4 5 6 |
#include "MegunoLink.h" TimePlot MyPlot; TimePlot MyPowerPlot("Power"); TimePlot MyTemperaturePlot(F("Temperture")); TimePlot MyCurrentPlot(F("Current"), Serial1); |
Sending Data
Methods to send numeric data to a Time Plot visualizer. Select a function based on the parameters you want to supply.
SendData(SeriesName, YValue, [SeriesProperties])
SendData(SeriesName, YValue, Color, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, YValue, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendFloatData(SeriesName, YValue, DecimalPlaces, [SeriesProperties])
SendFloatData(SeriesName, YValue, DecimalPlaces, [Color], [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendFloatData(SeriesName, YValue, DecimalPlaces, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, TimeStamp, YValue, [SeriesProperties])
SendData(SeriesName, TimeStamp, YValue, Color, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, TimeStamp, YValue, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, [SeriesProperties])
SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, [Color], [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendFloatData(SeriesName, TimeStamp, YValue, DecimalPlaces, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
Name | Type | Required? | Description |
---|---|---|---|
SeriesName |
Text |
Yes | The name of the series the data belongs to. A series is a collection of points, optionally connected by a line. |
TimeStamp |
time_t |
No | A time-stamp for the data point. MegunoLink uses the computer’s time if a time-stamp is not supplied. |
YValue |
Number |
Yes | The y-value to add to the plot for SeriesName |
SeriesProperties |
Text |
No | A series property string to set the series style |
Color |
Plot::Colors |
Yes | One of the supported color constants to set the series line and marker color |
RGBColor |
32 bit number | Yes | A 24 bit RGB color. In hex the components are: 0xRRGGBB where RR , GG and BB are 8 bit values for the red, green and blue components of the color. |
LineStyle |
Plot::LineStyle |
No | One of the supported line-style constants to set the series line style. Defaults to Plot::Solid |
LineWidth |
Number | No | The thickness to draw the series line. Defaults to 1 |
MarkerStyle |
Plot::MarkerStyle |
No | One of the supported marker-style constants to set the series marker style. Defaults to Plot::Circle |
AxisOption |
Plot::AxisOption |
No | One of the supported axis option constants to set which axis the series is linked to. Defaults to Plot::DefaultAxis , which doesn’t change the axis the series is linked to |
DecimalPlaces |
Number | Yes | The precision to use when sending floating-point numbers. |
1 2 3 4 5 6 |
MyPlot.SendData("Voltage", 12); MyPlot.SendData("Voltage", 12, "r:s4"); MyPlot.SendData("Voltage", 12, TimePlot::Red, TimePlot::Dashed, 3, TimePlot::Circle); MyPlot.SendData("Temperature", 12.4); MyPlot.SendData("Temperature", 12.4, "r:s4"); MyPlot.SendFloatData("Temperature", 12.4, TimePlot::Red, TimePlot::Dashed, 3, TimePlot::Circle); |
X-Axis Limits
Change the time-span shown on the plot’s x-axis.
SetXRange(TimespanHours)
1 |
MyPlot.SetXRange(1.0/60); //1.0/60 = 1 minute |
Auto Scroll behaviour
Enable/disable the Time-Plot’s auto-scroll behavior. When auto-scroll is enabled, older data scrolls off the left edge of the chart. Data is not lost; zoom or pan to see data that has scrolled out of view.
Run([Enable])
: whenEnable
istrue
or missing, turns on auto-scroll; iffalse
, auto-scroll is disabled.Stop()
: stop auto-scroll; stops the plot from panning automatically.
1 2 3 |
MyPlot.Run(true); // enables automatic scrolling MyPlot.Run(false); // disables automatic scrolling MyPlot.Stop(); // disables automatic scrolling |
Example
This example sends the current voltage on analog channel 0 to MegunoLink Pro every 200 ms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "MegunoLink.h" // Helpful functions for communicating with MegunoLink. // Millis value when the data was last sent. long LastSent; // Interval (milliseconds) between sending analog data const unsigned SendInterval = 200; // [ms] // The plot we are sending data to. TimePlot MyPlot; void setup() { Serial.begin(9600); LastSent = millis(); MyPlot.SetTitle("My Analog Measurement"); MyPlot.SetXlabel("Time"); MyPlot.SetYlabel("Value"); MyPlot.SetSeriesProperties("ADCValue", Plot::Magenta, Plot::Solid, 2, Plot::Square); } void loop() { if ((millis() - LastSent) > SendInterval) { LastSent = millis(); int DataValue = analogRead(0); MyPlot.SendData("ADCValue", DataValue); } } |