Reputation: 13
What I want: To connect a stand alone end device XBee in sleep mode to a XBee coordinator attached to a sparkfun redboard (Arduino Uno). For this example, I am using Faludis wireless sensor networks example on romantic lighting, but with the router/end device in sleep mode
When not in sleep mode, I have a light sensor hooked up to my end device, and sending via pin 20 to the coordinator radio. I have the coordinator pins 2 and 3 hooked up to the arduino board pin 0 and 1 respectively. My code for the coordinator arduino is from the book,
/*
* ROMANTIC LIGHTING SENSOR
*
* It detects whether your lighting is
* setting the right mood.
*
* USES PREVIOUSLY PAIRED XBEE ZB RADIOS
* by Rob Faludi http://faludi.com
*/
/*
CONFIGURATION
SENDER: (REMOTE SENSOR RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio
ATJV1 -> rejoin with coordinator on startup
ATD02 pin 0 in analog in mode
ATIR64 sample rate 100 millisecs (hex 64)
* THE LOCAL RADIO _MUST_ BE IN API MODE *
RECEIVER: (LOCAL RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio
*/
#define VERSION "1.02"
int LED = 11;
int debugLED = 13;
int analogValue = 0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(debugLED, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Make sure everything we need is in the buffer
if (Serial.available() >= 21) {
// Look for the start byte
if (Serial.read() == 0x7E) {
//Blink debug LED to indicate when data is received
digitalWrite(debugLED, HIGH);
delay(10);
digitalWrite(debugLED, LOW);
// Read the variables that we're not using out of the buffer
for (int i = 0; i<18; i++) {
byte discard = Serial.read();
}
int analogHigh = Serial.read();
int analogLow = Serial.read();
analogValue = analogLow + (analogHigh * 256);
}
}
/*
* The values in this section will probably
* need to be adjusted according to your
* photoresistor, ambient lighting, and tastes.
* For example, if you find that the darkness
* threshold is too dim, change the 350 value
* to a larger number.
*/
// Darkness is too creepy for romance
if (analogValue > 0 && analogValue <= 350) {
digitalWrite(LED, LOW);
}
// Medium light is the perfect mood for romance
if (analogValue > 350 && analogValue <= 750) {
digitalWrite(LED, HIGH);
}
// Bright light kills the romantic mood
if (analogValue > 750 && analogValue <= 1023) {
digitalWrite(LED, LOW);
}
//Serial.println(analogLow);
//Serial.println(analogHigh);
Serial.println(analogValue);
//delay(100);
}
Now when I change the settings on the router to end device, and
ATIR 3E8
ATSM 4
ATSP 64
ATST 14
I see the end device powering on every second (from LED's I have hooked to pins 13 15 and 6), but nothing on the coordinator end. Is there something I am doing wrong with the coordinator, or does the serial read on the Arduino just not like cyclic sleep mode?
Upvotes: 0
Views: 1267
Reputation: 11694
I believe you need to tune your IR
and SP
settings. This Knowledge Base Article on Digi's site has a good explanation:
Example:Sample Rates work very well with cyclic sleep modes, since the radio will sample once per wake period and immediately go back to sleep. If more than one sample per wake period is required, then modifications to the SO (Sleep Options) and ST (Time before Sleep) parameter are needed.
I want to sample ADC1, DIO2, and DIO3 once every minute and send the sample to a specific radio. To conserve battery life, the radio should only sample once per wake period.
Configuration:
- DH=0x0013A200
- DL=0x12345678 (address of the collector node)
- D1=0x02 (ADC)
- D2=0x03 (Digital Input)
- D3=0x03 (Digital Input)
- IR=0x200 (512ms)
- SM=0x04 (cyclic sleep)
- SP=0x1770 (60 seconds)
With this configuration, the radio will wake once every minute, sample D1 as an ADC, D2 and D3 as Digital Inputs, and send the single sample to the radio with the address 0013A200 12345678 before going back to sleep. The IR parameter does not exceed the radio’s wake period (this varies depending on the radio, but with the default settings it will only be a few milliseconds) so only one sample will be taken and sent over-the-air once per minute as defined by the sleep period instead of the sample rate interval.
Upvotes: 0