ZigBee Primer
A ZigBee PAN (personal area network) is a self-organizing series of modems that communicate using the same protocol (based on the IEEE 802.15.4 standard). Individual modems are configured to play a specific role within the network. Coordinators establish and organize the network (there is only ever one coordinator in a network). End Devices are the leaf nodes of the network, their responsibility is to provide valuable data. This data could be anything. It could be a power usage reading, a string relaying device status, or even a reading from a temperature sensor. The last type of configuration is the Router. Routers can act like End Devices and report data but the feature that makes routers special is that they act as network repeaters and extend the reach of the physical network. This paragraph is a very general overview of ZigBee, entire books have been written on the subject. If you wish to delve deeper into the intricacies of ZigBee I recommend that you pick one up to further your studies on the topic.
Required Materials
This blog post requires the following hardware:
2 x ZigBee Series 2 modems (either pro or standard)
2 x ZigBee Adapter Kits (some assembly required)
1 x FTDI Serial TTL-232 USB cable
1 x USB to UART TTL conversion module
(+ Your existing Raspberry Pi 2 / Windows IoT Core setup)
Additionally, you will need a serial terminal application on your PC, in this blog post I’ll be using CoolTerm for Windows. You will also need software to configure your ZigBee modems, this blog post will use XCTU.
Getting Started
After you have assembled your ZigBee adapters, it is time to configure the modems. Using the FTDI Serial TTL-232 USB cable, plug the USB end into your PC, and the other end into your ZigBee adapter board. The board is screen printed white where the cable is to be fitted (simply ensure that you’ve lined up the ground pin!).
Please note that the adapter boards are used throughout this blog post, so if I refer to “modem”, it means the modem and the adapter board that it is mounted on.
ZigBee Adapter Pins
Open the XCTU software, and discover the devices connected to the PC. Click the “discover” button, accept all defaults, and when found, add your modem to the selection list.
ZigBee Discovery Button
Let’s first configure a Router function modem. Start by assigning it a PAN id. This id can be any number you would like (I decided on 77 the jersey number of my all-time favorite hockey player, Ray Bourque!). The purpose of the PAN Id is to give the network an identifier. All modems assigned the same PAN Id will join together to form a network. Assign your modem a friendly name in the Addressing section, in the NI (Node Identifier) property. I named my modem “ZB_ROUTER_1”. Write these properties to the modem by clicking the Pencil icon.
ZigBee Router Configuration
Once the properties have been set, it’s time to update the firmware. When XCTU loads, it automatically pulls a copy of the latest firmware. Click on the Update Firmware button, and ensure that Router AT is selected as the function. Write the firmware to the modem.
Update Firmware Button
Update ZigBee Router Firmware
Disconnect your modem and repeat the configuration steps above to setup the Coordinator modem. In the properties assign the PAN Id as 77, Node Identifier as ZB_COORDINATOR, and set the Addressing DL (Destination Address Low) to FFFF (this will allow us to broadcast messages from the coordinator). Write these settings to the modem, and update the firmware, this time selecting the Coordinator AT function.
Update ZigBee Coordinator Firmware
The modems are now configured for use.
The Software Project
In this example, we will create a very simple UI that will run on our Pi. Open Visual Studio 2015 and create a new blank Universal Application. I’ve named mine “HelloZigbee”. Once the project is loaded, add a reference to the Windows Universal IoT Extensions.
Add the IoT Extension Reference
The Hardware Setup
You’ve already seen that ZigBee modems communicate as a serial device. Unfortunately, while the Pi itself does have UART pins, running the Windows IoT Core operating system reserves these pins for kernel debugging, so they are not available to us. This is where the USB to UART TTL Conversion module comes into play. We will be communicating serially to the ZigBee modem through this USB conversion board.
Take the modem that you’ve configured as the Coordinator and attach it to the USB to UART TTL Conversion module. You will need to connect Ground to Ground, 5V to 5V, the RX of the conversion module to the TX of the ZigBee adapter board, and the TX of the conversion module to the RX of the ZigBee adapter board. Connect the conversion module to a USB port on the Pi.
Serial Conversion Module
Next, use the FTDI Serial TTL-232 USB cable and attach the Router modem, then plug the USB end into your PC (just as you did when configuring the modem).
Running the Solution
On your PC, open an instance of CoolTerm. Connect it to the port associated with the ZigBee router that is currently connected. In order to see the information that you are sending across the wire, you’ll need to turn on local echo. To do this click on the Options button in the toolbar, select Terminal from the list box, and check the “Local Echo” checkbox.
Terminal Local Echo Preference
Ensure the USB to UART TTL conversion module with the Coordinator modem is connected to one of your Rasberry Pi USB ports, then power up your Rasberry Pi.
Once the Raspberry Pi is booted, deploy the HelloZigBee Universal application to the Pi (ARM, remote machine, select your Pi instance).
Application Running
Press on the Connect button. Once a connection has been made, the button will grey out and the Send and Read buttons will enable. Now you can have some fun chatting with yourself through your PC and Raspberry Pi! Type in a message to send to the Router modem by entering it in the textbox on your Pi and press Send. You will see the message display on the terminal on your PC. Next enter a message or two in the Terminal window of your PC. Then press the Read button on the Pi, and the message(s) will display on the Pi.
Coordinator sending a message to the Router
Router receiving message from coordinator
Router sending messages to Coordinator
Press the Read button to read the messages sent from the Router
In Conclusion
ZigBee communications are popular in the world of home automation and Smart Grids. This is just one of many ways that you can initiate conversations between devices, or create your very own sensor networks.
Comments