Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6829
    dolan
    Participant

    I am using the TimeAlarms and Time library

    https://playground.arduino.cc/Code/Time
    https://www.pjrc.com/teensy/td_libs_TimeAlarms.html

    This 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)?

    #6833
    LIM PHANG MOH
    Keymaster

    The 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.
    #6839
    dolan
    Participant

    I 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?

    #6841
    LIM PHANG MOH
    Keymaster

    You 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().

    #6845
    dolan
    Participant

    Yeah 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:

    https://github.com/dolanmiu/Automated-Chicken-Coop/blob/de49ed56db9d25fe82ffe62368b8b860af8c1422/main/main/main.ino#L36

    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.
    #6850
    LIM PHANG MOH
    Keymaster

    No 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.