It works as expected if I copy the exact code of his to wake up once per min. Now I want to change to wake up once per hour. So I did some changes on this line,
Clock.setA1Time(1, 1, 1, 0, 0b1110, false, false, false);
to this below,
Clock.setA1Time(1, 1, 1, 0, 0b1100, false, false, false);
Or Clock.setA1Time(1, 1, 0, 0, 0b1100, false, false, false);
But both don't work - the board doesn't sleep for one hour.
How do I set the RTC? I don't need the exact time. I just need the arduino to wake up every hour.
I've done all the looking I am going to for the library you are using. Your change looks plausible, at least the one with the same number of arguments.
This kind of thing is very painful if you sitting there watching it for an hour…
Looks like both alternate lines should work. What behavior do you actually get with them? Here's the beginning of the setA1Time function in the library:
Is the problem that the alarm doesn't start triggering an hour from NOW? It will trigger at minute 0, or minute 1, of each hour, but when that begins depends on the current time.
Agree @ShermanP, in fact I just wrote an alarm thing that "throws a stone" down the road of time by a specified number of minutes, which means
get the HH and MM from the RTC
do some calculations to add my delta minutes to the HH MM
plant them in the alarm time registers (and set the bits).
I wasn't using the library, just Wire i2c directly to the DS3231 as, like the OP, I am only trying to sleep for a period starting now, don't need all the library, besides preferring generally to be closer to the hardware at all times I can, where I have the most fun.
I found the problem. The code is alright. The problem is one of my electronic parts in the system has a capacitor built in it and the current backflows when the power is cut off which interrupted the sleep of the system and triggered the system to wake up. Thanks guys.
what library are you using for the DS3231? A link to where you found it or the exact name if you used the library manager. THX.
And I do not see where you account for the fact that you do not know what time is in the RTC, so setting the alarm to an absolute HH:MM value will be a totally random period until it matches the unknown time on the RTC.
Reread my #6.
The only way to get "an hour from now" is to see what time the RTC thinks now is, ass an hour (modulo 24) to it and place that hour value in the alarm register or use it in the setA1Time call.