Home › Forums › Mayfly Data Logger › XBee Networks of Mayfly Loggers – 900Mhz › Reply To: XBee Networks of Mayfly Loggers – 900Mhz
2019-06-10 at 6:01 PM
#12924
Here’s some sample code that I just put together to demonstrate the code for waking and sleeping the Xbee. You’ll notice it’s a little more complicated than just setting the D23 pin
Here’s some sample code that I just put together to demonstrate the code for waking and sleeping the Xbee. You’ll notice it’s a little more complicated than just setting the D23 pin high or low. That’s because the pin should be pulled high when you want to sleep the Xbee (like I mentioned in my previous post), and if you want to sleep the Mayfly (Mayfly sleep function not shown in the code below), you’ll want to enable the input pullup so the Mayfly pin still looks high to the Xbee unit, otherwise when the Mayfly sleeps, the Xbee won’t get the HIGH signal needed to keep it asleep and will therefore wake up.
It’s also a good idea to leave a few seconds before and after your payload transmission to give the Xbee network adequate time to do the behind-the-scenes payload transmission stuff.
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#define XBEE_SleepPin 23 void setup() { //Initialise the serial connection Serial.begin(57600); Serial1.begin(9600); //this is the Xbee UART, default Xbee speed is 9600 baud pinMode(8, OUTPUT); //Green LED pinMode(9, OUTPUT); //Red LED digitalWrite(8, HIGH); //turn on the Green LED and leave it on digitalWrite(9, LOW); //turn off the Red LED, we'll use it later to indicate Xbee wake pinMode(XBEE_SleepPin,OUTPUT); // Set the Xbee "wake-up pin" (D23) to output digitalWrite(XBEE_SleepPin,LOW); // wake-up XBee to start with Serial.println("Xbee Testing Sketch"); delay(2000); } void loop(){ wakeXbee(); delay(3000); //give the Xbee a few seconds to wake up and be seen by the network Serial1.println("This_is_the_xbee_payload"); //this is the text that gets sent via the Xbee RF module delay(3000); //give the Xbee a few seconds before putting it back to sleep sleepXbee(); delay(10000); // wait 10 seconds, then do it all over again } void sleepXbee(){ Serial.println("Putting the Xbee to sleep"); delay(100); pinMode(XBEE_SleepPin,INPUT_PULLUP); // Set the "wake-up pin" to input and enable the internal pullup digitalWrite(XBEE_SleepPin,HIGH); //put the Xbee to sleep digitalWrite(9, LOW); //turn off the RED LED when the Xbee is asleep } void wakeXbee() { Serial.println("Wake up the Xbee"); delay(100); pinMode(XBEE_SleepPin,OUTPUT); // Set the "wake-up pin" to output digitalWrite(XBEE_SleepPin,LOW); // wake-up XBee digitalWrite(9, HIGH); // turn on the RED LED when the Xbee is awake } |