JChristensen / DS3232RTC

Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks
GNU General Public License v3.0
392 stars 135 forks source link

Set Alarm for every 20 minutes #94

Closed hoseinaghajari closed 2 years ago

hoseinaghajari commented 2 years ago

HI DEAR @JChristensen .

You closed my previous issue so my question is can we Set Alarm for every 20 minutes? How?

JChristensen commented 2 years ago

As I said, my policy is to only entertain issues here on GitHub that are actual problems with the library.

But I also said that I had written an example sketch that illustrates the technique.

I hope you find it instructive. Please check it out.

Best regards.

JChristensen commented 2 years ago

By the way, I had another look at your sketch and I think I see an issue. Would you like a hint or would you prefer to have a go at it yourself?

hoseinaghajari commented 2 years ago

By the way, I had another look at your sketch and I think I see an issue. Would you like a hint or would you prefer to have a go at it yourself?

I would like to wake my Arduino whenever I want. for instance; in one project every 20 min or in another project every one hour. I want to have flexibility for time intervals.

by the way: I tested that example but If I change the wakeInterval {5}; to wakeInterval {10}; it will trig but won't go in sleep after that. here is my output: ddddddd

JChristensen commented 2 years ago

I've updated the example; give it another try please. A small delay is needed after waking up to allow communication to the RTC.

hoseinaghajari commented 2 years ago

I've updated the example; give it another try please. A small delay is needed after waking up to allow communication to the RTC.

Thank you. I solved That. just by resetting The RTC time before setting new alarm. But I have another question. Due to I need D2(INT0) on Arduino UNO for another purpose, Can we define Wakeup pin into other pins? such as 3. I've actually changed the const int wakeUpPin = 2; to const int wakeUpPin = 3; but it didn't trig the pin.

JChristensen commented 2 years ago

Pin 3 (INT1) should work the same, but note that the example sketch uses pin 3 to power the RTC. So that would need to be changed too.

JChristensen commented 2 years ago

Opps, my bad. The goToSleep() function was always setting INT0. One more change to the example sketch. It should now work for either INT0/Pin2 or INT1/Pin3. Give it a try please. Thanks for finding that.

hoseinaghajari commented 2 years ago

Opps, my bad. The goToSleep() function was always setting INT0. One more change to the example sketch. It should now work for either INT0/Pin2 or INT1/Pin3. Give it a try please. Thanks for finding that.

You Solved it so thank you BUT I come to think it has new problem with waking up. please tell me how did you solve goToSleep() function.

hoseinaghajari commented 2 years ago

Opps, my bad. The goToSleep() function was always setting INT0. One more change to the example sketch. It should now work for either INT0/Pin2 or INT1/Pin3. Give it a try please. Thanks for finding that.

You changed STH in Code or in library files?

JChristensen commented 2 years ago

You Solved it so thank you BUT I come to think it has new problem with waking up. please tell me how did you solve goToSleep() function.

It seems to be working OK here. What new problem do you think it has? I can't help unless you describe it.

It was a change to the example sketch. See here.

hoseinaghajari commented 2 years ago

You Solved it so thank you BUT I come to think it has new problem with waking up. please tell me how did you solve goToSleep() function.

It seems to be working OK here. What new problem do you think it has? I can't help unless you describe it.

It was a change to the example sketch. See here.

my connection is correct and here is my output: I reset it 3 times but here it is:

ffffffff

hoseinaghajari commented 2 years ago

Opps, my bad. The goToSleep() function was always setting INT0. One more change to the example sketch. It should now work for either INT0/Pin2 or INT1/Pin3. Give it a try please. Thanks for finding that.

In previous sketch you used LowPower.hLibrary but now you use avrLibrary. working with LowPower.h is easy but it just available on INT0.

JChristensen commented 2 years ago

my connection is correct and here is my output: I reset it 3 times but here it is:

That looks like an I2C communication failure. Try increasing the delay(20); on line 89 to delay(100);

JChristensen commented 2 years ago

In previous sketch you used LowPower.hLibrary but now you use avrLibrary. working with LowPower.h is easy but it just available on INT0.

<avr/sleep.h> is just for sleep functions, it doesn't really have anything to do with what interrupt is used to wake the MCU.

JChristensen commented 2 years ago

OK, I've made one last revision to the example sketch, just to add some informational print statements.

All seems to be working so I think the example sketch is complete.

/home/jack/Dropbox/sketchbook/temp/alarm_ex10/alarm_ex10.ino Jan 19 2022 12:55:22
Sketch start 17:57:28 Wed 19 Jan 2022
Wake interval: 5 minutes.
Using interrupt INT0
RTC interrupt pin: 2
RTC power pin: 5
Setting alarm for 18:00:00 Wed 19 Jan 2022
Going to sleep at 17:57:28 Wed 19 Jan 2022
Alarm at 18:00:00 Wed 19 Jan 2022
Setting alarm for 18:05:00 Wed 19 Jan 2022
Going to sleep at 18:00:10 Wed 19 Jan 2022
Alarm at 18:05:00 Wed 19 Jan 2022
Setting alarm for 18:10:00 Wed 19 Jan 2022
Going to sleep at 18:05:10 Wed 19 Jan 2022
Alarm at 18:10:00 Wed 19 Jan 2022
Setting alarm for 18:15:00 Wed 19 Jan 2022
Going to sleep at 18:10:10 Wed 19 Jan 2022
/home/jack/Dropbox/sketchbook/temp/alarm_ex10/alarm_ex10.ino Jan 19 2022 12:42:30
Sketch start 17:42:40 Wed 19 Jan 2022
Wake interval: 5 minutes.
Using interrupt INT1
RTC interrupt pin: 3
RTC power pin: 5
Setting alarm for 17:45:00 Wed 19 Jan 2022
Going to sleep at 17:42:40 Wed 19 Jan 2022
Alarm at 17:45:00 Wed 19 Jan 2022
Setting alarm for 17:50:00 Wed 19 Jan 2022
Going to sleep at 17:45:10 Wed 19 Jan 2022
Alarm at 17:50:00 Wed 19 Jan 2022
Setting alarm for 17:55:00 Wed 19 Jan 2022
Going to sleep at 17:50:10 Wed 19 Jan 2022
Alarm at 17:55:00 Wed 19 Jan 2022
Setting alarm for 18:00:00 Wed 19 Jan 2022
Going to sleep at 17:55:10 Wed 19 Jan 2022
hoseinaghajari commented 2 years ago

Unfortunately it still doesn't work for me. I will try to solve it. why you use PIN5 for vcc?

JChristensen commented 2 years ago

To minimize power consumption. Before the MCU sleeps, it first powers off the RTC. Else the RTC will continue to draw 100 μA or so.

On Jan 19, 2022 13:53, Hossein Aghajari wrote: Unfortunately it still doesn't work for me. I will try to solve it. why you use PIN5 for vcc?

hoseinaghajari commented 2 years ago

Good Idea