XBee + Sparkfun shield + arduino board

Hi I am fairly new to xbee and arduino and had some questions about them. I would really appreciate any help.

I had a trouble getting the two xbee’s each attached to a sparkfun xbee shield http://www.sparkfun.com/commerce/produc … ts_id=9588 which are then hooked up to separate arduino boards to work. I have one XBee act as the transmitter and one as the receiver. The “receiver” XBee is not receiving any of the transmissions however.

CODE FOR THE “TRANSMITTER”:

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

void loop() {
  Serial.println('H');
  digitalWrite(13, HIGH);
  delay(1000);
  Serial.println('L');
  digitalWrite(13, LOW);
  delay(1000);
}

CODE FOR THE “RECEIVER”:

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

void loop() {
  if(Serial.available() > 0) {
    data= Serial.read();
    if (data == 'H') {
      digitalWrite(13, HIGH);
    } else if {
      digitalWrite(13, LOW);
    }
  }
}

I checked the RX/TX pin connections and that the switch on the shield that controls which pins serve as the datain and dataout pins was switched to the correct position, and the grounds are connected and the 5V on the arduino board is connected to that pin on the shield. Are there any other things to check with the setup or is there something wrong with the code?

I also tried using an existing library that the arduino site recommended but in order to use it I need the SH and SL of the XBee. I tried to access these through the command mode but was unable to enter command mode. The code for this is below and based largely on something I found online:

// serial out is on port 1
// serial in is on port 0

// a status light is on port 13
int ledPin = 13;

// a byte to send out data:
char thisByte = 0;


void setup () {
  // set pins to input and output appropriately
  pinMode(ledPin, OUTPUT);
  pinMode(switchPin, INPUT);

  // start up the serial connection with 9600-8-n-1-true (non-inverted):
  Serial.begin(9600);

  // blink the status LED
  blinkLED(ledPin, 3);

  // for some reason it seems to help to send an arbitrary character first
  //then pause for the guard time before requesting command mode
  Serial.print("X");
  delay(1100);
  // put the XBee in command mode
  Serial.print("+++");
   delay(1100);
  // wait for a response from the XBee for 2000 ms, or start
  // over with setup if no valid response comes

  
  if (returnedOK() == 'T') {
    // if an OK was received then continue 
  }
  else {
    setup(); // otherwise go back and try setup again
  }
  
  Serial.println("ATSH");
  while (Serial.available() == 0) {};
  char data= Serial.read();
 
  Serial.println("CN");
  

  
  // wait for a response from the XBee for 2000 ms, or start
  // over with setup if no valid response comes
  
   if (returnedOK() == 'T') {
    // if an OK was received then continue 
  }
  else {
    setup(); // otherwise go back and try setup again
  }

}


void loop () {
  blinkLED(13, 3);
}

void blinkLED(int targetPin, int numBlinks) {
  // this function blinks the status LED light as many times as requested
  for (int i=0; i<numBlinks; i++) {
    digitalWrite(targetPin, HIGH);   // sets the LED on
    delay(250);                     // waits for a second
    digitalWrite(targetPin, LOW);    // sets the LED off
    delay(250);
  }
}


char returnedOK () {
  // this function checks the response on the serial port to see if it was an "OK" or not
  char incomingChar[3];
  char okString[] = "OK";
  char result = 'n';
  int startTime = millis();
  while (millis() - startTime < 2000 && result == 'n') {  // use a timeout of 10 seconds
    if (Serial.available() > 1) {
      // read three incoming bytes which should be "O", "K", and a linefeed:
      for (int i=0; i<3; i++) {
        incomingChar[i] = Serial.read();
      }
      if ( strstr(incomingChar, okString) != NULL ) { // check to see if the respose is "OK"
//      if (incomingChar[0] == 'O' && incomingChar[1] == 'K') { // check to see if the first two characters are "OK"
        result = 'T'; // return T if "OK" was the response
      }  
      else {
        result = 'F'; // otherwise return F
      }
    }
  }
  return result;
}

This code never puts the XBee device into command mode. Again, I was just hoping for suggestions about how to get this working.

Have you arranged your code to see if any character(s) at all are received after +++?

Are you certain that the UART wiring and voltage levels are correct, to include the correct method of transforming 3.3V to 5V and vice-versa? Some SFE boards for the XBee had a diode in series with the data and this was an incorrect design.

Have you proven that the XBee is healthy and works in some other arrangement, and has the baud rate default at 9600Baud?

Hi,

All of steve’s questions are valid. I just want to chime in, if you are not sure how to verify your Xbees are happy, and working properly, you might benefit from this tutorial I wrote on working with XCTU, the Xbee configuring software.

http://www.instructables.com/id/Changin … aud-Rates/

I would suggest using a usb explorer or some other direct connection between the computer and the XBee to program it using XCTU.

I’ve gotten my XBees programmed and I have code that should make them communicate, but I can’t tell if my XBee coordinator is even sending data. They both have the same PAN ID and I’ve set the first XBee’s destination address to the second one’s serial number and vice versa. Is there anything else I need to do? Any help would be much appreciated.

If the PAN coordinator is configured to not use a beacon, then on the end node, an LED on the RSSI pin will light for a few seconds each time there is a received transmission.

Also, you can address the packet to the broadcast address (FFFF) so all nodes will receive it, in case you have a mistake in that area.

Of course PAN ID and channel # have to be consistent.

If you’ve configured for transparent serial mode, it should plug/play. Assuming XBee Series 1 products

What do you mean by the PAN ID must be consistent with the channel #?

Also, I’m using Series 2 XB24-ZB

GaTechEE:
What do you mean by the PAN ID must be consistent with the channel #?

Also, I’m using Series 2 XB24-ZB

Series 2 are ZigBee oriented. Not sure if they, like the series 1, can run with ZigBee disabled and merely use 802.15.4.

PAN ID of course must be known a priori by all nodes.

Channel number must also be known, in 802.15.4 networks. In ZigBee, nodes will scan a user defined set of channels looking for the PAN ID.