I have successfully developed a weather station using the Adafruit datalogger shield with various sensors that logs the data to the shield's SD card. My intention is to use its RTC to trigger a record every hour, on the hour. I therefore need a RTC timer loop within the Arduino void(loop) to allow it to run once at each hour, but have been unsuccessful after many attempts. A cut-down version of my latest code is below, intended simply to serial.print only the date and time at each hour. It prints the data and time in void(setup), but never triggers the hourly records.
I am new to Arduino coding and any help would be greatly appreciated.
int prevHour;
// Inside your loop:
if(now.hour() != prevHour)
{
// Do your SD stuff here!
prevHour = now.hour();
}
It'll look if there is an difference between the old and new time (So the next hour, or from 23:00 to 0:00) in the hours, does your SD stuff and saves the current hours.
I'm not sure if the now.hour returns an Int though...
Another solution would be to replace the DS1307 with another RTC which have programmable alarms. For example the DS3231 can trigger an interrupt every hour. That will remove the need of constantly checking the time in loop().