Configure DS3234 RTC in OSBSS dataloggers

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:

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.

  • Lambert

    Sorry to bother again, DS3234.h here is not library used in datalogger, which library it is?

    • http://www.osbss.com/ OSBSS

      You will need the DS3234 library. Blog post updated with the link. We will eventually merge functions for setting time in our library.

      If you encounter other problems, do let us know; these tutorials are a work in progress and can always be improved.

  • Mark

    Have you encountered where the day remains 25 and the minute stays 85 in the serial monitor regardless of what’s in the code? I’ve tried the Sparkfun breakout and a generic, on the DHT logger and TRH logger circuits, and using both this RTC and the DHT RTC code but I keep getting this problem and it’s leaving me puzzled. I was able to get it working right finally in the TRH circuit, but now I can’t get past this weird issue on the DHT circuit.

    • http://www.osbss.com/ OSBSS

      This means the RTC isn’t being detected by the Arduino. If it’s working fine on the TRH circuit but not on the DHT circuit, there’s something wrong in the code. The SPI pins are set differently in the DHT 22 tutorial – make sure you configure them properly in the code. Also make sure some pins aren’t being shorted out or that there’s a loose connection somewhere.