Hello all,
I recently started exploring the low power functionality of moteino, however, have been facing some issuse in making it work.
I tried the PIR motion sensor example mentioned here: https://codebender.cc/example/RFM69/MotionMote#MotionMote.ino and also I tried using the other libraries(narcoleptic and Sleep_n0m1).
I could make the LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) command to work. But when I try to run radio.sleep() the moteino never wakes up after executing this command.
I also tried a few simple sketches to verify the same. And every time I add the radio.sleep() function the device never wakes up.
Is there some thing I am doing wrong or missing out? Below is the latest code I have been trying to make work.
Waiting for guidance and thank you in advance.
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h> //get it here: https://github.com/lowpowerlab/spiflash
#include <LowPower.h> //get library from: https://github.com/LowPowerLab/LowPower
#define NODEID 18 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200
#define MOTIONPIN 1 //hardware interrupt 1 (D3)
RFM69 radio;
volatile boolean motionDetected=false;
void setup() {
Serial.begin(SERIAL_BAUD);
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
radio.encrypt(ENCRYPTKEY);
attachInterrupt(MOTIONPIN, motionIRQ, RISING);
char buff[50];
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);
}
void motionIRQ()
{
motionDetected=true;
}
void loop() {
if (motionDetected)
{
if (radio.sendWithRetry(GATEWAYID, "MOTION", 6))
{
Serial.println(" ok!");
Blink(LED,3);
}
else
{
Serial.println(" nothing...");
}
motionDetected=false;
}
else
{
Serial.println("waiting");
}
// radio.sleep();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
void Blink(byte PIN, int DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}
Are you saying that if you leave the line "radio.sleep();" commented out, you get continuous serial output of "waiting" and if you uncomment, you get nothing?
If so, may I suggest that you add a line before uncommented radio.sleep() that has:
Blink(100);
radio.sleep();
And see if the LED blinks every 8 seconds?
Tom
Hint: It is highly recommended that you perform Serial.flush(); before and after sleeping...
Hi Tom,
Thanks for a quick reply. Regarding the led blink, I tried as you mentioned and it is blinking.
However, I also tried the flush command and it seems to work now. Although I had the flush command before the low power commands. But as you suggested, I will add it after the low power commands as well and do a thorough testing and update you the same.
Thanks for the help. Get back to you soon.