Have you ever had one of those projects where, after spending hours preparing and reading up on background material, find yourself ultimately baffled as to why it is not working? That’s what happened here, and as it turned out, the solution was trivial in the form of a single line of Processing code. We’ll get to that later. The goal here was to get two Digi XBee RF modules to communicate over 802.15.4, in particular, a simple “Hello World” type of event in the form of a blinking LED.
Alright, here’s how it work. The first XBee is connected to an XBee Explorer from Sparkfun. This board is awesome because it takes care of the conversion of serial signals to USB. Furthermore it has LEDs which indicate when the XBee is receiving or transmitting data. Here is a picture of the Explorer itself, and my Explorer mounted with an Xbee and connected to the iMac via a mini-USB cable:


The Processing code for sending out bytes of data through the XBee and over the wireless is very similar to the code from the previous post:
import processing.serial.*; Serial myPort; void setup(){ println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); } void draw(){ myPort.write('x'); delay(1000); myPort.write('o'); delay(1000); }
The second XBee (receiving XBee) is connected to a breakout board (from Sparkfun) which allows the XBee which has 2mm pin spacing to be used on breadboards which commonly have holes compatible with .1″ pin spacing. Four wires are connecting the XBee to the Arduino (see picture below). The yellow wire provides 3.3 volts from the aptly named pin on the Arduino. The red and green wires connect the XBee’s DIN and DOUT, to the Arduino’s TX and RX pins, respectively. Finally, the black wire is connected to the ground pin of the Arduino. Technically, the voltage of the DIN and DOUT connections should be translated down to 3.3 volts, but actually works fine at 5 volts (The unit MUST be powered at 3.3 volts, however).

After about the 5th try, I was able to snap a picture that actually had the blinking LED in an ON state. The code that was loaded onto the Arduino was:
void setup() { Serial.begin(9600); pinMode(13, OUTPUT); } void loop(){ if (Serial.available()){ byte val = Serial.read(); if (val == 'x') { digitalWrite(13, HIGH); } if (val == 'o') { digitalWrite(13, LOW); } } }
There you have it, a proof-of-concept that wireless communication is possible using these XBee modules. Oh yeah, the trivial problem that I alluded to in the beginning of this post was that in the Processing code for the transmitting XBee, I had a loop() function instead of a draw() function. Yeah, don’t do that. Ok, here’s video proof that the LED is actually blinking, and that this whole thing isn’t a farce: