adafruit_pcf8523 - PCF8523 Real Time Clock module

This library supports the use of the PCF8523-based RTC in CircuitPython. It contains a base RTC class used by all Adafruit RTC libraries. This base class is inherited by the chip-specific subclasses.

Functions are included for reading and writing registers and manipulating datetime objects.

Author(s): Philip R. Moyer and Radomir Dopieralski for Adafruit Industries. Date: November 2016 Affiliation: Adafruit Industries

Implementation Notes


Software and Dependencies:


  1. Milliseconds are not supported by this RTC.
  2. Datasheet:
class adafruit_pcf8523.PCF8523(i2c_bus)

Interface to the PCF8523 RTC.

Parameters:i2c_bus (I2C) – The I2C bus the device is connected to

Quickstart: Importing and using the device

Here is an example of using the PCF8523 class. First you will need to import the libraries to use the sensor

import time
import board
import adafruit_pcf8523

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
rtc = adafruit_pcf8523.PCF8523(i2c)

Now you can give the current time to the device.

t = time.struct_time((2017, 10, 29, 15, 14, 15, 0, -1, -1))
rtc.datetime = t

You can access the current time accessing the datetime attribute.

current_time = rtc.datetime

Alarm time for the first alarm.


True if the interrupt pin will output when alarm is alarming.


True if alarm is alarming. Set to False to reset.


True if the battery is low and should be replaced.


Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet figure 18 for the offset calibration calculation workflow.


False to apply the calibration offset every 2 hours (1 LSB = 4.340ppm); True to offset every minute (1 LSB = 4.069ppm). The default, False, consumes less power. See datasheet figures 28-31 for details.


Gets the current date and time or sets the current date and time then starts the clock.


Current date and time.


True for high oscillator capacitance (12.5pF), otherwise lower (7pF)


True if the device has lost power since the time was set.


Power management state that dictates battery switchover, power sources and low battery detection. Defaults to BATTERY_SWITCHOVER_OFF (0b000).