Daily Archives: March 8, 2017

How to Host XBee Sensors with the Raspberry Pi

Hosting sensors on the Raspberry Pi (RBPi) is so simple because the GPIO pins are all available. As most sensors need very little supporting components, hosting multiple sensors on your RBPi is possible. For instance, RBPi can simultaneously host multiple sensors for temperature, pressure, humidity, and other parameters for sampling atmospheric conditions from a weather station.

However, the RBPi does not support digitals signals on its GPIO pins. This is one reason the RBPi is so inexpensive. For accessing digital signals, the RBPi would need a digital to analog converter, preferably a 12-bit device with 4 channels.

Websites such as SparkFun and Adafruit carry a host of sensors and provide a huge amount of information about the products. Google also provides examples of using analog sensors with the RBPi. The restrictions of using only analog sensors and the 3.3 V maximum supply voltage makes the RBPi less versatile than its competitors such as the Arduino. In addition, on the RBPi you must run Python scripts as root, which makes it somewhat more difficult to do than doing so with the Arduino.

Other than connecting sensors directly to your RBPi, you can also consider using the RBPi as an aggregator node by using an XBee to connect to XBee-hosted sensors or Arduino-hosted sensors.

More specifically, you connect the remote sensor with the RBPi using XBee modules. For this, you will need to create a node first. Start with connecting the serial interface, which is a part of the GPIO header on the RBPi, to the serial interface on the XBee. Do not power on your RBPi or the sensor node, until after you have completed and verified all the hardware connections.

You will need an XBee breadboard adaptor and a breadboard. Plug in the adaptor on the breadboard. Now wire the 3.3 V and GND from the RBPi GPIO to the pins on your XBee adaptor. In case you are using the XBee Explorer Regulator from SparkFun, you may connect to the 5 V power line, as the XBee Explorer has an onboard regulator. The serial interface pins on the SparkFun board has the pins arranged in a header on the side of the board. This board also has the onboard regulator to protect the XBee, and you can connect the Explorer to the 5 V pin instead of the 3.3 V pin.

It is much easier to use connectors instead of wires. Therefore, consider soldering breadboard headers to the XBee adaptor and connect to the serial I/O header.

Next, connect the TXD pin of the GPIO on the RBPi to the DIN pin on the XBee Explorer. The RXD pin of the GPIO on the RBPi goes to the DOUT pin on the XBee Explorer. If using the SparkFun adapter, make sure you are connecting to the right pins—check the documentation for the same. Now take the coordinator XBee module and insert it into the XBee.

Before writing your own scripts, you need to download the special library from XBee. This provides a special Python module that encapsulates the XBee protocols and frame-handling mechanisms.