Reputation: 23
I am trying to read the alarm that is set in my Arduino real time clock (RTC), but for some reason rtc.getAlarmHour() and rtc.getAlarmMinute() don't seem to work. I had them working before, but I'm not sure what changed. I am using Arduino Uno. The following code just returns "Next Alarm: 0:0".
#include <Rtc_Pcf8563.h>
Rtc_Pcf8563 rtc;
void setup(){
rtc.clearStatus();
rtc.setAlarm(byte(rtc.getMinute())+2,byte(rtc.getHour()),99,99);
Serial.begin(9600);
printAlarm();
}
void loop(){
}
void printAlarm(){
Serial.print("Next Alarm ");
Serial.print(rtc.getAlarmHour());
Serial.print(":");
Serial.print(rtc.getAlarmMinute());
}
Upvotes: 0
Views: 893
Reputation: 23
I think I found the issue. I noticed that the issue was not occurring on my 2nd computer, and after much comparison between computers, I loaded a different version of the RTC_Pcf8563 library (which I had on the 2nd computer), and the problem is fixed. The problem was definitely fixed by making only the one change of replacing the library with the older library. In the troubleshooting process I also reloaded the newer library , and it didn't help, so it seems that this is an issue with RTC_Pcf8563 version 1.0.1.
Then after some more sleuthing, I found out that the version of RTC_Pcf8563 that I had on my 2nd computer was a corrected copy of version 1.0.1. It seems that in version 1.0.1 the getAlarmHour() and getAlarmMinute() functions are missing a call to the getAlarm() function. If this call is added, then everything works fine.
Original function in version 1.0.1
byte Rtc_Pcf8563::getAlarmMinute() {
return alarm_minute;
}
Corrected function
byte Rtc_Pcf8563::getAlarmMinute() {
getAlarm();
return alarm_minute;
}
Upvotes: 1
Reputation: 429
Suggestion:
1) Check I2C address of your clock chip
2) try the exemple from Arduino library documentation:
#include <Wire.h>
#include <Rtc_Pcf8563.h>
//init the real time clock
Rtc_Pcf8563 rtc;
void setup()
{
//clear out the registers
rtc.initClock();
//set a time to start with.
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc.setDate(14, 6, 3, 1, 10);
//hr, min, sec
rtc.setTime(1, 15, 0);
}
void loop()
{
//both format functions call the internal getTime() so that the
//formatted strings are at the current time/date.
Serial.print(rtc.formatTime());
Serial.print("\r\n");
Serial.print(rtc.formatDate());
Serial.print("\r\n");
delay(1000);
}
Good luck !
Upvotes: 0