kwartzlab makerspace

Posts Tagged ‘ZigBee’

Nov
19
2009

Arduino XBee communication

By » 2 Comments

This past week, i finally got 2 Arduinos (Arduini?) to communicate with the XBee shield. I wasn’t happy with the tutorials online, because these didn’t seem to tell you what you needed while at the same time included a lot of unnecessary info. Using ZNet 2.5 (Series 2) involves only one extra step.

The following parts were used:

Quantity Part Cost ea (CAD)
2 Arduino Duemilanove 33
2 Arduino XBee Shield v1.1 (includes XBee Series 2 module) 87
1 USB A B cable (salvaged) 0
1 Power adapter (salvaged) 0
Total 240

PFZ20-09781 Arduino with XBee shield


Basic Setup

The menu Tools –> Board –> Arduino Deumilanove w/ ATmega328 was selected.
The menu Tools –> Serial Post –> (appropriate port) was selected. Note the port needs to be selected each time a different Arduino is connected to USB. One automatically binds to COM3 and the other to COM4; there is most likely a setting somewhere to have these on the same COM port, but that would later preclude connecting both at the same time.


Testing the XBee

The shield and wireless module were assembled onto the Arduino. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:

Sketch: XBee_diagnostics

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

void loop()
{
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATID");
    echo();
}

void echo() {
    byte incomingByte;

    // see if there's incoming serial data:
    delay(50);
    while (Serial.available() > 0) {
        // read the oldest byte in the serial buffer:
        incomingByte = Serial.read();
        Serial.write(incomingByte);
        if(incomingByte != '\r') {
            Serial.write(' ');
        }
        delay(100);
    }
}

The Arduino was unplugged from USB, the jumpers switched to the inward position, then the serial monitor activated. The XBee should be responding with 234 as the ID (for Series 2).


Configuring

Use X-CTU to configure. Alternatively, any serial terminal will do. Note that the ATmega328 must be removed and the XBee shield pins placed in the outward position for this to work.

It may be preferred to configure the XBee module as part of a sketch and avoid removing the processor or finding a terminal program. The diagnostic sketch may be modified to with the following:

void loop()
{
    delay(2000);
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATDL FFFF");
    echo();
    Serial.println("ATWR");
    echo();
    delay(10000);
}

After configuring, the Arduino was unplugged fro USB.


Transmitter

The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:

Sketch: Send_physical_pixel

const int ledPin = 13;

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

void loop()
{
    digitalWrite(ledPin, HIGH);
    Serial.print('H');
    delay(1000);

    digitalWrite(ledPin, LOW);
    Serial.print('L');
    delay(1000);
}

The Arduino was unplugged from USB, the jumpers switched to the inward position. Then the Arduino was plugged into USB and the serial monitor activated. The serial monitor showed a string of HLHL… The LED was flashing at 0.5 Hz.

The Arduino was unplugged from USB, and the plugged this into the power adapter. The LED continued to flash at 0.5 Hz.


Receiver

Now for the second Arduino with XBee shield. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB and the following sketch Sketchbook –> Examples –> Communication –> PhysicalPixel was uploaded (unchanged).

The LED on the receiver is observed going on and off. However, not at regular 1 second intervals – the XBee sometimes groups the H and L sends together so these will be read at irregular intervals.


More Details

Note if you are in an area with ore XBee modules, then more configuration will be required to prevent all pairs from interfering with others.

Jumper meanings

When loading the Arduino while the XBee shield is attached, ensure the pins are in the USB position. Here’s a table of the explanation of jumper settings:

Position Meaning Connections Connections
Inward XBee Xbee.DOUT = Micro.RX = FTDI.TX Xbee.DIN = Micro.TX = FTDI.RX
Outward USB Xbee.DOUT = FTDI.RX Xbee.DIN = FTDI.TX

PFZ20-09787 XBee shield jumpers XBee

PFZ20-09786 XBee shield jumpers USB