Raspberry Pi Python Library for DS3231 Real Time Clock

Here is the third of a series of Python libraries for the Raspberry Pi for various Real Time Clocks (RTC). This is the pure Python driver for the DS3231 Real Time Clock(SwitchDoc Module here). The original

DS3231 Test Jig

code is the DS1307 library from @XiErCh. The main changes involve removing the 12 hour mode, which didn’t work correctly in all cases and a different clock starting procedure. This library now only runs in 24 hour mode. The DS3231 also has an on board temperature sensor that I will add into the library for the next version (this is now done as of August 7, 2014).

I will be releasing a library for the PCF8563 in the next couple of weeks. I have already released the DS1307 and the MCP79400 libraries. The DS3231 library is on https://github.com/switchdoclabs/RTC_SDL_DS3231.
The DS3231 (I used the SwitchDoc Labs DS3231 Module from our store ) is a 3.3V/5V device. You just connect it up to the Raspberry Pi I2C pins and you are ready to go.

To the right is a picture of the four RTC test jig. I have released the libraries for the

Four RTC Test Jig

DS1307 and the MCP79400 over the past few weeks. The Python library for the PCF8563 will be released next week.

Example Code for the DS3231

There is a testSDL_DS3231.py included with the library. Here is the bare code needed:
#!/usr/bin/env python
#
# Test SDL_DS3231
# John C. Shovic, SwitchDoc Labs
# 08/03/2014
#
#

Initial Test Results for the DS3231

I am in the process of running an month long test of three RTCs (DS3231, MCP79400 and the PCF8563) and so far, the DS3231 is running with an error < 2ppm (parts per million). 2ppm is about .17 seconds per day. I ran the test for the DS1307 and saw > 20ppm. Since I only can detect errors > 1 second, it will be a few more days until we all find out what the error rate really is. The DS3231 does do temperature compensation, so it is not going to drift as much with temperature. Temperature is clearly a problem for a project such as Project Curacao in the tropics, so I am planning to use this RTC in the upgrade in September.

Project Curacao, Arduino and the DS3231

I used a Adafruit DS1307 on Project Curacao connected to the Arduino Battery Watchdog. This has been the source of reliability issues on the Arduino. It requires a reboot (power on / off) about once a month. And it is the DS1307 getting lost. Noise? Heat? I am not sure. But I am replacing it in September with the DS3231 which is temperature compensated in any case.