Xbee

Ok, I am pulling my hair out with these XBees.

I went through Cairn's tutorial on how to set them up (they are version 2s). But they wouldn't talk to each other.

So I have the Router all hooked up, XBee VCC to the 3.3V on my Duemilanove, GND to Ground, DOUT to Pin1, DIN to Pin0 (I had them the other way round but computer couldn't recognise it). Plus two status LEDs connected to the XBee and two connected to pins 2 and 3.

Here's the example code using the XBee Arduino Library:

#include <XBee.h>

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };

// Enter address of remote XBee, typically the coordinator
//Tx16Request tx = Tx16Request(0x1874, ACK_OPTION, payload, sizeof(payload), DEFAULT_FRAME_ID);

// This is the SH + SL address of remote XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40327712);
//SH = 13a200
//SL = 40327712

// unless you have set DH/DL for 64 bit this will be received as a RX16 packet
Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();

int pin5 = 0;

int statusLed = 2;
int errorLed = 3;

void flashLed(int pin, int times, int wait) {

for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);

if (i + 1 < times) {
delay(wait);
}
}
}

void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
xbee.begin(9600);

}

void loop() {

// start transmitting after a startup delay. Note: this will rollover to 0 eventually so not best way to handle
if (millis() - start > 15000) {
// break down 10-bit reading into two bytes and place in payload
pin5 = 10;
payload[0] = pin5 >> 8 & 0xff;
payload[1] = pin5 & 0xff;

xbee.send(tx);

// flash TX indicator
//flashLed(statusLed, 1, 100);
}

// after sending a tx request, we expect a status response
// wait up to 5 seconds for the status response
if (xbee.readPacket(5000)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);

// get the delivery status, the fifth byte
if (txStatus.getStatus() == SUCCESS) {
// success. time to celebrate
flashLed(statusLed, 5, 50);
} else {
// the remote XBee did not receive our packet. is it powered on?
flashLed(statusLed, 5, 500);
}
}
} else {
// local XBee did not provide a timely TX Status Response -- should not happen
flashLed(errorLed, 2, 1000);
}
}

The result is
// local XBee did not provide a timely TX Status Response -- should not happen
flashLed(errorLed, 2, 1000);
everytime.

What am I doing wrong here??? Am getting desperate, progress presentation on Friday!

The problem is you are using the Series 1 code. Here's the Series 2 sketch GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode

and API documentation:

http://xbee-arduino.googlecode.com/svn/trunk/docs/api/annotated.html