#include <Wire.h>
#include <RTClibExtended.h>
#include <LowPower.h>
#define wakePin 2 //use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW
#define ledPin 13 //use arduino on-board led for indicating sleep or wakeup status
RTC_DS3231 RTC; //we are using the DS3231 RTC
byte AlarmFlag = 0;
byte ledStatus = 1;
//-------------------------------------------------
void wakeUp() // here the interrupt is handled after wakeup
{
}
//------------------------------------------------------------
void setup() {
//Set pin D2 as INPUT for accepting the interrupt signal from DS3231
pinMode(wakePin, INPUT);
//switch-on the on-board led for 1 second for indicating that the sketch is ok and running
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(1000);
//Initialize communication with the clock
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__)); //set RTC date and time to COMPILE time
//clear any pending alarms
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
RTC.armAlarm(2, false);
RTC.clearAlarm(2);
RTC.alarmInterrupt(2, false);
//Set SQW pin to OFF (in my case it was set by default to 1Hz)
//The output of the DS3231 INT pin is connected to this pin
//It must be connected to arduino D2 pin for wake-up
RTC.writeSqwPinMode(DS3231_OFF);
//Set alarm1 every day at 18:33
RTC.setAlarm(ALM1_MATCH_HOURS,00, 33, 18, 0); //set your wake-up time here
RTC.alarmInterrupt(1, true);
}
//------------------------------------------------------------
void loop() {
//On first loop we enter the sleep mode
if (AlarmFlag == 0) {
attachInterrupt(0, wakeUp, LOW); //use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW
digitalWrite(ledPin, LOW); //switch-off the led for indicating that we enter the sleep mode
ledStatus = 0; //set the led status accordingly
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); //arduino enters sleep mode here
detachInterrupt(0); //execution resumes from here after wake-up
//When exiting the sleep mode we clear the alarm
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
AlarmFlag++;
}
//cycles the led to indicate that we are no more in sleep mode
if (ledStatus == 0) {
ledStatus = 1;
digitalWrite(ledPin, HIGH);
}
else {
ledStatus = 0;
digitalWrite(ledPin, LOW);
}
delay(500);
}
In file included from C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp:32:0:
C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp: In member function 'void LowPowerClass::powerExtStandby(period_t, adc_t, bod_t, timer2_t)':
C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp:980:18: error: 'SLEEP_MODE_EXT_STANDBY' was not declared in this scope
lowPowerBodOn(SLEEP_MODE_EXT_STANDBY);
^
C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp:980:4: note: in expansion of macro 'lowPowerBodOn'
lowPowerBodOn(SLEEP_MODE_EXT_STANDBY);
^
C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp:985:17: error: 'SLEEP_MODE_EXT_STANDBY' was not declared in this scope
lowPowerBodOn(SLEEP_MODE_EXT_STANDBY);
^
C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power\LowPower.cpp:985:3: note: in expansion of macro 'lowPowerBodOn'
lowPowerBodOn(SLEEP_MODE_EXT_STANDBY);
^
Bibliotheek Wire op versie 1.0 in map: C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Wire wordt gebruikt
Bibliotheek RTClibExtended op versie 1.0.0 in map: C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\RTClibExtended wordt gebruikt
Bibliotheek Low-Power op versie 1.6 in map: C:\Users\Mysafety\Google Drive\documents\Arduino\libraries\Low-Power wordt gebruikt
exit status 1
Fout bij het compileren van board Arduino Pro or Pro Mini
PaulS:
Did you see rocketscream's comment about NOT using the code on a device with an AtMega168 chip? And yet, here you are trying to...
No sorry, I had overlooked that. But then why did I get this solved by adding a few lines to LowPower.h and is this not implemented?
Because now I can get it compiled for 168P.
brice3010:
No sorry, I had overlooked that. But then why did I get this solved by adding a few lines to LowPower.h and is this not implemented?
Because now I can get it compiled for 168P.
You can get it compiled sure. But that's a hack, not a fix. So they're not going to put that in the official version. Now you've got a define constant that secretly doesn't do what it says it does. That's OK for you since you know you hacked it. But it's not OK to put that out for people to download and try to use without knowing that one define constant is wrong.
Worked-around, you mean. I don’t know, but I suspect that SLEEP_MODE_EXT_STANDBY and SLEEP_MODE_STANDBY are supposed to be two different modes. All that you are doing is making them the same mode.
Delta_G:
You can get it compiled sure. But that's a hack, not a fix. So they're not going to put that in the official version. Now you've got a define constant that secretly doesn't do what it says it does. That's OK for you since you know you hacked it. But it's not OK to put that out for people to download and try to use without knowing that one define constant is wrong.
What do you mean? It doesn't matter what chip. Nobody wants defines that are secretly redefined to some other define that isn't the same thing. That leads people to think that they can do things that won't work. Then developers have to deal with all the "Why doesn't SLEEP_MODE_EXT_STANDBY work on my 168. It acts the same as SLEEP_MODE_STANDBY" questions.
Delta_G:
What do you mean? It doesn't matter what chip. Nobody wants defines that are secretly redefined to some other define that isn't the same thing. That leads people to think that they can do things that won't work. Then developers have to deal with all the "Why doesn't SLEEP_MODE_EXT_STANDBY work on my 168. It acts the same as SLEEP_MODE_STANDBY" questions.
I try to understand you, but I think I am missing something.
Page 41 of the 660 page dataheet it says:
10.7 Standby Mode When the SM2...0 bits are 110 and an external crystal/resonator clock option is selected, the SLEEP instruction makes the MCU enter Standby mode. This mode is identical to Power-down with the exception that the Oscillator is kept running. From Standby mode, the device wakes up in six clock cycles. ATmega48A/PA/88A/PA/168A/PA/328/P [DATASHEET] 42 Atmel-8271J-AVR- ATmega-Datasheet_11/2015 10.8 Extended Standby Mode When the SM2...0 bits are 111 and an external crystal/resonator clock option is selected, the SLEEP instruction makes the MCU enter Extended Standby mode. This mode is identical to Power-save with the exception that the Oscillator is kept running. From Extended Standby mode, the device wakes up in six clock cycles.
PaulS:
Worked-around, you mean. I don't know, but I suspect that SLEEP_MODE_EXT_STANDBY and SLEEP_MODE_STANDBY are supposed to be two different modes. All that you are doing is making them the same mode.
No, not a "workaround". The 168P does support extended standby. If allowed to be properly compiled. Which prior to my fix was not the case.