Ds3231 rtc library - alarm usage

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
AdelaideHillsMaker
 
Posts: 4
Joined: Thu Sep 23, 2021 7:46 am

Ds3231 rtc library - alarm usage

Post by AdelaideHillsMaker »

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.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Ds3231 rtc library - alarm usage

Post by mikeysklar »

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

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
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.
A1F1EDCF-9510-42F9-8FE6-E390AB7BD853.jpeg
A1F1EDCF-9510-42F9-8FE6-E390AB7BD853.jpeg (510.66 KiB) Viewed 372 times
https://docs.python.org/3/library/time.html

General docs for DS3231 lib.

https://circuitpython.readthedocs.io/pr ... t/api.html

User avatar
AdelaideHillsMaker
 
Posts: 4
Joined: Thu Sep 23, 2021 7:46 am

Re: Ds3231 rtc library - alarm usage

Post by AdelaideHillsMaker »

Per text
Per text
IMG_0260v3.jpg (173.82 KiB) Viewed 356 times
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
Per text
IMG_0260v2 (1).jpg (159.12 KiB) Viewed 356 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Ds3231 rtc library - alarm usage

Post by mikeysklar »

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

User avatar
AdelaideHillsMaker
 
Posts: 4
Joined: Thu Sep 23, 2021 7:46 am

Re: Ds3231 rtc library - alarm usage

Post by AdelaideHillsMaker »

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.
Heres the code
Heres the code
ScreenShotCode.JPG (232.39 KiB) Viewed 327 times
Heres the output from that code
Heres the output from that code
Result.JPG (217.58 KiB) Viewed 327 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Ds3231 rtc library - alarm usage

Post by mikeysklar »

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

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: Ds3231 rtc library - alarm usage

Post by blakebr »

Interested in resolution.

User avatar
AdelaideHillsMaker
 
Posts: 4
Joined: Thu Sep 23, 2021 7:46 am

Re: Ds3231 rtc library - alarm usage

Post by AdelaideHillsMaker »

Heres some code, cut down to something minimal.
Heres some code, cut down to something minimal.
Code.jpg (153.93 KiB) Viewed 243 times
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.
...and here's what that code game me.
...and here's what that code game me.
OutPut.jpg (196.98 KiB) Viewed 243 times
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

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: Ds3231 rtc library - alarm usage

Post by blakebr »

Thank you for solving an issue I have had for a long time but didn't look into solving yet.

Bruce

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”