Page 1 of 1
Read Passing Second from RTC
Posted: Sun Oct 03, 2021 11:01 am
by AbhijitR
Hello!
I am trying to save some readings after every 1 second, i am using DS3231 RTC for time keeping, i tried to do something similar from below post of Ben, but unfortunately it is not working as expected.
viewtopic.php?p=98927#p98927
I want to note and add the reading on every passing second, then after finishing 60 sec or 1 min i want to divide the reading by 60 to find the average for that minute and then store in SD, i am able to do the math and store too but what i notice is the time delay of 60 sec to do the math is increasing by few sec after every 1 minute, i think i am not catching each passing sec correctly from the RTC.
IS there any other way to catch the second from RTC correctly.
Thank you.
Abhi
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 11:03 am
by mnf
Hi Abhi,
The RTC can generate a 1s pulse - use this to generate an interrupt - and take a reading then.
Martin
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 12:00 pm
by AbhijitR
Hi! Martin
good afternoon
Thank you to share your views, may i request you to share some example if possible, or may be a link to some post, unfortunately i did not find any on that topic. I have observed one more thing with my RTC module, apart from Vcc, Gnd, SDA, SCK there is no other pin available to collect the signal or pulse.
Abhi
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 12:18 pm
by mnf
Hi Abhi,
A simple example - I used an Arduino Nano (and then I can plug my RTC module in on pin A2-A7 and power the RTC using A2 and A3 - you can remove the setup (output to A2 and A3) if you use a different power mode).
Note - I used the Ds3231 component from
viewtopic.php?f=80&t=22188&hilit=ds3231+revisited - but the same principle applies if you use the FC component.
The MCU is 'slept' - and woken by the 1s interrupt - connect the sqw output pin on RTC to d2 (it's SQW on my board - if there are only 4 pins then maybe there is no SQW out available with your board!). SQW is pin 3 on the DS3231 chip and it needs a pullup resistor to Vcc (see
https://www.digikey.co.uk/en/datasheets ... 31-ds3231s) I'd be tempted to try connecting it to D2 and using the Arduino internal pullup
Here it just outputs the time and the 1s counter counting the interrupts (which runs 0..255 as I used a byte and don't roll it into minutes)
Martin
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 1:29 pm
by AbhijitR
Hello! Martin
Humbly thank you for your valuable input, your suggestion worked like a "Piece of Cake".
As you instructed i manage to take the pin 3 of the chip to one of the interrupt pin on my chip, the RTC was already powered, i configured the SQWandINTcontrol Macro at the beginning of the main loop and done, i can see the LED placed in the INT macro flashing every sec, i had a very big smile on my face,

like that.
Thank you once again for your quick reply.
Abhi
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 1:46 pm
by mnf
Glad to hear it worked - especially with the connection to the chip being necessary - I'm not sure my soldering skills would cope with that!
Martin
Re: Read Passing Second from RTC
Posted: Sun Oct 03, 2021 1:57 pm
by AbhijitR
Hi! Martin
Not only the LED blink every second my calculation box now calculate the average exactly after 1 minute without fail.
And regarding the soldering to the pin 3, it was not a big trouble.
Cheers Martin, have a pleasant evening.
Abhi