Skip to content

Commit a12a680

Browse files
committed
Updated README.rst
1 parent 2bfed3c commit a12a680

File tree

2 files changed

+131
-4
lines changed

2 files changed

+131
-4
lines changed

3295-00.jpg

232 KB
Loading

README.rst

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,133 @@
1-
Adafruit uRTC Library
2-
*********************
31

4-
A MicroPython library for interfacing with various real-time clock modules.
2+
Introduction to Adafruit's PCF8523 Real Time Clock (RTC) Library
3+
================================================================
54

6-
For full documentation see http://micropython-urtc.rtfd.io/.
5+
This is a great battery-backed real time clock (RTC) that allows your
6+
microcontroller project to keep track of time even if it is reprogrammed,
7+
or if the power is lost. Perfect for datalogging, clock-building, time
8+
stamping, timers and alarms, etc. Equipped with PCF8523 RTC - it can
9+
run from 3.3V or 5V power & logic!
10+
11+
The PCF8523 is simple and inexpensive but not a high precision device.
12+
It may lose or gain up to two seconds a day. For a high-precision,
13+
temperature compensated alternative, please check out the
14+
`DS3231 precision RTC. <https://www.adafruit.com/products/3013>`_
15+
If you need a DS1307 for compatibility reasons, check out our
16+
`DS1307 RTC breakout <https://www.adafruit.com/products/3296>`_.
17+
18+
.. image:: 3295-00.jpg
19+
20+
Implementation Details
21+
=======================
22+
23+
Background
24+
----------
25+
26+
This page contains the details of the functions, classes, and methods
27+
available in the PCF8523 library.
28+
29+
The DS3231 library consists of three major sections:
30+
31+
#. Functions
32+
#. The base class _BaseRTC
33+
#. The subclass PCF8523
34+
35+
Functions
36+
---------
37+
38+
The only library functions of which you need to be aware of for the
39+
PCF8523 are datetime_tuple() and alarm_tuple().
40+
41+
The first is the function that creates an object
42+
you use to set the clock time. It takes eight arguments and returns a
43+
datetimetuple object containing the new time settings. The arguments are
44+
positional rather than keyword arguments. They are, in order:
45+
46+
* Year (4-digit)
47+
* Month (2-digit)
48+
* Day of the month (2-digit)
49+
* Day of the week (1 digit, 0 = Sunday)
50+
* Hour (24 hour clock, 2-digit)
51+
* Minute (2-digit)
52+
* Seconds (2-digits)
53+
* The digit 0 (representing milliseconds, which are not supported by this RTC)
54+
55+
The second is the function that returns an alarmtuple structure to set the
56+
alarm on the RTC. It takes four arguments:
57+
58+
* Day of the week
59+
* Day of the month
60+
* hour
61+
* minute
62+
63+
See the section, below, on usage for examples.
64+
65+
Class Methods
66+
-------------
67+
68+
Here are the important class methods for you to know:
69+
70+
* datetime() - sets or returns the RTC clock time
71+
* alarm_time() - sets or returns the current alarm setting
72+
* _register() - returns the contents of a register in the RTC chip
73+
* stop() - suspends RTC operation or, if the argument is None, returns the
74+
current setting.
75+
* lost_power() - returns true or false depending on whether the board has
76+
lost power. Passing the value "False" will reset the flag.
77+
* alarm() - returns the alarm state (True or False). Passing False as the
78+
argument will reset the flag.
79+
* battery_low() - returns True if the battery voltage is low (i.e., the battery
80+
needs to be replaced)
81+
82+
Usage Notes
83+
===========
84+
85+
Of course, you must import the library to use it:
86+
87+
import machine
88+
89+
import adafruit_pcf8523
90+
91+
All the Adafruit RTC libraries take an instantiated and active I2C object
92+
(from the machine library) as an argument to their constructor. The way to
93+
create an I2C object depends on the board you are using. If you are using the
94+
ATSAMD21-based board, like the Feather M0, you **must** initialize the object
95+
after you create it:
96+
97+
myI2C = machine.I2C(machine.Pin('SCL'), machine.Pin('SDA'))
98+
99+
myI2C.init()
100+
101+
If you are using the ESP8266-based boards, however, you do not need to
102+
init() the object after creating it:
103+
104+
myI2C = machine.I2C(machine.Pin(5), machine.Pin(4))
105+
106+
Once you have created the I2C interface object, you can use it to instantiate
107+
the RTC object:
108+
109+
rtc = adafruit_pcf8523.PCF8523(myI2C)
110+
111+
To set the time, you need to pass datetime() a datetimetuple object:
112+
113+
newTime = adafruit_pcf8523.datetime_tuple(2016,11,18,6,9,36,0,0)
114+
115+
rtc.datetime(newTime)
116+
117+
After the RTC is set, you retrieve the time by calling the datetime() method
118+
without any arguments.
119+
120+
curTime = rtc.datetime()
121+
122+
The PCF8523 supports an alarm function. You set the alarm very similarly to
123+
the way you set the datetime.
124+
125+
newAlarm = adafruit_pcf8523.alarm_tuple(6,18,10,41)
126+
127+
rtc.alarm_time(newAlarm)
128+
129+
Also, the PCF89523 is the only RTC from Adafruit that has a low battery
130+
detection. The battery_low() method returns True if the battery needs to be
131+
replaced. The only way to clear the flag is to replace the CR1220 battery.
132+
133+
Many more details can be found in the Docs/_build directory.

0 commit comments

Comments
 (0)