-
AuthorPosts
-
October 3, 2017 at 9:50 AM #6829dolanParticipant
I am using the TimeAlarms and Time library
https://playground.arduino.cc/Code/Time
https://www.pjrc.com/teensy/td_libs_TimeAlarms.htmlThis guy on GitHub, made a solution to tackle this problem, but it is not optimal as time drifts…
https://github.com/rocketscream/Low-Power/issues/19
Is there a way to save on power and at the same time keep time (and alarms)?
October 3, 2017 at 12:53 PM #6833LIM PHANG MOHKeymasterThe time library depends on either the millis() OR an external hardware RTC. In power down sleep mode, the Timer 0 that millis() uses is stopped. Best way is to use an external hardware RTC and tie an external interrupt capable pin such as pin D2 or D3 to wake the processor up from power down sleep.
- This reply was modified 6 years, 6 months ago by LIM PHANG MOH.
October 3, 2017 at 10:19 PM #6839dolanParticipantI am using a DC1307, which to my knowledge doesn’t have interrupts:
https://forum.arduino.cc/index.php?topic=349785.0
I have thought of a way:
sync the time library to RTC as you advised
Then use LowPower’s powerdown function every 8 seconds
Then pray that the TimerAlarm function executes.Would powerdown interfere with TimeAlarms if its synced to RTC?
October 3, 2017 at 11:31 PM #6841LIM PHANG MOHKeymasterYou would need to call the sync function again once awake from the 8 s power down period. Best method is using an external RTC with interrupt like DS3231. That way you can put the MCU to sleep forever and once the alarm fires, the interrupt pin will wake the MCU. But, again the millis() is stop during these sleep period. I don’t quite get why you need to maintain the millis().
October 4, 2017 at 1:39 AM #6845dolanParticipantYeah I agree, using a DS3231 sounds the most elegant and best, but however I already invested in a DS1307, so I dont wan’t to waste it lol
Maybe showing my code will give more context. Here is the code, pay attention to the highlighted line:
It uses TimeAlarms to run a task everyday. To close my Chicken Coop, otherwise the fox will eat them.
TimeAlarms is powered by Time I believe, so I need to maintain the millis() by using RTC sync, or adjustTime()- This reply was modified 6 years, 6 months ago by dolan.
October 4, 2017 at 9:18 AM #6850LIM PHANG MOHKeymasterNo it would not work if put to sleep. That’s how the Time library work without a physical alarm as it depends on the millis() to count time. The synchronization only happens in setup() to let the Time library knows the real calendar time. From there on wards, it depends on millis() to compute the alarm time in the future. millis() doesn’t run in sleep as it depends on timer 0.
-
AuthorPosts
- You must be logged in to reply to this topic.