Raspberry Pi Python Library for the PCF8563

PCF8563 Raspberry Pi
PCF8563 Test Jig

Raspberry Pi Python Library for PCF8563  Real Time Clock

Here is the third of a series of Python libraries for the Raspberry Pi for various Real Time

PCF8563 Raspberry Pi
PCF8563 Test Jig

Clocks (RTC).  This is the pure Python driver for the PCF8563 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.

This is the final RTC library of a series of four.  I have already released the DS3231, DS1307 and the MCP79400 libraries.  The PCF8563 library is on https://github.com/switchdoclabs/RTC_SDL_PCF8563.
The PCF8563 (I used the PCF8563 Module sold on Amazon) is a 3.3V/5V device. You just connect it up to the Raspberry Pi I2C pins and you are ready to go.  The board I used has a handy pass thru of the I2C bus and some useful headers for INT, CLKOUT, etc.  It does have 4.7K Pullups on the SCL / SDA pins.

PCF8563 Raspberry Pi
The PCF8563 Board

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

Real Time Clocks Raspberry PI
Four RTC Test Jig

DS3231, DS1307 and the MCP79400 over the past few weeks.

Example Code for the PCF8563

There is a testSDL_PCF8563.py included with the library. Here is the bare code needed:

#!/usr/bin/env python
#
# Test SDL_PCF8563
# John C. Shovic, SwitchDoc Labs
# 08/07/2014
#
#

# imports

import sys
import time
import datetime

import SDL_PCF8563

# Main Program

print ""
print "Test SDL_PCF8563 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()

pcf8563 = SDL_PCF8563.SDL_PCF8563(1, 0x51)
pcf8563.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 "PCF8563=\t\t%s" % pcf8563.read_datetime()

        time.sleep(10.0)

Your results should look like this.

Test SDL_PCF8563 Version 1.0 - SwitchDoc Labs
Program Started at:2014-08-07 16:15:41
Raspberry Pi= 2014-08-07 16:15:41
PCF8563= 2014-08-07 16:15:31

Initial Test Results for the PCF8563

I am in the process of running a month long test of three RTCs (DS3231, MCP79400 and the PCF8563) and so far, the PCF8563 is running with an error < 5ppm (parts per million).  5ppm is about .45 seconds per day.  The specification and app notes available for the PCF8563 are vague in terms of expected ppm, as it is dependent on the board design, temperature, crystal and capacitor choices, but I could tease out a number around 10ppm, so 5ppm isn’t unexpected as I am not varying temperature.

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.

Project Curacao, Arduino and the PCF8563

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.   The PCF8563 is a lot more accurate than the DS1307.  However, 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 the DS3231 RTC in the upgrade in September.

1 Comment

  1. Hello!
    I try use you library and test program in Raspberry B++, and have error:

    $ sudo python testSDL_PCF8563.py
    Test SDL_PCF8563 Version 1.0 - SwitchDoc Labs
    Program Started at:2015-01-26 09:57:55
    Traceback (most recent call last):
    File "testSDL_PCF8563.py", line 28, in
    pcf8563 = SDL_PCF8563.SDL_PCF8563(1, 0x51)
    File "/home/pi/rtc/SDL_PCF8563.py", line 88, in __init__
    self._bus = smbus.SMBus(twi)
    File "/usr/local/lib/python2.7/dist-packages/smbus/smbus.py", line 119, in __init__
    self.open(bus)
    File "/usr/local/lib/python2.7/dist-packages/smbus/smbus.py", line 146, in open
    raise IOError(e.errno)
    IOError: 2

    My devices is: Raspbery Pi B++, plate DVK511 and PCF8563 RTC Board. What is “IOError: 2”?

4 Trackbacks / Pingbacks

  1. Real Time Clock Python Libraries For Raspberry Pi - Reviews - SwitchDoc Labs
  2. Real Time Clocks: Raspberry Pi Comparison Results - SwitchDoc Labs
  3. Benchmarks: RealTime Clocks - DS3231 / PCF8563 / MCP79400 / DS1307 - SwitchDoc Labs
  4. Benchmarks of Real Time Clocks - Raspberry Pi and Arduino - SwitchDoc Labs

Comments are closed.