MegunoLink’s Property Table visualizer lists name/value pairs in a table. MegunoLink continuously looks at data in the serial stream from your Arduino for specially formatted commands to populate the table. The Property Table visualizer is useful for:
- Displaying current settings such as a temperature set-point
- Reporting state, such as battery voltage or motor direction
- Providing a summary of the last action your program took such as the speed and motor direction a linear stage was moved
Each row of a table lists a name, value and description. MegunoLink identifies each row by its name. So when you want to update the row, you supply the name and a new value and/or description:
1 2 |
Table MyTable; MyTable.SendData("Battery voltage", 3500, "mV"); |
Creating a Property Table Visualizer
Select Property Table from the visualizer menu or toolbox to add a new property table visualizer window to your MegunoLink project. You can add as many table windows as you like. Use message channels in your Arduino sketch to control the data sent to each visualizer.
Drag the visualizer tab to organize the windows in your MegunoLink project.
Property table controls can also be added to interface panels.
Sending Data from an Arduino
Create a Table
variable in your Arduino sketch and use its methods to send data and commands to the property table visualizer:
- Add
#include "MegunoLink.h"
to the top of your Arduino program, - Create a
Table
variable, then - Call
SendData
, for example, to send a named value to the table in MegunoLink.The property table Arduino reference as details of all the methods available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include "MegunoLink.h" #include "ArduinoTimer.h" Table MyTable; ArduinoTimer TableTimer; void setup() { Serial.begin(9600); } void loop() { if (TableTimer.TimePassed_Seconds(3)) { int BatteryVoltage = analogRead(A0); MyTable.SendData(F("Battery voltage"), BatteryVoltage, F("mV")); } } |
User Interface
The property table visualizer displays a list of name-value pairs in a table. The contents of the table may be freely edited by clicking in any cell. New values can be added either by serial commands received from your Arduino sketch or by entering a name and value pair in the last row.
The table can be sorted by clicking on a column heading. The order of rows can also be customized using the up and down arrow buttons on the toolbar.
Send the value of properties to the connected device. The Send All button sends all of the property values in the table while Send Selected sends only the property values selected.
Sending Properties to an Arduino Sketch
Send selected, or all, property values in the table to your Arduino sketch using the Send Selected and Send All buttons, respectively, on the visualizer toolbar. MegunoLink sends table property values using the format:
![property-name] [property-value]\r\n
.
You will need a serial command handler in your Arduino sketch, such as the command handler in our Arduino library, to receive and process property value messages sent from MegunoLink.
Here’s an example, using our command handler, that:
- periodically sends variable values to a table,
- updates the variable values in response to values send from the table, and
- updates the interval between sending values when a
UpdateInterval
property is received.
The UpdateInterval
property isn’t sent from the Arduino sketch here. Simply manually add a new row with the property name and value in the table.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
/* ********************************************************************************************** * Example program to send data to a MegunoLink property table and * receive property values back that update variables in the sketch. * Visit https://www.megunolink.com/documentation/property-table/ * for more information. * ********************************************************************************************** */ #include "MegunoLink.h" // for communicating with MegunoLink. #include "ArduinoTimer.h" // a timer to send data. #include "CommandHandler.h" // for handling serial commands. // Timer to keep track of sending data to MegunoLink. ArduinoTimer SendTimer; // Interval between sending updates to MegunoLink long UpdateInterval = 1000; // milliseconds. // Values we keep track of int Fish = 0; int Turtles = 0; // The table we are sending data to Table MyTable; // Command handlers to receive properties from MegunoLink CommandHandler<> SerialCommands; void setup() { Serial.begin(9600); Serial.println(F("Send data to MegunoLink table")); // Link variables to names we'll receive from MegunoLink // when the user sends properties from the table. See // https://www.megunolink.com/documentation/getting-started/processing-serial-commands/ SerialCommands.AddVariable(F("Fish"), Fish); SerialCommands.AddVariable(F("Turtles"), Turtles); SerialCommands.AddVariable(F("UpdateInterval"), UpdateInterval); // Set descriptions for the properties that we'll send // the the MegunoLink table. MyTable.SetDescription("Fish", "Lives in the sea"); MyTable.SetDescription("Turtles", "Very slow"); } void loop() { // Receive and process serial commands. SerialCommands.Process(); // Periodically send information to MegunoLink. See // https://www.megunolink.com/documentation/arduino-libraries/arduino-timer/ if (SendTimer.TimePassed_Milliseconds(UpdateInterval)) { MyTable.SendData("Fish", Fish); MyTable.SendData("Turtles", Turtles); Fish += 3; Turtles += 1; } } |