Xbee sleeping issue

Hello!

I have a project in which I want to set Xbee on sleeping mode. I have struggled with this one for some time already. So, I am using following code.

int digipin = 9;

void setup()

{  

 Wire.begin(); // I2C connection start
 Serial.begin(9600); //open serial in baud rate

 delay(2000);
 //setCommands();
 pinMode(digipin, OUTPUT);
}

void loop()
{
 //Serial.print("Node ready.");
 //update();
 sleep();
delay(8000);
 digitalWrite(digipin, HIGH); // this is trying to wake up Xbee, not working
}

void sleep(){

 Serial.print("+++");
  char thisByte = 0;
  while (thisByte != '\r') {
    if (Serial.available() > 0) {
      thisByte = Serial.read();
    }
  }
  Serial.print("ATSM1\r");
  Serial.print("ATCN\r");

}

This code has commented lines, which are the most important ones on reading the sensors (update()) and defining the network(setCommands()) etc. The problem is that when I uncomment these to act part of the program Xbee won't go to sleep anymore. Even when I test the code with normal "Serial.print" the sleep doesn't work either.

Second problem is to wake up the node. I am trying to do it with line "digitalWrite(digipin, HIGH)", but doesn't work.

Obviously there is something that I haven't understood here.

Help would be highly appreciated.

The problem is that when I uncomment these to act part of the program Xbee won't go to sleep anymore.

Since you didn't post them, it's hard to see what they do, and why including them causes the XBee insomnia.

How do you know when the XBee is sleeping vs. awake? Does it snore?

Even when I test the code with normal "Serial.print" the sleep doesn't work either.

The XBee is transmitting the serial data, so it seems logical that it needs to wake up to do this.

Thanks for the reply.

How do you know when the XBee is sleeping vs. awake? Does it snore?

I don’t hear Xbee snoring :), but since the led on the chip stops blinking and power goes down (measured with multimeter), I decided to believe that it’s sleeping.

The XBee is transmitting the serial data, so it seems logical that it needs to wake up to do this.

Yes I know that, but I try to put Xbee sleeping after all the serial activity is done. But your remark actually set me to right direction, finding the problems from serial operations.

Here is what I discovered.

End of the “update()” function I have code line that does the following:

  if (value <= 43 || value2 <= 30){
    Serial.println("something");
   }
  else if(value > 43 || value2 > 30){ 
   Serial.println("something else");
  }

When I change “println” to “print” Xbee goes to sleep mode. Also on “setCommands()” function I have following lines at the end:

Serial.print("ATDH0\r"); 
Serial.print("DL8119\r");  
Serial.print("ATMY1999\r");    
Serial.print("ATID2403\r"); 
Serial.print("ATCN\r");    // command mode exit

When I take the command mode exit out Xbee goes to sleep mode.

At least this solves the sleeping issue. Next I have to wake up Xbee.

Ok, so I am not able wake Xbee. I really don't know what to do. I am using following code, which is called from loop() to make Xbee to sleep

void set(){
delay(5000);
  Serial.print("+++");
  char thisByte = 0;
  while (thisByte != '\r') {
    if (Serial.available() > 0) {
      thisByte = Serial.read();
    }
  }
  
  Serial.print("ATSM1\r");
  Serial.print("ATD70\r");
  Serial.print("ATCN\r");
  

delay(10000);

Obviously setting SM back to 0 doesn't work.

Also the cyclic sleep works by following code:

void set(){
delay(5000);
  Serial.print("+++");
  char thisByte = 0;
  while (thisByte != '\r') {
    if (Serial.available() > 0) {
      thisByte = Serial.read();
    }
  }

 Serial.print("ATCE0\r"); 
  Serial.print("ATSM4\r");
  Serial.print("ATST 157C\r");  // time before sleep 5.5 sec
  Serial.print("ATSP 1F4\r"); // sleep time 5 sec
  Serial.print("ATD70\r"); //not to reset Arduino
  Serial.print("ATCN\r");
}

In this I try to set SM to 0 and 7 pin to 1, which doesn't put it back to normal mode. I don't mind which one of these modes I am using, I just want to wake up Xbee completely and put it back to sleep when upcoming sensor readings and radio transmit operations are done.

I am using following devices:

Xbee expansion shield http://shieldlist.org/dfrobot/ioexpansion-v5

With Xbee series 1 radio and Arduino Uno.

I would appreciate any hints!

Ok, I was missing the point about Xbee and shield pin connections. So I needed to wire pin 9 from Xbee to the shield. Then using following lines when ever I need to sleep and wake up:

uint8_t digipin = 8; // D8 pin wired to pin 9 in Xbee
pinMode(digipin, OUTPUT); //defining Xbee sleep pin to output

...

Serial.print("+++");
  // wait for the radio to respond with "OK\r"
  char thisByte = 0;
  while (thisByte != '\r') {
    if (Serial.available() > 0) {
      thisByte = Serial.read();
    }
  }

Serial.print("ATSM1\r"); //sleeping mode
Serial.print("ATD70\r"); //preventing Arduino reset while Xbee on sleep

...

digitalWrite(digipin, HIGH); //XBee going to sleep

...

digitalWrite(digipin, LOW); //wake up XBee

Hello,

I also have a problem with my XBee for his wake. I use the command "ATSM1"(which is not in my program, I've done with X-CTU) because I want to sleep by myself. I can do to sleep and wake up but the big problem is that it takes 12 seconds to wake up, it's too much! Is it possible that I can reduce his waking hours? I would like it between 3 and 5 seconds to wake up. Another problem, I use xbee : XBP24-ZB, version 2264, why can't I use "ATSM2"? Sorry for my bad english. Thank you in advance

Hello darkduino,

I have the same problem as you, I use ATSM1 and the wake-up time is very long (around 10-12 seconds).
Did you find and resolve the problem?

Thanks!