API mode allows you to controll the functions of an XBee remotely, while at the same time sending arbitrary data through the XBee network. This is a more advanced, and in many ways more useful mode than the default Transparent mode.
The following projects are currently coverd on this page:
I started this project as a means to provide control panels for my Free-moN modules. Currently, All of the turnouts on each of my modules are electrically controlled using DCC accessory decoders and Tortoise switch machines.
Since Free-moN modules are used by unfamiliar operators at setups, you need to provide an easy to use control panel for each module. Because Free-moN modules do not have a "front" or "back", you need to be able to control every turnout from any side of the module. This implies you need to construct at least two control panels (one for each side) for every module that has an electrically controlled turnout.
At home, I use my Free-moN modules as a shelf layout, and I control the turnouts using either a JMRI control panel or a handheld DCC throttle. Even if I didn't use the computer or DCC throttle to control the turnouts, I would at most use 1 of the control panels for each module, so I feel there would be waisted effort building two panels for each module.
Using an XBee to control the local inputs of the DCC Accessory decoders provides several advantages over a hard wired physical panel.
The Accessory Decoder Interface Board provides the on-module connections for the remote controll panel. The Interface Board(s) consist of an XBee mounted on a Sparkfun electronics XBee Explorer Regulated, a power supply circuit, and a set of optical isolators.
The Power supply circuit rectifies an AC or DCC input voltage to 5VDC. 5VDC is fed to the XBee Explorer Regulated, which produces the 3.3VDC input voltage required by the XBee.
The optical isolators provide protection for both the DCC accessory decoder and the XBee. On the XBee side of the circuit, the optical isolator contains an LED. On the DCC accessory decoder side of the optical isolator, there is a phototransistor. The phototransistor acts like a light activated switch, completing hte circuit whenever the LED is on. As constructed, the boards include 4 seperate optically controlled switches.
A copy of the basic hardware schematic appears below.
Note two differences between the schematic above and the final interface. First, the Optocoupler's used were actually NEC PS2501-4 optocouplers, which provides all 4 optocouplers in a single chip. Second, the power supply used in the diagram above was the one I used when I breadboarded the circuit. The final circuit used a bridge rectifier and an LM7505 voltage regulator instead of the breadboard power supply shown.
The final circuit, connected to an NCE Switch-It, is shown below.
I have constructed a temporary hardware control panel for testing purposes. This control panel consists of an Arduino with an attached XBee Shield, and 8 buttons connected to digital inputs 2 to 9. When each of the buttons is pressed, the software loaded in the arduino sends an XBee command by utilizing the xbee-arduino api.
Arduino Source code for the prototype panel is available here
The final panel uses the same code as the temporary panel, but it is constructed in a slightly different manner. The panel uses 4 momentary spdt toggle switches to control each of the turnouts on the module. These toggle switches are connected to an Arduino Pro-Mini. For XBee communication, a Sparkfun ElectronicsXBee Explorer Regulated is connected to the Arduino Pro-Mini. The panel is battery powered with a rechargeable battery. A battery charge circuit us provided by a Sparkfun Electronics Power Cell. Power to the XBee and Arduino Pro-Mini is controlled via an SPDT slide switch. The inside and front of the panel are shown below.