MegunoLink supports XBee networks with a coordinator plugged into your computer. The coordinator is the root of a XBee mesh network providing a gateway for many nodes to communicate with MegunoLink.

MegunoLink supports communication with a coordinator node in API 2 mode. API mode provides more robust communication with individual nodes than transparent serial mode. It helps ensure the payload from individual nodes doesn’t get mixed up. You can send data for time-plots, XY-plots, tables or any MegunoLink visualizer simultaneously from many nodes without it getting lost or garbled.

Add a UDP connection

Create a new connection by selecting XBee Series 2 Pro from the Add Connection menu.

During development you might like to create a serial connection to individual nodes as well. This allows you to use individual nodes serial port for sending debugging and diagnostic reports in addition to sending data over the XBee network.

Although XBee coordinators use a serial port for communicating with the host computer, you need to create a XBee connection, not a serial connection, so MegunoLink can apply the special decoding required to retrieve the payload for XBee networks running in API mode. If your XBee network is running in transparent mode, you should use a normal serial connection. In transparent mode, serial data from different nodes can be mixed together preventing MegunoLink decoding messages properly.

To create a XBee connection:

  1. Open a connection manager visualizer
  2. Choose XBee Series 2 Pro from the Add Connection drop-down menu

MegunoLink will create a configuration panel for the new XBee connection:

XBee Series 2 Pro configuration panel

The XBee Series 2 Pro configuration panel

The title box (top-left corner) lets you give the connection a name. This is useful to keep track when you have multiple sources: serial connections to each node as well as the coordinator connection, for example. The name you enter here will be displayed on the Connect button shown in visualizers.

The Port, Baud rate, Advanced and Reset controls let you configure and control the serial port that that coordinator is connected to. See Serial/ USB Connections for more information.

The Node Disc button initiates node discovery. This instructs the coordinator query the nodes attached to the network. Each active node responds to node discovery with its address. MegunoLink queries each node for its node identifier (NI register). You can change the node identifier using the XBee manager visualizer.

The address and identifier of nodes that respond are added to the drop-down list next to the node-discovery button. Any messages you send with MegunoLink, from the monitor or interface panel visualizers, for example, are sent to the node selected in the drop-down list. MegunoLink will receive and process messages from any node.

Click the Connect button to open the connection and begin receiving data. Only one program can use the port at any time so MegunoLink will show an error if another program (XCTU, for example) already has the port open.

Sending Data through an XBee Network

This sketch demonstrates sending for plotting through a XBee network. It is setup for two nodes to generate and send sinewaves to the coordinator for plotting in MegunoLink. The sinewaves are just convienent test data; you could use measurements collected from a sensor or any other data that you’d like to see plotted.

The test network contained two nodes — Node 1 and Node 2 each configured as a router — and a coordinator node, which was plugged into the computer running MegunoLink. Each node generates a sine wave and sends values through the XBee network every 200 ms for MegunoLink to plot. Node 1 generates a sinewave with a frequency of 0.4 Hz; node 2’s sinewave is at 0.5 Hz.

Each time a node sends a message through the XBee channel, it also writes to the serial port. This is often useful for debugging multi-node networks. So I’ve also opened a serial connection to each node and added a monitor visualizer for each node so we can see the debugging information.

The MegunoLink interface built for this example has (working clockwise):

  • a connection manager with:
    • 1 XBee Series 2 Pro source to a coordinator. This connection receives the data for plotting sent over the XBee network
    • 2 standard serial connections, one for each node. This lets us see diagnostic information from the nodes that can help troubleshooting wireless
  • A monitor showing the data received by the XBee coordinator
  • A plot showing data received from the XBee two nodes (blue for node 1, red for node 2)
  • Two monitor windows, one for each of the XBee nodes. These are connected to the serial ports for debugging and show the number of messages each node has sent
XBee user interface.

A user interface for testing XBee nodes with connections for the XBee channel and each node and a graph showing data sent over the XBee network

This example sketch demonstrates sending data from two nodes over a XBee network, for plotting. The same approach can be used to send debug messages, table data etc. To run this example you’ll need the following libraries:

  1. xbee-arduino, for communicating with XBee radios in API mode by Andrew Rapp
  2. Software Serial, to use pins D2 and D3 for serial communication with the XBee
  3. PString, a light-weight string formating library by Mikal Hart
  4. MegunoLink Arduino Library, to format the message for plotting data

You’ll need to make sure your XBee radios are running in API mode 2 (mode 2 escapes special bytes) at 9600 baud. Change the #define NODE 1 to #define NODE 2 for the second node. This configures the nodes to use different series names for the graphs and generate different frequency sine waves to make things more interesting.

Start typing and press Enter to search