Feature-image-small

MegunoLink Pro supports communication over Ethernet networks using the User Datagram or UDP protocol. UDP is a simple protocol which is supported by the Arduino Ethernet libraries and Arduino compatible boards such as the EtherTen and EtherMega, both from Freetronics. UDP can also be used with shields including the Arduino Ethernet and WiFi shields.

The Arduino libraries makes it very easy to get started with Ethernet communication. This program will read selected analog inputs and send the data to MegunoLink Pro for plotting. Initially only the first channel is included, but you can toggle each ADC channel on or off by sending the channel number from MegunoLink Pro’s monitor window. The program was tested with the Freetronics EtherMega, but it should work with any Ethernet equipped Arduino. The latest version of the program is available on github.com

The first part of the program sets up some configuration we need. Like any internet device, the Arduino ethernet shield will need a MAC address and its own IP address. In theory the MAC address should be globally unique, but many Arduino devices don’t come with built-in MAC addresses. However, as long as the device is on a private network just pick a MAC address that doesn’t match any other device on your network. You’ll also need an IP address; this should be in the same address range as the IP address of your PC running MegunoLink Pro. To find out your PC’s address, open the Command Prompt (you’ll find it in the start menu) and type ipconfig. Look for the IPv4 Address; its probably something like 192.168.15.100. Normally you’d setup the Arduino to request an address from a DHCP server, but to keep things simpler, we can just make one up. The first three numbers should be the same as you’re computer’s address and the last number should be different to any other device on your network and between 1 and 254. If you don’t have many devices on your network, you can probably just pick one at random!

As well as its own IP address, the Arduino needs to know your computer’s IP address so it knows where to send the data for plotting by MegunoLink Pro. This is the destination address in the listing below.

You’ll also need a service port for each end of the connection. The service port lets several programs all listen for traffic on a single computer (on the PC end anyway). Each program uses a different port and this port number needs to be shared between the sender and receiver so the two ends know they are talking to the right program. The port can be the same, or different for each end. In this program I’ve used 8888 for both ends.

UDP data is handled by the ProcessUDPTraffic function, which is called each time the Arduino program runs through the main loop. This function checks for any UDP messages and reads them. It assumes the message is a single character which indicates which ADC port to toggle: 0 for the first ADC port, 1 for the second, etc. If a valid character is found at the start of the UDP message, it updates the array which keeps track of which ports should be graphed: EnableADCSend.

Reading the analog port and sending commands to MegunoLino Pro is handled by the SendADCData function, which is called each time through the main program loop. To avoid saturating the network, it doesn’t send data every time through the loop however. Instead, it keeps track of the last time a message was sent (the LastSend variable) and waits until the SendPeriod has passed before sending the next message.

At the appropriate time the function works through all of the ports and for any which are enabled, reads the ADC value and sends a message in the plot command format recognized by MegunoLink Pro.

To view the data sent by the Arduino program:

  1. Fire up MegunoLink Pro and create Time Plot, Monitor and Connection Manager visualizers.
  2. Select UDP from the Add Connection button on the Connection Manager visualizer to create a new UDP source.
  3. Set the receive port and the destination port to match the values chosen in your Arduino program. Set the destination address to 255.255.255.255, the UDP broadcast address (this saves having to remember the Arduino’s IP address).
  4. Set the source selector in the Monitor and Time Plot visualizers to the UDP port you just created and press the connect button

All going well, you’ll see data start to appear in the monitor window and on the graph. Type a number (0-7) into the control at the bottom of the Monitor visualizer and hit the send button. This will toggle transmission of data from the corresponding ADC channel adding and removing traces from the graph.

img_54ba2468ec7e4

Send data over an ethernet connection for plotting in MegunoLink Pro

That’s it for our simple example. Grab the files from GitHub; both the MegunoLink Pro project file and the Arduino source code are in there. Download a free trial for MegunoLink Pro, then post a message in the comments below and let us know how you’re using ethernet communication in your project.

Recommended Posts
Showing 2 comments
  • Mark
    Reply

    Great, thanks for sharing ๐Ÿ™‚

Leave a Comment

Start typing and press Enter to search