Go Down

Topic: Arduino Xbee series 1 + shield and having to re-Up (Read 1 time) previous topic - next topic


Greetings users,

I have 2 arduino duemilanove and 2 Xbee series 1 w/ libelium shields on both.
I've been reading the Making Things Talk book and have completed Chapter 6 tutorial on  XBee Analog Duplex sender p. 203.
I was able to get the sketch working and the two Xbee's communicating.  But one thing I noticed is that when I power off the Arduino/Xbee's and than power them back up they no longer communicate and I have to load up the code on each of them again.
Is that how they are?  Is there something I'm doing wrong and has anyone else experienced this problem?   :-?

Thank you!


I have a pair of Arduinos with XBee shields. When I power up the Arduino, the XBee shield gets power, and the XBee wakes up.

What you are seeing is NOT normal.

Could be hardware, software, or XBee configuration.

Post the code on the Arduinos, a link to the XBee shield you are using, and tell us about any XBee configuration that you did (firmware level, function set, etc.)
The art of getting good answers lies in asking good questions.


Thanks for your response.

this is for one Xbee.  of course the destination address is different for the 2nd Xbee

Here's the code:

Code: [Select]
#define sensorPin 0    // input sensor
#define txLed 2        // LED to indicate outdoing data
#define rxLed 3        // LED to indicate incoming data
#define analogLed 9    // LED that changes brightness with incoming value
#define threshold 10   // how much change you need to see on
                      // the sensor before sending
int lastSensorReading = 0;    // previous state of the switch

int inByte= -1;               // incoming byte from serial RX
char inString[6];            // string for incoming serial data
int stringPos = 0;           // string index counter

void setup() {
   // configure serial communication:

   // configure output pins:
   pinMode(txLed, OUTPUT);
   pinMode(rxLed, OUTPUT);
   pinMode(analogLed, OUTPUT);
 // set Xbee's destination address:
 // blink the TX LED indicating that the main program's about to start:

void setDestination() {
 // put the radio in command mode:
 // wait for the radio to respond with "OK\r"
 char thisByte = 0;
 while (thisByte != '\r') {
   if (Serial.available() > 0) {
     thisByte = Serial.read();
 // set the destination address with 16-bit addressing.  This radio's
 // destination should be the other radio's MY address and vice versa:
 Serial.print("ATDH0, DL1975\r");
 Serial.print("ATMY2010\r");    // set my address (16-bit addressing)

 // set the PAN ID.  If you're in a place where many people
 // are using XBees, choose a unique PAD ID
 Serial.print("ATCN\r");    /// go in to data mode:

// Blink the tx LED:
void blink(int howManyTimes) {
 for (int i=0; i< howManyTimes; i++) {
   digitalWrite(txLed, HIGH);
   digitalWrite(txLed, LOW);

void loop() {
 // listen for incoming serial data:
 if (Serial.available() > 0) {
   // turn on the RX LED whenever you're reading data:
   digitalWrite(rxLed, HIGH);
 else {
   // turn off the receive LED when there's no incoming data:
   digitalWrite(rxLed, LOW);
 // listen to the potentiometer:
 char sensorValue = readSensor();
 // if there's something to send, send it:
 if (sensorValue > 0) {
   // light the tx LED to say you're sending:
   digitalWrite(txLed, HIGH);
   Serial.print(sensorValue, DEC);
   // turn off the tx LED:
   digitalWrite(txLed, LOW);

void handleSerial() {
 inByte = Serial.read();
 // save only ASCII numeric characters (ASCII 0 - 9):
 if ((inByte >= '0') && (inByte <= '9')) {
   inString[stringPos] = inByte;
 // if you get an ASCII carriage return:
 if (inByte == '\r') {
   // convert the string to a number:
   int brightness = atoi(inString);
 // set the analog output LED:
 analogWrite(analogLed, brightness);

 // put zeroes in the array
 for (int c = 0; c < stringPos; c++) {
   inString[c] = 0;
 // reset the string pointer:
 stringPos = 0;


char readSensor() {
 char message = 0;
 // read the sensor:
 int sensorReading = analogRead(sensorPin);
 // look for a change from the last reading
 // that's greater than the threshold:
 if (abs(sensorReading - lastSensorReading) > threshold) {
   message = sensorReading/4;
   lastSensorReading = sensorReading;
 return message;


If you are using a Windoze OS, there is a program called X-CTU that can be obtained from digi.com. See the link here:

You can set PAN ID, MY and DL/DH for each XBee once, rather than every time the Arduino starts up.

Does the failure of the XBees to communicate come from a failure to successfully execute setDestination()?

If you configure them using X-CTU, you no longer need the setDestination() call or function.
The art of getting good answers lies in asking good questions.


Yes, they were both configured using X-CTU and I did Write the configuration to each Xbee.  That is fine.

It's after I upload the sketches to each of them.  They are working fine then.

But after I unplug the power adapters and plug them back in, the sketch is no long working and the boards are no longer communicating and I have to attach the USB and reUpload the sketch to each board to get the sketch working again.



Ok, I just reUploaded to one of the Arduino/Xbee boards and than I noticed it activated the other one.  So I didn't have to reUpload to both.  

continuing to troubleshoot....   :-?


What i have to do with my xbee's is to hold the arduino in reset (keep button pushed) while the xbee's form a network(?) after powerup. After that (let's say 3 seconds) i release the reset button from the arduino and the xbee's work as intended. If i do not do this the connection is not reliable. (works sometimes)

I do not know if this has got anything to do with your problem but could be worth a try.



If you've configured the XBees using X-CTU, then the setDestination() function is not needed. Try removing it, and see if that makes any difference.
The art of getting good answers lies in asking good questions.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131