PCF8523 RTC Alarm not working

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
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

PCF8523 RTC Alarm not working

Post by maldemer »

Using the M0 Express and the Adalogger FeatherWing - RTC + SD Add-on. The RTC seems to maintain the time I set, but the alarm function does not seem to work. I used the code in https://github.com/adafruit/Adafruit_Ci ... on_PCF8523. I can print the changing time, but alarm_status never seems to become 'True'.

Here's the code:

Code: Select all

import time
import busio
from board import *
import sys
import adafruit_pcf8523

myI2C = busio.I2C(SCL, SDA)

rtc = adafruit_pcf8523.PCF8523(myI2C)

rtc.datetime = time.struct_time((2017,10,15,16,15,0,0,9,-1))
rtc.alarm = (time.struct_time((2017,10,15,16,16,0,0,9,-1)), "minutely")

t = rtc.datetime
a = rtc.alarm
print(t)
print(a)
print(t.tm_hour, t.tm_min)

while True:
	time.sleep(10)
	t = rtc.datetime
	print(t.tm_hour, t.tm_min)
	
	if rtc.alarm_status:
		print("wake up!")
		rtc.alarm_status = False
and here's some output:

Code: Select all

code.py output:
struct_time(tm_year=2017, tm_mon=10, tm_mday=15, tm_hour=16, tm_min=15, tm_sec=0, tm_wday=0, tm_yday=-1, tm_isdst=-1)
(struct_time(tm_year=2017, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=1, tm_isdst=-1), None)
16 15
16 15
16 15
16 15
16 15
16 15
16 16
16 16
16 16
16 16
16 16
16 16
16 17
16 17
16 17
When I print the alarm setting it seems like the function wasn't called successfully (struct_time is beginning of 2017 and the frequency is None), but I don't get any errors.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: PCF8523 RTC Alarm not working

Post by tannewt »

Does it work if you set alarm_interrupt to True as well? I might need to tweak the docs.

User avatar
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

Re: PCF8523 RTC Alarm not working

Post by maldemer »

Changed code to

Code: Select all

rtc.datetime = time.struct_time((2017,10,15,16,15,0,0,9,-1))
rtc.alarm_interrupt = True
rtc.alarm = (time.struct_time((2017,10,15,16,16,0,0,9,-1)), "minutely")
but result was the same.

User avatar
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

Re: PCF8523 RTC Alarm not working

Post by maldemer »

Hmm, seems it works when I specify 'hourly', but I think the chip supports minute alarm resolution as well.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: PCF8523 RTC Alarm not working

Post by tannewt »

Ok, a bug wouldn't surprise me. Please file an issue on the GitHub repo and assign it to me.

User avatar
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

Re: PCF8523 RTC Alarm not working

Post by maldemer »

Issue added.

When I mispelled 'minutely' I noticed an error that led me to adafruit_register/i2c_bcd_alarm.py; This has the following comment
:param bool has_seconds: True if the alarm can happen minutely.
but in adafruit_pcf8523.py I see this:
alarm = i2c_bcd_alarm.BCDAlarmTimeRegister(0x0a, has_seconds=False, weekday_shared=False, weekday_start=0)
Could this be causing a problem?

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: PCF8523 RTC Alarm not working

Post by tannewt »

I think its working as expected. "minutely" means it should alarm once a minute based on the seconds setting. "hourly" means it alarms once an hour based on minutes and seconds when available. "daily" is once a day based on hour and seconds.

I think "hourly" is what you are expecting.

User avatar
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

Re: PCF8523 RTC Alarm not working

Post by maldemer »

"minutely" is what I want as I want to trigger an action every 15 minutes. I guess I can work around this by using a timer.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: PCF8523 RTC Alarm not working

Post by tannewt »

Are you doing data logging or something? My goal in the future is to have `time.sleep` be smart and wind things down for long sleeps. So, I'd suggest jut using time.sleep to do it.

User avatar
maldemer
 
Posts: 23
Joined: Mon Aug 03, 2009 4:32 pm

Re: PCF8523 RTC Alarm not working

Post by maldemer »

No, I'm building a clock that will that will produce different sounds/lights based on time of day and particular calendar events (birthday, holiday, etc.) The minutely alarm was just there to use (or so I thought - I'll just use a timer to work around it.)

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: PCF8523 RTC Alarm not working

Post by tannewt »

Ok! Please post in-progress and finished pics! It sounds really cool.

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

Return to “Adafruit CircuitPython”