Setting accurate time with DS3231.h library

Hi friends,

I’m using the <DS3231.h> library in a project and having a few challenges which I know is die to my user error.

I’ve tried to se the module a accurately as possible, yet always off by a few seconds due to the upload process.

Questions:

  1. Can the DS3231 module retrieve system time? If not, is there a more accurate way to set the time?
  2. I notice the date and year do not update. Is there another procedure for this?

Thanks for any help!

screen_shot 2019-12-25 at 10.43.13 PM.jpg

1) The module cannot retrieve the time. The module time and date registers are set using program commands.

2) One certainly can set the month, day and year. Post the failing code, using code tags.

To accurately set the RTC, you have to write a program that will read a time from the Serial port and then program the RTC to match that date/time. I typically use RTCLib which has an adjust() function. I copy the unixtime from a time website (a few seconds in the future) and paste it into the Serial Monitor and press ENTER when the current time arrives.

You can also use the compile date/time example but simply add a few seconds to it and play around until you get the time correct.

Thanks friends.

I noticed I had the day/month backwards which resulted in the inaccurate date.

I'll give the RTC lib a try.

Thanks!

If you just want time, you don't need a library. You most certainly don't need one to just set the time, particularly as you probably don't need to do it often. If you do, you might consider getting the time off the internet anyway, or perhaps GPS, and maybe dispense with the DS3231 altogether. In the meantime, below includes a separate programme to set the time and easily good for one second accuracy. It is set on release of the reset button.

http://bildr.org/2011/03/ds1307-arduino/

Thank you! I'll check it out!

Nick_Pyner: If you just want time, you don't need a library. You most certainly don't need one to just set the time, particularly as you probably don't need to do it often. If you do, you might consider getting the time off the internet anyway, or perhaps GPS, and maybe dispense with the DS3231 altogether. In the meantime, below includes a separate programme to set the time and easily good for one second accuracy. It is set on release of the reset button.

http://bildr.org/2011/03/ds1307-arduino/

there is a line in the code to set the time.

you put it in for a minute from now with 0:00 seconds and load it.

put up the internet for time.

hold the reset button down and when the internet time matches your time, let go.

the reset will reset the time to the time you set.

================

now, immediately, remark out the line that sets time and re-upload.

since there never was a second re-set, the RTC holds the time of the last re-set and you re-uploaded the code without the bit that alters the RTC time.