Ds3231 rtc library - alarm usage
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- AdelaideHillsMaker
- Posts: 4
- Joined: Thu Sep 23, 2021 7:46 am
Ds3231 rtc library - alarm usage
Hello. I’m having trouble getting the syntax right in setting an alarm and checking it’s status later to see whether its triggered. I also dont get what a “valid” duration setting is. Thank you in advance. Oh, I’m using a raspberry Pi zero/ python.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Ds3231 rtc library - alarm usage
Looking at our github repo for the CircuitPython DS3231 library there is a short example of the time structure for setting an alarm.
https://github.com/adafruit/Adafruit_Ci ... 3231#alarm
If it is time.struct_time that is intimidating you this is the breakdown from year to second starting with 1's not 0's.
https://docs.python.org/3/library/time.html
General docs for DS3231 lib.
https://circuitpython.readthedocs.io/pr ... t/api.html
https://github.com/adafruit/Adafruit_Ci ... 3231#alarm
Code: Select all
rtc.alarm1 = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")
if rtc.alarm1_status:
print("wake up!")
rtc.alarm1_status = False
https://docs.python.org/3/library/time.html
General docs for DS3231 lib.
https://circuitpython.readthedocs.io/pr ... t/api.html
- AdelaideHillsMaker
- Posts: 4
- Joined: Thu Sep 23, 2021 7:46 am
Re: Ds3231 rtc library - alarm usage
Thank you. Ive attached a few screen shots - one with a piece of simple test code and the other with an error Im getting. The line is OK with "daily" as in your example but almost nothing else, so I don't understand what the options are. So as I see it Ive set the alarm for one minute hence, and the loop carries on for 100 seconds showing the alarm status. It doesn't change, even if I reset it first. Can anyone see what Im missing? Something simple and obvious I trust.
- Attachments
-
- Per text
- IMG_0260v2 (1).jpg (159.12 KiB) Viewed 356 times
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Ds3231 rtc library - alarm usage
You are getting close. I don't have an exact alarm example to point you at for minute or hourly.
Make sure you are checking the value of alarm_status.
https://circuitpython.readthedocs.io/pr ... rm1_status
Also reviewing this code will give you an idea of what is going on under the hood.
https://circuitpython.readthedocs.io/pr ... alarm.html
Make sure you are checking the value of alarm_status.
https://circuitpython.readthedocs.io/pr ... rm1_status
Also reviewing this code will give you an idea of what is going on under the hood.
https://circuitpython.readthedocs.io/pr ... alarm.html
- AdelaideHillsMaker
- Posts: 4
- Joined: Thu Sep 23, 2021 7:46 am
Re: Ds3231 rtc library - alarm usage
Thanks everybody. OK Ive simplified the code and set up a little test.
So I'm hoping you could glance at it and tell me where I'm going wrong, or what I've missed.
The idea is that I set the alarm (in this test code) to 1 minute in the future and then monitor the alarm status.
It doesn't seem to change after 1 minute.
So I'm hoping you could glance at it and tell me where I'm going wrong, or what I've missed.
The idea is that I set the alarm (in this test code) to 1 minute in the future and then monitor the alarm status.
It doesn't seem to change after 1 minute.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Ds3231 rtc library - alarm usage
I think your code looks good and you are doing things right. The only thing that stands out is that you are not setting alarm1_status to false initially and that you will want to set it to false after acknowledging it.
https://circuitpython.readthedocs.io/pr ... rm1_status
https://circuitpython.readthedocs.io/pr ... rm1_status
- blakebr
- Posts: 956
- Joined: Tue Apr 17, 2012 6:23 pm
Re: Ds3231 rtc library - alarm usage
Interested in resolution.
- AdelaideHillsMaker
- Posts: 4
- Joined: Thu Sep 23, 2021 7:46 am
Re: Ds3231 rtc library - alarm usage
OK Ive been fiddling around with the code. Using "secondly" it was trying to trigger "True" at the beginning of every second .... anyway to cut a long story short here's some code which is looking better. Next I'll be building hardware and software around it to take a picture and shut down the power, aka a long term time lapse device
- blakebr
- Posts: 956
- Joined: Tue Apr 17, 2012 6:23 pm
Re: Ds3231 rtc library - alarm usage
Thank you for solving an issue I have had for a long time but didn't look into solving yet.
Bruce
Bruce
Please be positive and constructive with your questions and comments.