Update interface panel controls by sending serial commands from the Arduino to MegunoLink Pro. The article How to Quickly Make a User Interface to Control Your Arduino Program talks about making a new interface panel to send commands to your Arduino. In this article we look at how your Arduino program can send commands to MegunoLink to update text, numbers, progress bars and other controls on an Interface Panel.
To make it easier to send the right commands to MegunoLink Pro, we’ve built an Arduino library to control the MegunoLink Interface Panel. Download the MegunoLink Pro Arduino Library from GitHub and copy it into a sub-directory of the
libraries folder in your Arduno installation. The Arduino website has more information on Installing Arduino Libraries. To start using the MegunoLink Pro library, you’ll need to include it in your Arduino project. To include the library, add
#include "MegunoLink.h" at the top of your Arduino program.
Sending Values to Update Interface Panel controls using the library
InterfacePanel class exposes functions for sending data to MegunoLink Pro. To use these functions, first declare an InterfacePanel variable at the start of your program. The variable needs one parameter: the channel used by the message processor on your interface panel, more on that below:
// Useful tools for sending data to MegunoLink Pro
// The InterfacePanel variable used to communicate with MegunoLink Pro
The InterfacePanel variable has a bunch of functions that can be used to set controls:
SetText(ControlName, Value): sets the text displayed in a text box
SetProgress(ControlName, Value): sets the value shown by a progress bar
SetNumber(ControlName, Value): sets the value shown by numeric up/down and slider controls
SetCheck(ControlName, Value): checks or unchecks a check-box control
Each function takes two parameters:
ControlName: Identifies the name of the control on the interface panel. Find the control name using the properties browser in the interface designer. It is labeled (name).
Value: The new control value to set. It is a string for
SetText, an integer for
SetNumber, and a boolean (true/false) value for
Preparing an Interface Panel to Receive Data
For a Interface Panel to handler serial commands you need to add a MLPUIMessageProcessor component to your Interface Panel. The MLPUIMessageProcessor component looks for the text in the serial message that is used to set control values. You can find it in the Communications section of the Interface Designer toolbox. After placing the MLPUIMessageProcessor, set the channel name. This is the same channel name that is passed to the
InterfacePanel::Set* functions. The message processor only decodes messages with matching channel names. This lets you have several different interface panels in one MegunoLink Pro project without them interfering with each other. Set the channel name on the MLPUIMessageProcessor properties in the Interface Designer.
Pulling it Together
The data receiver demo is a MegunoLink Pro project and an Arduino program which demonstrates setting Interface Panel controls from an Arduino program. You can download a zip file with the MegunoLink Pro Project and Arduino Program.
The Interface Panel for the demo receiver project has four controls and one component:
- A label control for the title
- A text box for status updates; name=’Status’
- A numeric control showing the current value; name=’Current’
- A progress bar control showing progress; name=’Progress’
- A MLPUIMessageProcessor component to decode messages sent by the Arduino; channel = ‘Test’
The Arduino program sets the values shown in the text box, numeric and progress bar controls once per second as part of its main loop:
#include "MegunoLink.h" // Helpful functions for communicating with MegunoLink Pro.
// Millis value when the data was last sent.
// Progress value
// The interface panel we are sending data to
LastSent = millis();
Progress = 0;
if ((millis() - LastSent) > 1000)
LastSent = millis();
if (Progress == 0)
else if (Progress == 8)
Panel.SetText("Status", "Nearly there");
else if (Progress == 9)
Progress = (Progress + 1) % 10;