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.

Install the library to update interface panel controls

Install the MegunoLink Pro library into your Arduino libraries folder. You can download the library from GitHub.

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

The 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:

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 SetProgress and SetNumber, and a boolean (true/false) value for SetCheck

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.

A UI processor is used to update interface panel controls

To set control values from an Arduino program, add a MLPUIMessageProcessor component to your interface design. Then set the channel the Arduino program will use when communicating with the Interface Panel.

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 below.

Arduino program to set values on MegunoLink Interface Panel
Update interface panel text, number and progress controls

The Arduino program will set values of the text box (2), number (3) and progress bar (4) controls.

The Interface Panel for the demo receiver project has four controls and one component:

  1. A label control for the title
  2. A text box for status updates; name=’Status’
  3. A numeric control showing the current value; name=’Current’
  4. A progress bar control showing progress; name=’Progress’
  5. 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:

Start typing and press Enter to search