I am using a DS3231 RTC module. It requires to set the time every time it is reset. I was wondering if I could read my MacBook's time and date and feed into the module at the setup stage. Is this possible?
P.S. I do not have to use a battery.
-
2Actually the whole point of an RTC is that it has a battery backed up clock that does NOT reset on power loss.Kwasmich– Kwasmich2019年04月02日 12:44:00 +00:00Commented Apr 2, 2019 at 12:44
-
Yes. But due to some reason, I have a RTC without a battery backup. I had myself opened the Amazon packing today and unboxed the module. And the bottom side has no battery.Nimish Mishra– Nimish Mishra2019年04月02日 12:45:52 +00:00Commented Apr 2, 2019 at 12:45
-
5So.... attach a battery?Majenko– Majenko2019年04月02日 12:52:53 +00:00Commented Apr 2, 2019 at 12:52
-
1Please note that some of these modules have a (badly designed) charging circuit, and thus require a rechargeable coin cell (LIR2032). Or you can remove the charging resistor from the board.Gerben– Gerben2019年04月02日 14:30:33 +00:00Commented Apr 2, 2019 at 14:30
-
1What I've do with one of my clocks if create an interactive serial console, where I could type the current time, when the code saw that the RTC was reset. There is no way to get the time from the USB host without some software running on the host, or like I did, some manual serial data entry.Gerben– Gerben2019年04月02日 14:32:24 +00:00Commented Apr 2, 2019 at 14:32
2 Answers 2
You can use __DATE__
and __TIME__
compiler time constants in IDE and do check inside of your setup()
function if the RTC clock is zeroed then parse and set compile time values.
char cr[] = __DATE__;
char ct[] = __TIME__;
At the compile time these macros will be replaced with text constants "Apr 4 2019"
and "10:35:22"
respectively.
You could use softRTC library to get date/time from your system. So program flow could be get date/time from softRTC library during setup part and then use those variables in loop set your DS2321 RTC which will always be running till you poweroff.
-
2softRTC is relying on the preprocessor. So each time you want to set the time you will have to open ArduinoIDE and compile+upload the sketch. This is not going to work in stand alone. Beside Atmel only guarantees 10.000 write cycles when uploading code.Kwasmich– Kwasmich2019年04月02日 14:26:01 +00:00Commented Apr 2, 2019 at 14:26
-
I can't find softRTC library. how does it solve the use of DS3231 without battery?2019年04月02日 16:58:53 +00:00Commented Apr 2, 2019 at 16:58