Arduino time alarm without an external interrupt alarm pin on the RTC?
February 12, 2013 1:47 PM Subscribe
I want to program my Arduino to go to sleep at 6 pm and wake back up at 5 am, and then execute a few simple functions once every hour while it's awake. I have a DS1307 real-time clock, but it doesn't have an alarm interrupt pin, so I can't just set up an external interrupt to tell the Arduino to wake when the alarm pin is set to high. What's the best way to do this without an alarm pin?
I'm a bit of a programming newbie, but I have written a program to which I need to add this functionality. I've played with a few of the libraries out there, but most of the best/most efficient methods require the alarm interrupt pin on the RTC, and I am having trouble figuring out how to accomplish this without it. Unfortunately, I am irrevocably stuck with the DS1307 and buying another RTC module that has an alarm pin is simply not an option. I would also like to use the narcoleptic library for the sleep function to extend my battery life.
Can somebody walk me through how to get my Arduino + DS1307 to sleep from 5am to 6pm and only trigger my function once every hour, while using the narcoleptic delay function somehow? I am willing to give up on the narcoleptic part if I need to, but using narcoleptic will give me a much longer run time, which is really important to the project as well (this is for a multiple-week data-logging application). Cheers and thanks for any advice you might have!
posted by dialetheia to technology (5 answers total)
Anyway, basically what you're going to do is use narcoleptic to sleep for some period of time, as determined by how inaccurate you're willing to be. Without an alarm, you'll be relying on the 128kHz oscillator, which is super-inaccurate. Like, ±3 minutes in an hour. Each time the Arduino wakes up, it will query the RTC, execute its function if the time is "close enough" to the right time, then go back to sleep.
During the inactive part of the day you could probably get away with longer periods of sleep between clock checks.
posted by jedicus at 2:01 PM on February 12