Skip to content

Commit b63c904

Browse files
Merge pull request #34 from jposada202020/improving_docs
improving_docs
2 parents 3061645 + 3eb5a93 commit b63c904

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

README.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,51 +85,47 @@ Basics
8585

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

88-
.. code:: python
88+
.. code:: python3
8989
90-
import busio
9190
import adafruit_ds3231
9291
import time
9392
9493
All the Adafruit RTC libraries take an instantiated and active I2C object
95-
(from the ``busio`` library) as an argument to their constructor. The way to
94+
(from the ``board`` library) as an argument to their constructor. The way to
9695
create an I2C object depends on the board you are using. For boards with labeled
9796
SCL and SDA pins, you can:
9897

99-
.. code:: python
98+
.. code:: python3
10099
101-
from board import *
102-
103-
You can also use pins defined by the onboard ``microcontroller`` through the
104-
``microcontroller.pin`` module.
100+
import board
105101
106102
Now, to initialize the I2C bus:
107103

108-
.. code:: python
104+
.. code:: python3
109105
110-
myI2C = busio.I2C(SCL, SDA)
106+
i2c = board.I2C()
111107
112108
Once you have created the I2C interface object, you can use it to instantiate
113109
the RTC object:
114110

115-
.. code:: python
111+
.. code:: python3
116112
117-
rtc = adafruit_ds3231.DS3231(myI2C)
113+
rtc = adafruit_ds3231.DS3231(i2c)
118114
119115
Date and time
120116
-------------
121117

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

124-
.. code:: python
120+
.. code:: python3
125121
126122
rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1))
127123
128124
After the RTC is set, you retrieve the time by reading the ``datetime``
129125
attribute and access the standard attributes of a struct_time such as ``tm_year``,
130126
``tm_hour`` and ``tm_min``.
131127

132-
.. code:: python
128+
.. code:: python3
133129
134130
t = rtc.datetime
135131
print(t)
@@ -141,15 +137,15 @@ Alarm
141137
To set the time, you need to set ``alarm1`` or ``alarm2`` to a tuple with a
142138
``time.struct_time`` object and string representing the frequency such as "hourly":
143139

144-
.. code:: python
140+
.. code:: python3
145141
146142
rtc.alarm1 = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")
147143
148144
After the RTC is set, you retrieve the alarm status by reading the corresponding
149145
``alarm1_status`` or ``alarm2_status`` attributes. Once True, set it back to False
150146
to reset.
151147

152-
.. code:: python
148+
.. code:: python3
153149
154150
if rtc.alarm1_status:
155151
print("wake up!")

adafruit_ds3231.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: MIT
55

66
"""
7-
`adafruit_ds3231` - DS3231 Real Time Clock module
7+
`adafruit_ds3231`
88
=================================================
99
CircuitPython library to support DS3231 Real Time Clock (RTC).
1010
@@ -26,12 +26,14 @@
2626
2727
**Software and Dependencies:**
2828
29-
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
30-
https://github.com/adafruit/circuitpython/releases
29+
* Adafruit CircuitPython firmware for the supported boards:
30+
https://circuitpython.org/downloads
3131
3232
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
33+
3334
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
3435
36+
3537
**Notes:**
3638
3739
#. Milliseconds are not supported by this RTC.
@@ -49,7 +51,42 @@
4951

5052
# pylint: disable-msg=too-few-public-methods
5153
class DS3231:
52-
"""Interface to the DS3231 RTC."""
54+
"""Interface to the DS3231 RTC.
55+
56+
:param ~busio.I2C i2c: The I2C bus the device is connected to
57+
58+
**Quickstart: Importing and using the device**
59+
60+
Here is an example of using the :class:`DS3231` class.
61+
First you will need to import the libraries to use the sensor
62+
63+
.. code-block:: python
64+
65+
import time
66+
import board
67+
import adafruit_ds3231
68+
69+
Once this is done you can define your `board.I2C` object and define your sensor object
70+
71+
.. code-block:: python
72+
73+
i2c = board.I2C() # uses board.SCL and board.SDA
74+
rtc = adafruit_ds3231.DS3231(i2c)
75+
76+
Now you can give the current time to the device.
77+
78+
.. code-block:: python
79+
80+
t = time.struct_time((2017, 10, 29, 15, 14, 15, 0, -1, -1))
81+
rtc.datetime = t
82+
83+
You can access the current time accessing the :attr:`datetime` attribute.
84+
85+
.. code-block:: python
86+
87+
current_time = rtc.datetime
88+
89+
"""
5390

5491
lost_power = i2c_bit.RWBit(0x0F, 7)
5592
"""True if the device has lost power since the time was set."""

docs/index.rst

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

26+
Adafruit DS3231 Precision RTC Breakout Learning Guide <https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout/>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/ds3231_simpletest.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,9 @@
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_ds3231
1912

20-
21-
i2c = io.I2C(board.SCL, board.SDA) # Change to the appropriate I2C clock & data
22-
# pins here!
23-
24-
# Create the RTC instance:
13+
i2c = board.I2C() # uses board.SCL and board.SDA
2514
rtc = adafruit_ds3231.DS3231(i2c)
2615

2716
# Lookup table for names of days (nicer printing).

0 commit comments

Comments
 (0)