The DS3234 RTC breakout from SparkFun does not include a backup battery (CR1225). After inserting the battery, the RTC’s oscillator initializes and starts keeping time from 1/1/2000 00:00:00. The RTC’s time needs to be manually setup once. If you’ve already assembled an OSBSS datalogger, upload the following code to configure the current time in the RTC:
// RTC.configure(MOSI, MISO, CLK, CS) // RTC.setDateTime(day, month, year, hour, minute, second) #include <DS3234.h> void setup() { Serial.begin(19200); //Pin configurations for all OSBSS dataloggers: pinMode(6, OUTPUT); pinMode(4, OUTPUT); pinMode(3, OUTPUT); digitalWrite(6, HIGH); digitalWrite(4, HIGH); digitalWrite(3, HIGH); delay(5); RTC.configure(11,12,13,10); // for OSBSS datalogger //RTC.configure(10,11,12,13); // for bare RTC on Arduino Pro Mini or Uno RTC.setDateTime(26,3,15,17,25,0); // Format: DD/MM/YY hh:mm:ss } void loop() { Serial.println(RTC.readDateTime()); delay(1000); }
You need to install the DS3234 library for syncing time.
In the function RTC.setDateTime(), replace the numbers with the current day, month, year, hour, minute and second and upload the code. Make sure you select the correct board and processor in the IDE. In most OSBSS dataloggers, this should be Arduino Pro Mini (3.3V, 8MHz). After uploading, open the serial monitor and ensure the baud rate is 19200. The RTC starts keeping time from your configured date and time. Once the RTC is set, you can configure the launch time and upload the datalogger’s code without unplugging the FTDI cable. This is to ensure the RTC isn’t configured again to your previously set time once you plug the cable back in. The OSBSS datalogger will now start logging at the exact date and time.
If you want to sync the RTC with your PC’s exact time, set the minute variable in the function to a minute ahead in the future. After the code is set, press the serial monitor button about two seconds before the set minute. This takes care of that small delay before the serial monitor opens. You should now see your PC’s time and the RTC’s time to be in perfect sync.
Note: PC’s clocks are not accurate. They are known for their large drifts and should not be relied on for referring to the exact time. If you’re concerned about maintaining the exact date and time, check your PC’s clock time with a web server (which is usually synced with an atomic clock). In Windows, the clock time is synced with the internet time once a week. During this week however, the time drifts a lot, by almost a minute or more in some cases. There are some tweaks you can do to ensure that the time syncs more often, but a simple way would be to shut down your PC every night. The time is synced every time it turns on. The DS3234 RTC however is extremely accurate due to its unique temperature-compensated crystal, and it is able to maintain time with minimal or almost no drift throughout the year without needing to be re-synced. A 3.4 million second drift test done using several RTCs including the DS3231 (same IC as DS3234, but uses an I2C interface) shows that the RTC is more accurate than its advertised accuracy over an extended period of time.