Skip to content

Commit 1487891

Browse files
committed
Switch library to PCF8563, a similar RTC to PCF8523
.. but not so similar that we want to support them in the same library.
1 parent b170b09 commit 1487891

File tree

8 files changed

+65
-88
lines changed

8 files changed

+65
-88
lines changed

README.rst

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11

2-
Introduction to Adafruit's PCF8523 Real Time Clock (RTC) Library
2+
Introduction to Adafruit's PCF8563 Real Time Clock (RTC) Library
33
================================================================
44

5-
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-pcf8523/badge/?version=latest
6-
:target: https://circuitpython.readthedocs.io/projects/pcf8523/en/latest/
5+
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-pcf8563/badge/?version=latest
6+
:target: https://circuitpython.readthedocs.io/projects/pcf8563/en/latest/
77
:alt: Documentation Status
88

99
.. image :: https://img.shields.io/discord/327254708534116352.svg
1010
:target: https://discord.gg/nBQh6qu
1111
:alt: Discord
1212
13-
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_PCF8523/workflows/Build%20CI/badge.svg
14-
:target: https://github.com/adafruit/Adafruit_CircuitPython_PCF8523/actions/
13+
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_PCF8563/workflows/Build%20CI/badge.svg
14+
:target: https://github.com/adafruit/Adafruit_CircuitPython_PCF8563/actions/
1515
:alt: Build Status
1616

1717
This is a great battery-backed real time clock (RTC) that allows your
1818
microcontroller project to keep track of time even if it is reprogrammed,
1919
or if the power is lost. Perfect for datalogging, clock-building, time
20-
stamping, timers and alarms, etc. Equipped with PCF8523 RTC - it can
20+
stamping, timers and alarms, etc. Equipped with PCF8563 RTC - it can
2121
run from 3.3V or 5V power & logic!
2222

23-
The PCF8523 is simple and inexpensive but not a high precision device.
24-
It may lose or gain up to two seconds a day. For a high-precision,
23+
The PCF8563 is simple and inexpensive but not a high precision device.
24+
It may lose or gain multiple seconds a day. For a high-precision,
2525
temperature compensated alternative, please check out the
2626
`DS3231 precision RTC. <https://www.adafruit.com/products/3013>`_
2727
If you need a DS1307 for compatibility reasons, check out our
2828
`DS1307 RTC breakout <https://www.adafruit.com/products/3296>`_.
2929

30-
.. image:: _static/3295-00.jpg
31-
:alt: PCF8523 Breakout Board
32-
3330
Dependencies
3431
=============
3532

@@ -42,17 +39,17 @@ This is easily achieved by downloading
4239
Installing from PyPI
4340
====================
4441
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
45-
PyPI <https://pypi.org/project/adafruit-circuitpython-pcf8523/>`_. To install for current user:
42+
PyPI <https://pypi.org/project/adafruit-circuitpython-pcf8563/>`_. To install for current user:
4643

4744
.. code-block:: shell
4845
49-
pip3 install adafruit-circuitpython-pcf8523
46+
pip3 install adafruit-circuitpython-pcf8563
5047
5148
To install system-wide (this may be required in some cases):
5249

5350
.. code-block:: shell
5451
55-
sudo pip3 install adafruit-circuitpython-pcf8523
52+
sudo pip3 install adafruit-circuitpython-pcf8563
5653
5754
To install in a virtual environment in your current project:
5855

@@ -61,7 +58,7 @@ To install in a virtual environment in your current project:
6158
mkdir project-name && cd project-name
6259
python3 -m venv .env
6360
source .env/bin/activate
64-
pip3 install adafruit-circuitpython-pcf8523
61+
pip3 install adafruit-circuitpython-pcf8563
6562
6663
6764
Usage Notes
@@ -75,7 +72,7 @@ Of course, you must import the library to use it:
7572
.. code:: python
7673
7774
import busio
78-
import adafruit_pcf8523
75+
import adafruit_pcf8563
7976
import time
8077
8178
All the Adafruit RTC libraries take an instantiated and active I2C object
@@ -101,7 +98,7 @@ the RTC object:
10198

10299
.. code:: python
103100
104-
rtc = adafruit_pcf8523.PCF8523(i2c_bus)
101+
rtc = adafruit_pcf8563.PCF8563(i2c_bus)
105102
106103
Date and time
107104
-------------
@@ -145,7 +142,7 @@ Contributing
145142
============
146143

147144
Contributions are welcome! Please read our `Code of Conduct
148-
<https://github.com/adafruit/Adafruit_CircuitPython_PCF8523/blob/master/CODE_OF_CONDUCT.md>`_
145+
<https://github.com/adafruit/Adafruit_CircuitPython_PCF8563/blob/master/CODE_OF_CONDUCT.md>`_
149146
before contributing to help this project stay welcoming.
150147

151148
Documentation

adafruit_pcf8523.py renamed to adafruit_pcf8563.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
# THE SOFTWARE.
2222

2323
"""
24-
`adafruit_pcf8523` - PCF8523 Real Time Clock module
24+
`adafruit_pcf8563` - PCF8563 Real Time Clock module
2525
====================================================
2626
27-
This library supports the use of the PCF8523-based RTC in CircuitPython. It
27+
This library supports the use of the PCF8563-based RTC in CircuitPython. It
2828
contains a base RTC class used by all Adafruit RTC libraries. This base
2929
class is inherited by the chip-specific subclasses.
3030
@@ -40,9 +40,8 @@ class is inherited by the chip-specific subclasses.
4040
4141
**Hardware:**
4242
43-
* Adafruit `Adalogger FeatherWing - RTC + SD Add-on <https://www.adafruit.com/products/2922>`_
44-
(Product ID: 2922)
45-
* Adafruit `PCF8523 RTC breakout <https://www.adafruit.com/products/3295>`_ (Product ID: 3295)
43+
+* Seeeduino `XIAO Expansion Board - Works With Adafruit QT Py <https://www.adafruit.com/product/5033>`_
44+
+ (Product ID: 5033)
4645
4746
**Software and Dependencies:**
4847
@@ -53,56 +52,47 @@ class is inherited by the chip-specific subclasses.
5352
**Notes:**
5453
5554
#. Milliseconds are not supported by this RTC.
56-
#. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8523.pdf
55+
#. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf
5756
5857
"""
5958

6059
__version__ = "0.0.0-auto.0"
61-
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCF8523.git"
60+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCF8563.git"
6261

6362
from adafruit_bus_device.i2c_device import I2CDevice
6463
from adafruit_register import i2c_bit
65-
from adafruit_register import i2c_bits
6664
from adafruit_register import i2c_bcd_alarm
6765
from adafruit_register import i2c_bcd_datetime
6866

69-
STANDARD_BATTERY_SWITCHOVER_AND_DETECTION = 0b000
70-
BATTERY_SWITCHOVER_OFF = 0b111
67+
import time
7168

69+
class PCF8563:
70+
"""Interface to the PCF8563 RTC."""
7271

73-
class PCF8523:
74-
"""Interface to the PCF8523 RTC."""
75-
76-
lost_power = i2c_bit.RWBit(0x03, 7)
77-
"""True if the device has lost power since the time was set."""
78-
79-
power_management = i2c_bits.RWBits(3, 0x02, 5)
80-
"""Power management state that dictates battery switchover, power sources
81-
and low battery detection. Defaults to BATTERY_SWITCHOVER_OFF (0b000)."""
82-
72+
datetime_compromised = i2c_bit.RWBit(0x2, 7)
73+
"""True if the clock integrity is compromised."""
74+
8375
# The False means that day comes before weekday in the registers. The 0 is
8476
# that the first day of the week is value 0 and not 1.
85-
datetime_register = i2c_bcd_datetime.BCDDateTimeRegister(0x03, False, 0)
77+
datetime_register = i2c_bcd_datetime.BCDDateTimeRegister(0x02, False, 0)
8678
"""Current date and time."""
8779

8880
# The False means that day and weekday share a register. The 0 is that the
8981
# first day of the week is value 0 and not 1.
9082
alarm = i2c_bcd_alarm.BCDAlarmTimeRegister(
91-
0x0A, has_seconds=False, weekday_shared=False, weekday_start=0
83+
0x09, has_seconds=False, weekday_shared=False, weekday_start=0
9284
)
93-
"""Alarm time for the first alarm."""
85+
"""Alarm time for the alarm."""
9486

95-
alarm_interrupt = i2c_bit.RWBit(0x00, 1)
87+
alarm_interrupt = i2c_bit.RWBit(0x01, 1)
9688
"""True if the interrupt pin will output when alarm is alarming."""
9789

9890
alarm_status = i2c_bit.RWBit(0x01, 3)
9991
"""True if alarm is alarming. Set to False to reset."""
10092

101-
battery_low = i2c_bit.ROBit(0x02, 2)
102-
"""True if the battery is low and should be replaced."""
103-
10493
def __init__(self, i2c_bus):
105-
self.i2c_device = I2CDevice(i2c_bus, 0x68)
94+
time.sleep(.05)
95+
self.i2c_device = I2CDevice(i2c_bus, 0x51)
10696

10797
# Try and verify this is the RTC we expect by checking the timer B
10898
# frequency control bits which are 1 on reset and shouldn't ever be
@@ -112,9 +102,6 @@ def __init__(self, i2c_bus):
112102
with self.i2c_device as i2c:
113103
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
114104

115-
if (buf[1] & 0b00000111) != 0b00000111:
116-
raise ValueError("Unable to find PCF8523 at i2c address 0x68.")
117-
118105
@property
119106
def datetime(self):
120107
"""Gets the current date and time or sets the current date and time then starts the
@@ -124,5 +111,5 @@ def datetime(self):
124111
@datetime.setter
125112
def datetime(self, value):
126113
# Automatically sets lost_power to false.
127-
self.power_management = STANDARD_BATTERY_SWITCHOVER_AND_DETECTION
128114
self.datetime_register = value
115+
self.datetime_compromised = False

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
.. automodule:: adafruit_pcf8523
2+
.. automodule:: adafruit_pcf8563
33
:members:

docs/conf.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Adafruit PCF8523 RTC Library documentation build configuration file, created by
3+
# Adafruit PCF8563 RTC Library documentation build configuration file, created by
44
# sphinx-quickstart on Fri Nov 11 21:37:36 2016.
55
#
66
# This file is execfile()d with the current directory set to its
@@ -54,7 +54,7 @@
5454
master_doc = "index"
5555

5656
# General information about the project.
57-
project = "Adafruit PCF8523 RTC Library"
57+
project = "Adafruit PCF8563 RTC Library"
5858
copyright = "2016, Philip Moyer"
5959
author = "Philip Moyer"
6060

@@ -153,7 +153,7 @@
153153
# The name for this set of Sphinx documents.
154154
# "<project> v<release> documentation" by default.
155155
#
156-
# html_title = u'Adafruit PCF8523 RTC Library v1.0'
156+
# html_title = u'Adafruit PCF8563 RTC Library v1.0'
157157

158158
# A shorter title for the navigation bar. Default is the same as html_title.
159159
#
@@ -252,7 +252,7 @@
252252
# html_search_scorer = 'scorer.js'
253253

254254
# Output file base name for HTML help builder.
255-
# htmlhelp_basename = 'AdafruitsPCF8523RTCLibrarydoc'
255+
# htmlhelp_basename = 'AdafruitsPCF8563RTCLibrarydoc'
256256

257257
# -- Options for LaTeX output ---------------------------------------------
258258

@@ -277,8 +277,8 @@
277277
latex_documents = [
278278
(
279279
master_doc,
280-
"AdafruitPCF8523RTCLibrary.tex",
281-
"Adafruit PCF8523 RTC Library Documentation",
280+
"AdafruitPCF8563RTCLibrary.tex",
281+
"Adafruit PCF8563 RTC Library Documentation",
282282
"Philip Moyer",
283283
"manual",
284284
),
@@ -324,8 +324,8 @@
324324
man_pages = [
325325
(
326326
master_doc,
327-
"AdafruitPCF8523RTCLibrary23rtclibrary",
328-
"Adafruit PCF8523 RTC Library Documentation",
327+
"AdafruitPCF8563RTCLibrary23rtclibrary",
328+
"Adafruit PCF8563 RTC Library Documentation",
329329
[author],
330330
1,
331331
)
@@ -344,10 +344,10 @@
344344
texinfo_documents = [
345345
(
346346
master_doc,
347-
"AdafruitPCF8523RTCLibrary",
348-
"Adafruit PCF8523 RTC Library Documentation",
347+
"AdafruitPCF8563RTCLibrary",
348+
"Adafruit PCF8563 RTC Library Documentation",
349349
author,
350-
"AdafruitPCF8523RTCLibrary",
350+
"AdafruitPCF8563RTCLibrary",
351351
"One line description of project.",
352352
"Miscellaneous",
353353
),

docs/examples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Demo
22
----
33

4-
.. literalinclude:: ../examples/pcf8523_simpletest.py
5-
:caption: examples/pcf8523_simpletest.py
4+
.. literalinclude:: ../examples/pcf8563_simpletest.py
5+
:caption: examples/pcf8563_simpletest.py
66
:linenos:

docs/index.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@ Table of Contents
2020

2121
api
2222

23-
.. toctree::
24-
:caption: Tutorials
25-
26-
Adafruit PCF8523 Real Time Clock <https://learn.adafruit.com/adafruit-pcf8523-real-time-clock?view=all>
27-
Adafruit Adalogger FeatherWing <https://learn.adafruit.com/adafruit-adalogger-featherwing?view=all>
28-
2923
.. toctree::
3024
:caption: Related Products
3125

32-
Adafruit PCF8523 Real Time Clock Breakout <https://www.adafruit.com/product/3295>
33-
Adafruit Adalogger FeatherWing - RTC + SD <https://www.adafruit.com/product/2922>
26+
Seeeduino `XIAO Expansion Board - Works With Adafruit QT Py <https://www.adafruit.com/product/5033>`_
3427

3528
.. toctree::
3629
:caption: Other Links
3730

38-
Download <https://github.com/adafruit/Adafruit_CircuitPython_PCF8523/releases/latest>
31+
Download <https://github.com/adafruit/Adafruit_CircuitPython_PCF8563/releases/latest>
3932
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
4033
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
4134
Discord Chat <https://adafru.it/discord>

examples/pcf8523_simpletest.py renamed to examples/pcf8563_simpletest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
# Simple demo of reading and writing the time for the PCF8523 real-time clock.
1+
# Simple demo of reading and writing the time for the PCF8563 real-time clock.
22
# Change the if False to if True below to set the time, otherwise it will just
33
# print the current date and time every second. Notice also comments to adjust
44
# for working with hardware vs. software I2C.
55

66
import time
77
import board
8+
import busio
89

9-
# For hardware I2C (M0 boards) use this line:
10-
import busio as io
11-
12-
# Or for software I2C (ESP8266) use this line instead:
13-
# import bitbangio as io
14-
15-
import adafruit_pcf8523
10+
import adafruit_pcf8563
1611

1712
# Change to the appropriate I2C clock & data pins here!
18-
i2c_bus = io.I2C(board.SCL, board.SDA)
13+
i2c_bus = busio.I2C(board.SCL, board.SDA)
1914

2015
# Create the RTC instance:
21-
rtc = adafruit_pcf8523.PCF8523(i2c_bus)
16+
rtc = adafruit_pcf8563.PCF8563(i2c_bus)
2217

2318
# Lookup table for names of days (nicer printing).
2419
days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
@@ -37,8 +32,13 @@
3732
# pylint: enable-msg=using-constant-test
3833
# pylint: enable-msg=bad-whitespace
3934

35+
4036
# Main loop:
4137
while True:
38+
if rtc.datetime_compromised:
39+
print("RTC unset")
40+
else:
41+
print("RTC reports time is valid")
4242
t = rtc.datetime
4343
# print(t) # uncomment for debugging
4444
print(

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
long_description = f.read()
2020

2121
setup(
22-
name="adafruit-circuitpython-pcf8523",
22+
name="adafruit-circuitpython-pcf8563",
2323
use_scm_version=True,
2424
setup_requires=["setuptools_scm"],
25-
description="CircuitPython library for PCF8523 real time clock.",
25+
description="CircuitPython library for PCF8563 real time clock.",
2626
long_description=long_description,
2727
long_description_content_type="text/x-rst",
2828
# The project's main homepage.
29-
url="https://github.com/adafruit/Adafruit_CircuitPython_PCF8523",
29+
url="https://github.com/adafruit/Adafruit_CircuitPython_PCF8563",
3030
# Author details
3131
author="Adafruit Industries",
3232
author_email="[email protected]",
@@ -49,8 +49,8 @@
4949
"Programming Language :: Python :: 3.5",
5050
],
5151
# What does your project relate to?
52-
keywords="adafruit pcf8523 real time clock rtc breakout hardware micropython circuitpython",
52+
keywords="adafruit pcf8563 real time clock rtc breakout hardware micropython circuitpython",
5353
# You can just specify the packages manually here if your project is
5454
# simple. Or you can use find_packages().
55-
py_modules=["adafruit_pcf8523"],
55+
py_modules=["adafruit_pcf8563"],
5656
)

0 commit comments

Comments
 (0)