Raspberry Pi Python Library for MCP79400 Real Time Clock
Here is the second of a series of Python libraries for the Raspberry Pi for various Real Time Clocks (RTC). This is the pure Python driver for the MCP79400 Real Time Clock. The original 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. We will be releasing libraries for the DS3231 and the PCF8563 over the next couple of weeks. To the left is a picture of the four RTC test jig. The MCP79400 library is on https://github.com/switchdoclabs/RTC_SDL_MCP79400.
The MCP79400 (we used the BM005 Clock and Calendar Module from Solutions Cubed, LLC) is a 3.3V and 5V device. You just connect it up to the Raspberry Pi I2C pins and you are ready to go.
We will be releasing libraries for the DS3231 and PCF8563 in the next few weeks. The python library for the DS1307 has already been released (https://github.com/switchdoclabs/RTC_SDL_DS1307).
Example Code for the MCP79400
There is a testSDL_MCP79400.py included with the library. Here is the bare code needed:
import sys import time import datetime import SDL_MCP79400 # Main Program print "" print "Test SDL_MCP79400 Version 1.0 - SwitchDoc Labs" print "" print "" print "Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S") filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt" starttime = datetime.datetime.utcnow() # MCP79400 # Note: MCP79400 can't quite use the same library as DS1307 for read/write time # There are differences in starting the clock mcp79400 = SDL_MCP79400.SDL_MCP79400(1, 0x6F) mcp79400.write_now() # Main Loop - sleeps 10 minutes, then reads and prints values of all clocks while True: currenttime = datetime.datetime.utcnow() deltatime = currenttime - starttime print "" print "Raspberry Pi=\t" + time.strftime("%Y-%m-%d %H:%M:%S") print "MCP79400=\t\t%s" % mcp79400.read_datetime() time.sleep(10.0)
You should see a result like this:
Raspberry Pi= 2014-07-27 19:36:32 MCP79400= 2014-07-27 19:36:32
Initial Test Results for the MCP79400
I am in the process of running an month long test of three RTCs (DS3231, MCP79400 and the PCF8563) and so far, the MCP79400 is running with an error < 20ppm (parts per million). 20ppm is about 1.7 seconds per day. It will be a few more days until we find out what the error rate really is. This device does allow you to trim the clock with an adjustment of up to +/- 127ppm, so we may be able to get quite accurate. It does not do temperature compensation as the DS3231 does, so it is still going to drift with temperature. This is clearly a problem for a project such as Project Curacao in the tropics.
Project Curacao, Arduino and the MCP79400
We 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? We are not sure. But we are replacing it in September possibly with the MCP79400, but more likely the DS3231 which is temperature compensated.
5 Trackbacks / Pingbacks
Comments are closed.