DS1307 RTC and TimeAlarms: hourly alarm, like 0000 through 2300

seattlebiker

New member
Greetings,

I have a question about the clever TimeAlarms library for the DS1307/DS3231 RTC's that is maintained by Paul Stoffregen. I am looking at the readme.txt file on GitHub, and it apparently can alarm given all kinds of different situations. Except one, it seems. I need to alarm on the hour, daily, i.e., at midnight, 1AM, 2AM, 3AM, etc. I haven't tried it, but I need something like this: Alarm.alarmRepeat(0-23, 0, 0, getBucketTips), so I can get the rainfall count and zero out count for the next hourly report. It would be great if the TimeAlarms library can do this but maybe I'm stuck with just creating a function using the Time library. Also wondering if I should use a DS3231 instead of the DS1307. Ideas? Thanks for any assistance.
 
It might be worth considering the RTC RV-3028-C7, the library that I am using can be set up to have an alarm when "Minutes minutes match (once per hour)".
The Library by Constantin Koch can be found here.
Just remember to include the below in your code and it will work just fine.
Code:
static time_t getUnixTime() { return rtc.getUNIX(); }
 
Regarding your second question, the DS3231 has an integrated oscillator which makes it better than the DS1307. The DS1307 is available in DIP8 package so it is a good option if you want to avoid SMD package. If you choose the DS1307, use a good 32KHz quartz such as the Citizen CFS-20632768HZFB
 
Last edited:
Greetings,

I have a question about the clever TimeAlarms library for the DS1307/DS3231 RTC's that is maintained by Paul Stoffregen. I am looking at the readme.txt file on GitHub, and it apparently can alarm given all kinds of different situations. Except one, it seems. I need to alarm on the hour, daily, i.e., at midnight, 1AM, 2AM, 3AM, etc. I haven't tried it, but I need something like this: Alarm.alarmRepeat(0-23, 0, 0, getBucketTips), so I can get the rainfall count and zero out count for the next hourly report. It would be great if the TimeAlarms library can do this but maybe I'm stuck with just creating a function using the Time library. Also wondering if I should use a DS3231 instead of the DS1307. Ideas? Thanks for any assistance.

Seattlebiker:
I much prefer the DS3231 or the DS3232 over the DS1307, as the newer ones (3231 and 3232) both have builtin TCXO's (Temperature Compensated Crystal Oscillators), which makes them incredibly accurate over the long term. I have gotten time stability of better than 10 seconds over a period of 1 month. The DS3232 also has some built-in memory that is battery backed-up which is nice for long term constants.

I use code in my one second loop to check for those special times, as it requires only a few lines of code. It looks something like this:

Code:
if (currentTime[2] == 0)  // Seconds = zero.
                        {  // one minute has passed.
                            if (currentTime[1] == 0)  // Minutes = zero.
                                {  // One hour has passed
                                    if (currentTime[0] == 0)  // Hours = zero, It is Midnight 00:00:00.
                                        {
                                            insideDailyHighTemp = sensorState.Temperature;  // Set inside Daily High Temp to ambient at midnight.
                                            insideDailyLowTemp = sensorState.Temperature;  // Set inside Daily Low Temp to ambient at midnight.
                        
                                            outsideDailyHighTemp = WeatherDataStruct.Temperature;  // Set outside Daily High Temp to ambient at midnight.
                                            outsideDailyLowTemp = WeatherDataStruct.Temperature;  // Set outside Daily Low Temp to ambient at midnight.
                        
                                            if (currentDate[0] == 1)  // This is the day.
                                                {
                                                    if (currentDate[1] == 10)  // This is the month of October.
                                                        {

                                                        }
                                                }
                                        }
                                    #if defined(USINGGPS)
                                        if (currentTime[0] == 2)  // Hours = two, It is 2AM 02:00:00.
                                            {
                                                updateGPSFlag = true;  // Setting this flag means that the next 2 second interrupt comes around, it will update the RTC from the GPS.
                                            }
                                    #endif
                                }
                        }

Regards,
Ed
 
The RTC RV-3028-C7 is much mire accurate than the DS3231 or the DS3232 and it can last for many years (circa 6+) from one RTC back up battery and has the needed hourly alarm.
 
The DS3231 has two programmable alarms which would make it easy for you to set an alarm that occurs every hour on a specific minute of the hour.

Pete
 
Hey Ed, thanks! Here I was thinking I'd have to try adding a feature to the TimeAlarms library to do that. Reminds me of the old saying, "All I wanted to do was drain the swamp, and now I'm up my a-- in alligators!" :) I'll use your idea. I might also follow the guidance of using a DS3231 - I have a couple of those modules. I'm using the DS1307 since I had one of those and a 32KHz crystal on hand. For grins I might just see how bad the DS1307's drift is. Thanks for the snippet of code! - Bruce
 
Hi again sbfreddie. So, I'm a bit confused by the how you arrive at the construct "currentTime[]" array. Can you please give me an example? Thanks!
 
Hi again sbfreddie. So, I'm a bit confused by the how you arrive at the construct "currentTime[]" array. Can you please give me an example? Thanks!

Seattlebiker:
I wrote this code about 10 years ago for my Weather-Station/Clock project. This code has been running continuously for a very long time and only stops when the power goes out, but since the DS3231 is battery backed it never forgets the time and date.

This code is a part of the main Loop:

Code:
/*******************************************************************************************************************
     *                           This section runs every second, driven by interrupt.
     *******************************************************************************************************************/
    if (oneSecondFlag == true)  // This runs every second
        {
            if (preferencesInProgressFlag == false)
                {
                    /*******************************************************************************************************************
                    * Get current time from DS3231 and put into variables curentTime[0] (hh), [1] (mm), & [2] (ss).
                    *******************************************************************************************************************/
                    if (RTC.read(tm))
                        {
                            lastTimeSetByClock = makeTime(tm);  // Converts tmElements array into a Time_T (UNIX Time), LastTimeSetByClock is a Time_T (UNIX Time) variable.
                
                            currentTime[0]      = (tm.Hour);
                            currentTime[1]      = (tm.Minute);
                            currentTime[2]      = (tm.Second);
                            currentDate[0]      = (tm.Day);
                            currentDate[1]      = (tm.Month);
                            currentDate[2]      = (tmYearToCalendar(tm.Year));
                            currentDayOfWeek    = (tm.Wday);  // Put the Day of the Week into the currentDayOfWeek Variable.
                        }
                    else
                        {
                            if (RTC.chipPresent())
                                {
                                    Serial.println(F("The DS3231 is stopped.  Please run the SetTime"));
                                    Serial.println(F("example to initialize the time and begin running."));
                                    Serial.println();
                                }
                            else
                                {
                                    Serial.println(F("DS3231 read error!  Please check the circuitry."));
                                    Serial.println();
                                }
                        }
Regards,
Ed
 
Back
Top