Arduino DS1302 & creating interupt for updating display

I am building an clock with an arduino UNO & DS1302  RTC & some neopixels, got it working mostly but I cannot seem to implment a interupt that will update the time only when it has changed.

I have tried a few methods but with no luck, but none of which address the flow, its impossible to keep checking & sometimes even when I do seconds are missed here & there so an interupt is the best way

Does anyone have any examples of a working interupts  I can modifyt to work with RTC, I simply want to trigger  the update time function when the DS1302 sends trigger, then I can go about my sketch & let the interupt handle it

I havent had much luck reading the pulse either, I can read the time, set the time & all that but I havent been able to set/verify its bytes, theres one for example that sets "trickle_charger" I can disable , but I havent been able to read the byte to verify if its 1 or 0

any help would be great, 

iceng2 months ago

I keep the smallest last time digit, then every key pole read the time and if that digit is changed you update the display . . . etc etc

rdlockrey (author)  iceng2 months ago

I think thats what im doing now, the thing is alot can happen before I poll the rtc to see if its changed, using the second seems logical & works but isnt very accurate, I have tweaked it a few times now but still it comes down to basically manually checking,

heres an example what mean... here's a very basic chime function that sounds every hour, if the minutes are :00 and the seconds are :00 then it must be a new hour.

// sudo example not tested

if (min==0) && (sec==0)


the above code works but at times it would miss the chime because it was busy & took a second to poll the rtc, by the time it got back & polled the rtc it was :01 so it failed, this is obviously bad coding but I needed to start somewhere.

my biggest issue is delays, I have been able to remove all but one delay, since I have an oled display & some leds & piezo, its needed until I can get an interupt with a 1 second pulse.

why Cant I I use the SQ out to read when its changed? like this.. why wont this theory work for me?

// -----------------------
// code starts here

const byte interruptPin = 2;

void setup()
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), rtc_pulse, CHANGE);

void loop()

// no code in loop used for this example

void rtc_pulse()
// time_update(); //got the pulse call update function

void time_update()

// position cursor
// set font black
// write the old value
// position cursor
// set font white
// write new value


// -----------------------
// code ends here

it seems to me the code theory should work... it might not be exactly formatted but isnt this the correct forumlas?

If I had a working example of a interupt that was triggered upon change then I think I could make it work, i just need to work on it, im missing something... I ordered a high precision ds-3231 if I ever get to version 2 of this clock, but I sure would like to grasp this issue. Im going to need more and more interupts with future projects

steveastrouk2 months ago

Use a timer interrupt, with a nominal period of 1 second ? The 1302 doesn't generate an interrupt every second like some RTC chips do