The challenge to take on today was one that is at the center of the functionality of the timing gate: wireless communication between two remote hosts.

An easy way to do this on small scales is with XBees, a small device made by Digi. Xbees allow simple wireless communication and can interface with a wide variety devices, making them an indispensable tool in many projects. As with the Arduino and Raspberry Pi, a further part of the convenience of using Xbees is how much documentation and support is available. For instance, interfacing an Arduino and Xbee is as simple as buying the Xbee shield pictured below to make plugging your Xbee into your Arduino a breeze.


Arduino Xbee Shield

For devices other than the Arduino, the Xbee can plug into USB ports with an Xbee explorer made by Sparkfun. See image below.


Xbee USB Explorer

Configuring Xbees

Xbees are highly customizable. They can work in one of two modes. In transparent mode, they simply act as a wireless serial communication (for an introduction to serial communication see here). Whatever is sent into the TX pin of one Xbee is sent out of the RX pin of the opposite Xbee. This means transparent mode is best for communication between only two devices. Neither host devices is aware of the Xbee, it simply sees a serial interface, thus the name "transparent." The other operation mode is API mode. When Xbees are configured in API mode, they act more like hosts and routers on a traditional TCP/IP network. Packets are sent wrapped in a proprietary version of the Zigbee protocol created by Digi. This allows for far more advanced network features, such as choosing destinations for individual packets, diagnostic tests such as pings to see if hosts are operational, and more. API mode is good for networks with many hosts that each need to communicate and are not in a permanent configuration.

We ended up going with transparent mode. Transparent mode works perfect for us since once we configure the two Xbees to point at each other, they need no additional configuration. How does one configure the Xbees to begin with? Using a piece of software called XCTU.

Using XCTU 

The first step is to get XCTU to recognize your Xbees. XCTU runs on desktop OSs so you'll need a computer and an Xbee explorer so you can plug your Xbee in via USB. When first opening the program, you'll see an interface like the one below. Click the button in the upper left with a "+" on it.

In the dialog box that appears, note the devices listed under "Select the Serial/USB port." Then, plug in your Xbee and hit "refresh list." Click on the device that appears and select "finish." A message saying "discovering radio modules connected to your machine" will appear for a period, after which you will be returned the main XCTU screen, except now your Xbee is added to the list on the left. Repeat for your second Xbee.

From here, there is some slight configuration to ensure that your Xbees are pointed at each other, but from then on you should never need to configure your Xbees again as long as they're used for the same purpose.

Below is a list of fields that may need changing. To configure an Xbee, click on it on the left and edit values on the right.

ID - this value needs to be the same for both devices. Leaving it at 7FFF will work fine.

DH/DL - These two strings determine where the Xbee is configured to send packets. For the Xbees to work properly, each should have their DH and DL set to the SH and SL of the opposite Xbee. For an example of this, see the below screenshot.

The DH of Xbee A is set to the SH of Xbee B. The same is done for DL and SL. 


Testing

After completing this configuration, your Xbees should be ready to communicate. To test, attach them both to your computer with Xbee explorers and switch the right side of your XCTU interface to console mode. This is done by clicking the console icon in the top right. You'll now be presented with a terminal like window that represents bytes sent and received by your selected Xbee. You can switch which Xbee's terminal is viewed by clicking on a device on the left. Click the white open button for both Xbees, then start typing in the left console window. Sent characters are in blue. Switch over to the second Xbee and you'll see your message relayed. The red indicates the characters have been received, as opposed to transmitted. Congratulations, you now have fully working bidirectional, wireless communication. 
"hello world" transmitted on Xbee A
"hello world" received on Xbee B