DescriptionThis time we are going to perform a system that executes specific tasks according to the communication between two XBee. As usual, we are dividing this practicaL exercise into two parts. The first one will show you how to configurate the XBee modules and the Arduino in order to blink a LED at the receiver part. The second part extends that functionality, so we are going to create a Morse code player, which reproduces the characters introduced on the sender side into Morse. To coordinate all this stuff we are going to use Python code with XBee libraries on the sender side.
- Hookup wires.
- 1 x Arduino board.
- 1 x USB A-to-B cable for the Arduino.
- 1 x XBee radio configured as ZigBee Coordinator API.
- 1 x XBee radio configured as ZigBee Router API.
- 1 x Breakout board.
- 1 x USB cable for the XBee.
- 1 x LED.
- 1 x Buzzer for output.
- Python . Download here.
- XBee library for Python . Download here.
- Pyserial library for Python . Download here or Download here 2.
- XBee library for Arduino . Download here .
Remember you can find the code used in the code section.
The first thing we must do is to install and configure python and the needed libraries for our purpose. After downloading the Python we should see a wizard like the shown on the image below:
|Figure 1: Python Wizard|
You only have to follow the steps and install it. If you want to execute Python programs with "cmd" tool you should add the directory of the Python to the "path" variable (System > Advanced system settings > Environment variables > System variables > Path ). After doing that you should see the Python version at cmd by typing "python":
|Figure 2: Python installation and configuration check|
To complete the configuration of the system we must install the XBee and PySerial libraries by the following way:
- Download the XBee library from the given link (if you have problems with it you can go to the 2nd link and pick the version that suits better to you computer).
|Figure 3: XBee library download|
- Install it by typing "python setup.py install" on the directory where you stored it (C:\Users\User\Destop\XBee-2.1.0 in our case):
|Figure 4: XBee library install|
- Download the "pyserial" library and to exactly the same to install it.
Now we have the software properly installed, but the last thing we must do before building the circuit and implementing the code is to set the XBee modules on the API mode. For the coordinator we set it as "ZigBee Coordinator API":
|Figure 5: XBee mode|
We do the same for the router ("ZigBee Router API"). We also have to enable the API mode at both XBee by setting the "AP" field with number 2.
|Figure 6: Enable API mode|
The circuit that we have to build by now is quite simple: a LED connected to the D1 port of the XBee (note that in this case we only use the arduino to feed the XBee):
|Figure 7: Circuit part 1|
The code that we must implement on the sender side will send packets to the receiver XBee (we can also send broadcast packets on the same PAN ID with dest_addr_long='\x00\x00\x00\x00\x00\x00\xFF\xFF') that will enable and disable the D1 port in order to let the current path and activate the LED. We also have to take into account in which port we have placed the XBee (COM5 in our case).
To execute it we go to the directory where it is placed and we type "python nameOfTheFile.py"
|Figure 8: Code execution|
Code Part 1 
Images Part 1
|Figure 9: Image Circuit Part 1|
In this second part we are going to change a bit the implementation of the sender side and we are going to add functionalities that the Arduino must implement in order to play the received characters in morse code. The figure below shows the International Morse Code, which we used at the Arduino code for the player:
|Figure 10: International Morse Code |
We have the same scenario as in part 1, but we have added a LED and a buzzer, which are connected to the Arduino in order to process the information received from the XBee (which receives the characters from the sender XBee).
|Figure 11: Circuit part 2|
The next step is to implement the "Sender" and the "MorsePlayer" codes and we will see how the LED is turned ON and the buzzers sounds when we receive a character, playing it in morse code. The caracthers are introduced through the keyboard using the Python console.
|Figure 12: Circuit part 2 (1)|
|Figure 13: Cicuit part 2 (2)|
|Figure 14: Circuit part 2 (3)|
Code Part 2: Sender 
Code Part 2: Morse Player
References Python software and libraries, retrieved from: https://www.python.org/
 XBee library for Arduino, retrieved from: https://code.google.com/p/xbee-arduino/
 Code for activate/desactivate D1 port on the receiver side by Jaume Barceló and Luis Sanabria
 International Morse Code, retrieved from: http://en.wikipedia.org/wiki/Morse_code
 Version of the code "modified3-blink-LED", by Jaume Barceló and Luis Sanabria