Hardware Reference
In-Depth Information
The next example (see Listing 5-2) Arduino sketch uses sleep mode 5, demonstrating a method of allowing other
modules in the network to wake and send data to the end device, while allowing the code to wake up the module
to send data. The code examples use the setup in Figure 5-4 ; the only change to the Arduino connections is that
an extra connection is added between the serial adapter and the Arduino, connecting XBee pin 9 to Arduino pin 9.
Both modules need to be set with AT command mode firmware—ZIGBEE COODINATOR AT for one and ZIGBEE
END DEVICE AT for the other. The modules need the destination addressed set to be able to communicate. When
configuring the end device, set the SM register to 5, allowing the code and other external events wake up the module.
Listing 5-2. Arduino Dual-Direction Communication with Sleep Mode Communications
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //rx,tx
void setup() {
pinMode (9 , OUTPUT);
Serial.begin(9600);
Serial.println("Ready");
mySerial.begin(9600);
} // end setup
void loop() {
digitalWrite (9 , LOW);
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available()){
digitalWrite (9 , HIGH); // transition from LOW to HIGH to wake up module
delay (2);
digitalWrite (9 , LOW);
delay (2); // delay to give the chip time to recognize the transition
mySerial.write(Serial.read());
} // end if (Serial.available())
} // end loop
 
Search WWH ::




Custom Search