Skip to main content

Introduction to Adafruit’s PCF8563 Real Time Clock (RTC) Library

Documentation Status Discord Build Status Code Style: Ruff

This is a great battery-backed real time clock (RTC) that allows your microcontroller project to keep track of time even if it is reprogrammed, or if the power is lost. Perfect for datalogging, clock-building, time stamping, timers and alarms, etc.

The PCF8563 is simple and inexpensive but not a high precision device. It may lose or gain multiple seconds a day. For a high-precision, temperature compensated alternative, please check out the DS3231 precision RTC. If you need a DS1307 for compatibility reasons, check out our DS1307 RTC breakout.

Dependencies

This driver depends on the Register and Bus Device libraries. Please ensure they are also available on the CircuitPython filesystem. This is easily achieved by downloading a library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-pcf8563

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-pcf8563

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-pcf8563

Usage Notes

Basics

Of course, you must import the library to use it:

import busio
from adafruit_pcf8563.pcf8563 import PCF8563
import time

All the Adafruit RTC libraries take an instantiated and active I2C object (from the busio library) as an argument to their constructor. The way to create an I2C object depends on the board you are using. For boards with labeled SCL and SDA pins, you can:

from board import *

Now, to initialize the I2C bus:

i2c_bus = board.I2C()

Once you have created the I2C interface object, you can use it to instantiate the RTC object:

rtc = PCF8563(i2c_bus)

Date and time

To set the time, you need to set datetime to a time.struct_time object:

rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1))

After the RTC is set, you retrieve the time by reading the datetime attribute and access the standard attributes of a struct_time such as tm_year, tm_hour and tm_min.

t = rtc.datetime
print(t)
print(t.tm_hour, t.tm_min)

Alarm

To set the time, you need to set alarm to a tuple with a time.struct_time object and string representing the frequency such as “hourly”:

rtc.alarm = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")

After the RTC is set, you retrieve the alarm status by reading the alarm_status attribute. Once True, set it back to False to reset.

if rtc.alarm_status:
    print("wake up!")
    rtc.alarm_status = False

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Metadata

Release files for adafruit-circuitpython-pcf8563 2.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adafruit-circuitpython-pcf8563 2.0.9
File Size Uploaded
adafruit_circuitpython_pcf8563-2.0.9.tar.gz 25.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adafruit-circuitpython-pcf8563 2.0.9
File Interpreter ABI Platform
adafruit_circuitpython_pcf8563-2.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / adafruit_circuitpython_pcf8563-2.0.9.tar.gz

Download URL adafruit_circuitpython_pcf8563-2.0.9.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c69609b971c532a584123043ba61a9f93311e1cb259f2f0df8d12720e30fadbb
BLAKE2b-256 checksum
How to use checksums
d50e0d5e193fdae864bf01c8eff536ac76f27489f39612cda9462bf66ef3e026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / adafruit_circuitpython_pcf8563-2.0.9-py3-none-any.whl

Download URL adafruit_circuitpython_pcf8563-2.0.9-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7af5439fcedc83db9d8f212b26bcd1a2473bcf096e947e9fafbe9e63b04ce72
BLAKE2b-256 checksum
How to use checksums
fb6f11805be879f1d6182225b3947a370dbdb4d6a032095fcfb1a76d8026ab0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

2.0.9 This release

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page