Arduino DS3231 RTC coding question

Hi there,

I am using the code example in this page, Arduino-Nano-33-IoT-Ultimate-Guide/SavePowerRTC.md at 45e601ad5b7f255e385400d87164c21a09e8f6b4 · ostaquet/Arduino-Nano-33-IoT-Ultimate-Guide · GitHub

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.

Thanks in advance.

Please post the code here

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

@cooplion, your topic has been moved to a more suitable location on the forum.

+1.

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… :wink:

a7

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:

void DS3231::setA1Time(byte A1Day, byte A1Hour, byte A1Minute, byte A1Second, byte AlarmBits, bool A1Dy, bool A1h12, bool A1PM) {

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 hope it is all still fun.

a7

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.

I still haven't found

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.

a7

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.