The advantage of a wireless connection is that devices do not require physical wires to communicate with one another. So, it also makes sense if they use batteries instead of mains AC power. However, battery life can also pose a major limitation to this freedom: depending on the location of the device, it can be difficult or expensive to replace the battery.
XBee modules are low-power devices. They can put themselves into a temporary sleep state in which they consume virtually no current. During sleep, the device is almost completely turned off and is sometimes incapable of sending or receiving data until it wakes up.
Imagine that you have several greenhouses, each with a temperature sensor connected to an XBee. Fully charged batteries would only power the modules for one day. What could you do to maximise the life of those batteries? Putting the modules into a cycle where they sleep for one second and then wake for one second before sleeping again could double the battery life to two days. Cyclically sleeping for 59 seconds and then waking for one second might keep the same batteries going for 60 days. Taking this further, it would be possible to extend the battery life for years.
Of course, before using sleep mode you must take into consideration the structure of your project and how the XBee network is formed. The greenhouse modules described above are an excellent candidate for sleep mode because they only send data periodically and are not expected to receive data. The modules can therefore be sleeping most of the time and wake up only to send the temperature value.
Sleep modes
XBee ZB end devices support three different sleep modes:
- Pin sleep (SM = 1).
- Cyclic sleep (SM = 4).
- Cyclic sleep with pin wake-up (SM = 5).
An end device in one of these sleep modes polls its parent every 100 ms. while it is awake to retrieve buffered data. When the module enters sleep mode:
- The On/Sleep pin (pin 13) is de-asserted (low) to indicate the module is entering sleep mode.
- If CTS hardware flow control is enabled, the CTS pin (pin 12) is de-asserted (high) to indicate that serial data should not be sent to the module.
- If the Associate pin (pin 15) is configured, it is driven low to avoid using power to light the LED.
- The Sleep_RQ pin (pin 9) is configured as a pulled-down input so that an external device can drive it high to wake the module (only applies to SM = 1 or SM = 5).
All other pins are left unmodified during sleep so they can operate as previously configured by the user.
When the XBee wakes from sleep:
- The On/Sleep pin is asserted (high) to indicate the module is awake.
- If CTS hardware flow control is enabled, the CTS pin is asserted (low) to indicate that serial data can be sent to the module.
- The Associate pin resumes its former configured operation
- All other pins are left unmodified so they can operate as previously configured by the user.
Pin sleep
Pin sleep allows an external microcontroller to determine when the XBee should sleep and when it should wake by controlling the Sleep_RQ pin (pin 9). When Sleep_RQ is asserted (high) by connecting it to 3.3 volts, the module will finish any operation and enter a low power state. The module will wake when the Sleep_RQ pin is de-asserted (low).
Pin sleep mode is enabled by setting the Sleep Mode (SM) parameter to Pin Hibernate [1].
Cyclic sleep
Cyclic sleep allows the module to sleep for a specified time and wake for a short time to poll its parent for any buffered data messages before returning to sleep again.
Cyclic sleep mode is enabled by setting the Sleep Mode (SM) parameter to 4 or 5. The cyclic sleep with pin wake up (SM = 5) is a slight variation of the cyclic sleep mode (SM = 4) that allows the module to be woken prematurely by de-asserting the Sleep_RQ pin.
The following parameters control cyclic sleep:
Parameter | Name | Description |
SP | Cyclic Sleep Period | Configures the sleep period of the module. |
SN | Number of Cyclic Sleep Periods | Configures the number of sleep periods multiplier. |
ST | Time before Sleep | Defines the period of inactivity of the module (during which no data is sent or received) before returning to cyclic sleep. If the XBee is transmitting or receiving a message, it will not go to sleep. |
SO | Sleep Options | Defines options for sleep mode behavior:
|
Example: Enable sleep mode
In this example, you will learn how to extend the battery life of an XBee ZigBee module. The example uses all three modules included in the kit to demonstrate how a ZigBee network handles messages when some modules are sleeping.
You will configure one of the modules as coordinator and the other two as end devices with different sleep modes. An end device will periodically send the value of an ADC to the other end device. Since the receiver will be asleep, the coordinator will store all of its messages and forward them to the destination module once it has woken up.
1. Requirements
Hardware
- Three XBee ZigBee modules
- ThreeXBee Grove Development Boards
- Threemicro USB cables
- One computer
Software
- XCTU
2. Connect the components
- Plug the XBee modules into theXBee Grove Development Boards and connect them to your computer using the micro USB cables provided.
For further information on how to connect your hardware, go to the Assemble the hardware section.
- After connecting the modules to your computer, open XCTU.
Make sure you are in Configuration working mode.
3. Configure the XBees
To transmit data wirelessly between your XBee’s, you must configure them to be in the same network. Remember that in the ZigBee protocol, one device must be the coordinator and the rest can be routers or end devices. In this case, you will have two end devices configured to sleep using different sleep modes: one with cyclic sleep (XBee B) and the other with pin hibernate sleep (XBee C).
The coordinator is in charge of storing the messages sent from XBee B to XBee C while XBee C is asleep. It forwards the messages once it wakes up.
- Restore the default settings of all XBee’s with the Load default firmware settings button at the top of the Radio Configuration section.
- Use XCTU to configure the following parameters:
Param | XBee A | XBee B | XBee C | Effect |
ID | 2015 | 2015 | 2015 | Defines the network for a radio to attach to. This must be the same for all radios on your network. |
JV | — | Enabled [1] | Enabled [1] | Verifies if a coordinator exists on the same channel to join the network or to leave if it cannot be found. |
CE | Enabled [1] | — | — | Sets the device as coordinator. |
DH | — | 0013A200 | — | Defines the destination address (high part) to transmit the data to. |
DL | — | SL of XBee C | — | Defines the destination address (low part) to transmit the data to. Use the address 0000000000000000 to address the coordinator. |
NI | CO-ORD | ED_CYCLIC | ED_PIN | Defines the node identifier, a human-friendly name for the module.
The default NI value is a blank space. Make sure to delete the space when you change the value. |
AP | API enabled [1] | API enabled [1] | API enabled [1] | Enables API operating mode. |
SP | 384 | 384 | — | Defines the duration of time spent sleeping. 384 (hexadecimal) = 900 (decimal) x 10 ms = 9 seconds. |
SM | — | Cyclic sleep [4] | Pin Hibernate [1] | Enables cyclic sleep mode on XBee B and pin hibernate sleep mode on XBee C (both end devices). |
ST | — | 7D0 | — | Defines the period of inactivity (no serial or RF data received) before going to sleep. 7D0 (hexadecimal) = 2000 (decimal) x 1 ms = 2 seconds. |
SO | — | 2 | — | Keeps the module awake during the entire period. |
D2/D3 | — | ADC [2] | — | Sets the DIO2/AD2 or DIO3/AD3 pin as ADC in XBee B, depending on if the XBee module is THT or SMT. This pin is connected to a potentiometer.
Configure the D2 parameter as ADC [2] only if XBee B is surface-mount (SMT). However, if XBee B is through-hole (THT), you have to configure the D3 parameter as ADC [2] instead of the D2. |
IR | — | 3E8 | — | Configures XBee B to send an IO sample every second (1000 ms = 3E8 in hexadecimal). |
- Write the settings of all XBees with the Write radio settings button at the top of the Radio Configuration section.
4. Sleep
With this configuration, ED_CYCLIC sends the value of the potentiometer to ED_PIN every time it wakes up. The coordinator stores all the D_CYCLIC samples sent to ED_PIN until it wakes up. To verify, perform the following steps in XCTU:
- Select ED_PIN module (receiver).
- Switch to Consoles working mode.
- Open the serial connection with the module.
- To request the module to sleep, click the DTR radio button from the top of the console to deactivate it (notice that the CTS indicator is also deactivated):
- The DTR pin is the same as the Sleep_RQ pin. When the DTR option is deactivated, the module goes to sleep; when DTR is activated, the module wakes up.
- After 20 seconds or so, activate theDTR button:
- Check that the module receives a series of IO Samples (IO Data Sample RX Indicator):
-
When the module wakes up, it immediately receives several IO samples instead of receiving one every second (IR parameter). This happens because the coordinator stores the samples that ED_PIN is not able to receive while it is asleep. Once ED_PIN wakes up, the coordinator sends all IO samples at once.
-
Select one frame and check its details in the right panel. You will see the value of the potentiometer (DIO3_AD3) and other details related to the frame.
- Repeat step 4 and rotate the potentiometer of the board where ED_CYCLIC is attached. Wait for another 20 seconds and check that the new packets that arrive contain a different value for the DIO3_AD3 pin.
- If you leave the receiver module (ED_PIN) awake, ED_PIN receives an IO sample every second while the ED_CYCLIC is awake (STvalue is two seconds). After that, ED_CYCLIC goes to sleep for nine seconds (SP parameter). Then the cycle starts over again.
- For more information please visit: tenettech.com
- For technical query please send an e-mail: info@tenettech.com