Hi All,
Could you help me to check my code for a simple Xbee sleep test.
I am not sure I fully understand the process of putting the radio to sleep.
Currently with this code the power consumption goes from 130mA to 70mA.
My bug is that when I press the button power goes down to 70mA but back up to 130mA after i released it.
Then if I leave everything alone for a few seconds power overs between 70mA and 110mA.
What I am missing ?? Is the fluctuation because of the Arduino Nano still working, so needing power ?
Is my code reversed to put the Xbee in sleep - I thought the pin needs to be low to trugger sleep and High to wake it.
Thanks.
#include <SoftwareSerial.h>
// RX: Arduino pin 2, XBee pin DOUT. TX: Arduino pin 3, XBee pin DIN
SoftwareSerial XBee(2, 3);
// Declare pin numbers for feedback LEDs 1 thru 4
const int LED1_pin = 12;
// Declare pin numbers for bell and light buttons
const int BTN_Light_ON = 7;
int BTN_Light_state = LOW; // low = not pressed
int wake_pin_state = LOW;
// Declare sleep pin on arduino for DTR (pin 9) pin of Xbee
const int XBee_wake = 5; // pin number
void setup()
{
pinMode(LED1_pin, OUTPUT);
pinMode(XBee_wake, OUTPUT);
pinMode(BTN_Light_ON, INPUT);
// Initialize XBee Software Serial port. Make sure the baud
// rate matches your XBee setting (9600 is default).
XBee.begin(9600);
Serial.begin(9600);
}
void loop()
{
BTN_Light_state = digitalRead(BTN_Light_ON);
if (BTN_Light_state == HIGH) {
digitalWrite(XBee_wake, LOW); // wake xbee to send
wake_pin_state = LOW;
delay(10); // pause to give it time to wake up
XBee.write('L'); // light btn is pressed
Serial.println("Xbee is awake, just sent L");
delay(3000); // long delay to allow me to read the monitor
}
// put the XBee to sleep
if (wake_pin_state == LOW){
Serial.println("Wake pin state was low so entered if - about to pause 5 seconds and sleep Xbee");
digitalWrite(XBee_wake, HIGH);
delay(5000);
Serial.println("Xbee should be sleeping");
wake_pin_state = HIGH;
}
}
