Skip to content

Commit 506eefe

Browse files
committed
improving_docs
1 parent faecef2 commit 506eefe

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

README.rst

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,51 +72,47 @@ Basics
7272

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

75-
.. code:: python
75+
.. code:: python3
7676
77-
import busio
78-
import adafruit_pcf8523
7977
import time
78+
import adafruit_pcf8523
8079
8180
All the Adafruit RTC libraries take an instantiated and active I2C object
82-
(from the `busio` library) as an argument to their constructor. The way to
81+
(from the `board` library) as an argument to their constructor. The way to
8382
create an I2C object depends on the board you are using. For boards with labeled
8483
SCL and SDA pins, you can:
8584

86-
.. code:: python
87-
88-
from board import *
85+
.. code:: python3
8986
90-
You can also use pins defined by the onboard `microcontroller` through the
91-
`microcontroller.Pin` module.
87+
import board
9288
9389
Now, to initialize the I2C bus:
9490

95-
.. code:: python
91+
.. code:: python3
9692
97-
i2c_bus = busio.I2C(SCL, SDA)
93+
i2c = board.I2C()
9894
9995
Once you have created the I2C interface object, you can use it to instantiate
10096
the RTC object:
10197

102-
.. code:: python
98+
.. code:: python3
10399
104-
rtc = adafruit_pcf8523.PCF8523(i2c_bus)
100+
rtc = adafruit_pcf8523.PCF8523(i2c)
105101
106102
Date and time
107103
-------------
108104

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

111-
.. code:: python
107+
.. code:: python3
112108
113109
rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1))
114110
115111
After the RTC is set, you retrieve the time by reading the `datetime`
116112
attribute and access the standard attributes of a struct_time such as ``tm_year``,
117113
``tm_hour`` and ``tm_min``.
118114

119-
.. code:: python
115+
.. code:: python3
120116
121117
t = rtc.datetime
122118
print(t)
@@ -128,14 +124,14 @@ Alarm
128124
To set the time, you need to set `alarm` to a tuple with a `time.struct_time`
129125
object and string representing the frequency such as "hourly":
130126

131-
.. code:: python
127+
.. code:: python3
132128
133129
rtc.alarm = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")
134130
135131
After the RTC is set, you retrieve the alarm status by reading the
136132
`alarm_status` attribute. Once True, set it back to False to reset.
137133

138-
.. code:: python
134+
.. code:: python3
139135
140136
if rtc.alarm_status:
141137
print("wake up!")

adafruit_pcf8523.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ class is inherited by the chip-specific subclasses.
2929
3030
**Software and Dependencies:**
3131
32-
* Adafruit CircuitPython firmware: https://github.com/adafruit/circuitpython/releases
32+
* Adafruit CircuitPython firmware for the supported boards:
33+
https://circuitpython.org/downloads
34+
3335
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
36+
3437
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
3538
3639
**Notes:**
@@ -54,7 +57,42 @@ class is inherited by the chip-specific subclasses.
5457

5558

5659
class PCF8523:
57-
"""Interface to the PCF8523 RTC."""
60+
"""Interface to the PCF8523 RTC.
61+
62+
:param ~busio.I2C i2c_bus: The I2C bus the device is connected to
63+
64+
**Quickstart: Importing and using the device**
65+
66+
Here is an example of using the :class:`PCF8523` class.
67+
First you will need to import the libraries to use the sensor
68+
69+
.. code-block:: python
70+
71+
import time
72+
import board
73+
import adafruit_pcf8523
74+
75+
Once this is done you can define your `board.I2C` object and define your sensor object
76+
77+
.. code-block:: python
78+
79+
i2c = board.I2C() # uses board.SCL and board.SDA
80+
rtc = adafruit_pcf8523.PCF8523(i2c)
81+
82+
Now you can give the current time to the device.
83+
84+
.. code-block:: python
85+
86+
t = time.struct_time((2017, 10, 29, 15, 14, 15, 0, -1, -1))
87+
rtc.datetime = t
88+
89+
You can access the current time accessing the :attr:`datetime` attribute.
90+
91+
.. code-block:: python
92+
93+
current_time = rtc.datetime
94+
95+
"""
5896

5997
lost_power = i2c_bit.RWBit(0x03, 7)
6098
"""True if the device has lost power since the time was set."""

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

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>
26+
Adafruit PCF8523 Real Time Clock <https://learn.adafruit.com/adafruit-pcf8523-real-time-clock/>
27+
Adafruit Adalogger FeatherWing <https://learn.adafruit.com/adafruit-adalogger-featherwing>
2828

2929
.. toctree::
3030
:caption: Related Products

examples/pcf8523_simpletest.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@
88

99
import time
1010
import board
11-
12-
# For hardware I2C (M0 boards) use this line:
13-
import busio as io
14-
15-
# Or for software I2C (ESP8266) use this line instead:
16-
# import bitbangio as io
17-
1811
import adafruit_pcf8523
1912

20-
# Change to the appropriate I2C clock & data pins here!
21-
i2c_bus = io.I2C(board.SCL, board.SDA)
22-
23-
# Create the RTC instance:
24-
rtc = adafruit_pcf8523.PCF8523(i2c_bus)
13+
i2c = board.I2C()
14+
rtc = adafruit_pcf8523.PCF8523(i2c)
2515

2616
# Lookup table for names of days (nicer printing).
2717
days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

0 commit comments

Comments
 (0)