Arduino Clock that doesn't poll the RTC all the time


I'm currently working on a project which involves quite some things in one Arduino Mega, like:

SD Slot
Ethernet (W5500)
RGB LED Dimming (PWM)
OLED Display (using u8glib)
RTC Module (DS3231)
Temperature/Humidity Monitoring (DHT22)
User control via buttons and website

so far, everything is working great but when I poll the RTC, the program hangs for a little time and I'd like to get rid of that. Currently I'm polling the RTC every 200ms or so, because if I increase that value, I've observed the seconds "jumping" sometimes.

So my approach was to poll the RTC only once in a while and increment the time using another mechanism. I guess, millis won't be too accurate, as it is affected by the rest of the code running on the µC, right?

Any idea? Like using some timer with interrupts? I don't really know what direction to go at the moment.
How is this done normally? Polling the RTC all the time works, if the µC isn't doing anything else (or at least if it doesn't have to serve user requests).

Use interrupts for user requests is the wrong approach in my opinion, because it doesn't solve the root issue in the first place.

Thanks all for your advices!

You can set up the DS3231 so that it causes an interrupt every second. The interrupt routine sets a byte flag, and the loop function just checks whether the flag is set. Easy.


The finest resolution of the 3231 is one second. So poll it once a second. Or do you need more resolution? In which case use millis() to keep track of the ms in between seconds.

You can use this Arduino Time library

The Time library adds timekeeping functionality to Arduino with or without external timekeeping hardware. It allows a sketch to get the time and date as: second, minute, hour, day, month and year.

Using these function to provide time synchronization by RTC.

	setSyncProvider(getTimeFunction);// Set the external time
									  //  provider

	setSyncInterval(interval);    // Set the number of
								   //  seconds between re-sync

You can function like this

	setSyncProvider(RTC.get);   // the function to get the time from the RTC