I had created a daily alarm example before my DS1307 RTC module arrived that operated perfectly. Then tested my RTC alone with success.
Now I'm trying to add the RTC to my working daily alarm sketch. My problem is, the daily alarm event does not fire (with RTC time). After searching for examples, and reading other users RTC questions, I think my Arduino clock is not synchronized with my RTC, and my code is alarming reference the Auduino time.
So, the most accurate time keeping (alarm) method isn't an initial sync with the Arduino, it would be the alarm time being checked against the RTC time. What would be the lowest-overhead way of checking RTC time for the alarm? Nothing I have tried works. Latest code below.
// Daily alarm test using a DS1307 RTC
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#include <Time.h>
#include <TimeAlarms.h>
LiquidCrystal_I2C lcd(0x27,20,4);
RTC_DS1307 RTC;
void setup () {
//setTime(12,19,0,06,04,13); // Old set time, pre RTC
RTC.begin();
Alarm.alarmRepeat(11,50,0, Alarm1); // every day 11:50 Hours
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
pinMode(13, OUTPUT);
//if (! RTC.isrunning()) {
// Serial.println("RTC is NOT running!");
// // following line sets the RTC to the date & time this sketch was compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop () {
digitalClockDisplay();
Alarm.delay(1000);
}
void digitalClockDisplay()
{
DateTime now = RTC.now();
char buf[20];
//sprintf(buf, "%02d:%02d:%02d %02d/%02d/%4d", now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year());
sprintf(buf, "%02d:%02d %02d/%02d/%4d", now.hour(), now.minute(), now.month(), now.day(), now.year());
lcd.print(buf);
lcd.setCursor(0,0);
}
void Alarm1(){
digitalWrite(13, HIGH); //alarm test output
delay(5000);
digitalWrite(13, LOW); }