Data for plots, tables and monitor visualizers is normally sent periodically. If MegunoLink isn’t connected at the time, data is lost but there are no other consequences. However, property information, such a graph titles, table descriptions or initial values for interface panel controls are usually sent infrequently and perhaps only once. If MegunoLink is not connected when this information is sent the user interface may not behave as expected.

There are several solutions to this problem. The most straight forward is sending initial settings from the Arduino setup() function and have MegunoLink reset the device whenever it connects. However, it is often helpful if the Arduino sketch does not restart every time a connection is opened. If MegunoLink has just been started, however, it may not have the current settings from your Arduino sketch. In this situation, you could either send the configuration information every few seconds or have MegunoLink send a command when it connects. Your Arduino sketch then replies with its current settings. This article explores these different options.

Reset on connection

Newly created serial connections automatically reset compatible Arduino boards whenever you open the serial connection. This is the same behavior used by the Arduino serial monitor and uses the same mechanism that the Arduino IDE employs to trigger the bootloader and load new programs onto your Arduino.

To make sure MegunoLink is configured to reset your board on connection, click the Advanced button in the connection manager visualizer (when the serial connection is closed) to open the serial port settings. Make sure the Disable DTR and Disable RTS are not checked. Note: the board might not reset the first time you connect after changing these settings (depending on the state of the DTR/RTS pins and board design).

Reset on serial connection

Make sure Disable DTR and Disable RTS are not checked for your Arduino sketch to reset whenever a serial connection is opened for most Arduino boards.

With your Arduino sketch resetting every time MegunoLink connects, all the initial settings can go into the Arduino setup function, which runs whenever the device is reset.

For example, you might want to set title, axis labels on a graph and initial values of an interface panel control:

Send configuration periodically

The downside of resetting the device to send settings to MegunoLink is that you may lose any state information (e.g. filter history, motor location, set-point) that has not been saved to the device eeprom. To avoid this, you could simply put the configuration in its own function and send it periodically. Then MegunoLink will receive the updated settings within a short period, whether the device is reset or not when the connection is opened. For example:

This approach works best for settings the user is unlikely to change in MegunoLink. That could include things like graph titles or property descriptions in tables. Sending control values to an interface panel may frustrate the user if the the control values they are updating are overwritten by commands from your sketch.

Send on connect

Sending data periodically can overwrite changes the user makes in MegunoLink, a particular problem for interface panels where continually updating control values from your sketch might prevent the user entering new values.

A SerialConnection component on an interface panel visualizer helps solve this problem. The SerialConnection sends a command shortly after MegunoLink opens a connection. So you can have your Arduino sketch send initial settings to MegunoLink by adding:

  1. a command in your Arduino sketch (using our command handler, for example) to send initial settings to MegunoLink, and
  2. an interface panel with a SerialConnection component in your MegunoLink project that sends the initial settings command.

Here’s a simple example that configures a time-plot and sends the current plot data update interval to an interface panel control. The settings are updated at startup and when a !SendConfig\r\n command is received. A SerialConnection on the interface panel sends !SendConfig\r\n whenever the serial connection is opened. The configuration is also sent in the setup() function. So updated settings will be sent to MegunoLink if the Arduino is reset while the serial connection is opened.

Select Library ExamplesInitializingSettings in MegunoLink to open this example.

Interface panel setup for sending a command on connect

Use the SerialConnection component to trigger update of MegunoLink settings from your Arduino sketch.

For more information…

Start typing and press Enter to search