« October 2008 | Main | December 2008 »

November 2, 2008

Wireless Communication Working

As it turns out the supplier that we purchased the Xbee Arduino shields from, switched from the XBee Series 1 to Series 2 -- which does not support out-of-the-box virtual-wire communication.

To make a long story short, I got the two Xbee units up & running using a "virtual wire". (As in the Arduino is just using the standard communication methods)

See the video:

The Arduino on the left (powered by the Mac), is commanding, via Xbee, the Arduino on the right (powered by the PC) to turn on/off the LED every second.

Midway through the video I unplug the transmitting Arduino, to show the effect it has on the receiving -- the light stops blinking.

See the extended entry for sketch code

~Zeb "Is not happy with Sparkfun Electronics right now" GrandPre

The Xbee units had to be programmed separately of the arduinos using Max-Streams (the maker of XBee) software. This may work to our benefit as I had to spend some time acquainting myself with the datasheet & creating a network for the two units. (called a ZigNet)

I was a little concerned the other design group (Solar House) that is using the Xbee units might interfere with our communication, so I created a unique network ID (which offers optional encryption). I gave the network the ID# 1337, for obvious reasons.

Here are the two Arduino's source code:

****************Transmitting Code***********

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print('H'); //instruction to turn LED ON -- but really could be anything
delay(1000);
Serial.print('L'); //instruction to turn LED OFF
delay(1000);
}

**************RECEIVING CODE*******************

int outputPin = 12;
int val;

void setup()
{
Serial.begin(9600);
pinMode(outputPin, OUTPUT);
}

void loop()
{
if (Serial.available()) {
val = Serial.read();


if (val == 'H') {
digitalWrite(outputPin, HIGH); //turn LED ON
}
if (val == 'L') {
digitalWrite(outputPin, LOW); //turn LED OFF
}
}
}