Skip to content

Commit 51c66f2

Browse files
update docs of DS1307
1 parent 3bd23ae commit 51c66f2

File tree

5 files changed

+120
-26
lines changed

5 files changed

+120
-26
lines changed

docs/DOCUMENTATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Documentation is generated by using Sphinx and published on RTD
88

99
Documentation is automatically created on each merge to the development
1010
branch, as well as with each pull request and available
11-
[📚 here at Read the Docs][ref-rtd-micropython-package-template]
11+
[📚 here at Read the Docs][ref-rtd-micropython-ds1307]
1212

1313
### Install required packages
1414

@@ -37,4 +37,4 @@ sphinx-build docs/ docs/build/html/ -d docs/build/docs_doctree/ --color -bhtml -
3737
The created documentation can be found at `docs/build/html`.
3838

3939
<!-- Links -->
40-
[ref-rtd-micropython-package-template]: https://micropython-package-template.readthedocs.io/en/latest/
40+
[ref-rtd-micropython-ds1307]: https://micropython-ds1307.readthedocs.io/en/latest/

docs/EXAMPLES.md

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,110 @@
11
# Examples
22

3-
Usage examples of this `micropython-package-template` library
3+
Usage examples of this `micropython-ds1307` library
44

55
---------------
66

7-
## TBD
7+
## General
88

9-
Some text with *italic*, **bold** and `hightlighted` words.
9+
An example of all implemented functionalities can be found at the
10+
[MicroPython DS1307 examples folder][ref-micropython-ds1307-examples]
1011

11-
```{note}
12-
A reStructuredText highlighted note
12+
## Setup DS1307
13+
14+
```python
15+
from eeprom import DS1307
16+
from machine import I2C, Pin
17+
18+
I2C_ADDR = 0x68
19+
20+
# define custom I2C interface, default is 'I2C(0)'
21+
# check the docs of your device for further details and pin infos
22+
# this are the pins for the Raspberry Pi Pico adapter board
23+
i2c = I2C(0, scl=Pin(13), sda=Pin(12), freq=800000)
24+
ds1307 = DS1307(addr=I2C_ADDR, i2c=i2c) # DS1307 on 0x68
25+
26+
# get LCD infos/properties
27+
print("DS1307 is on I2C address 0x{0:02x}".format(ds1307.addr))
28+
print("Weekday start is {}".format(ds1307.weekday_start))
1329
```
1430

15-
```{eval-rst}
16-
.. warning::
17-
Some eval warning
31+
## Set time
32+
33+
Set the RTC time to the current system time
34+
35+
```python
36+
from time import gmtime, time
37+
38+
now = gmtime(time())
39+
ds1307.datetime = now
1840
```
1941

42+
## Get time
43+
44+
Get the current RTC time and all available properties of `DS1307`
45+
2046
```python
21-
def hello_world():
22-
print('Hello')
47+
# Print the date and time in ISO8601 format: 2023-04-18T21:14:22
48+
print("Today is {:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}".format(
49+
ds1307.year, ds1307.month, ds1307.day,
50+
ds1307.hour, ds1307.minute, ds1307.second))
51+
52+
# check whether this year is a leap year
53+
print("Is this year a leap year? {}".format(ds1307.is_leap_year(ds1307.year)))
54+
55+
# get the day of the year
56+
print("Today is day {} of {}".format(
57+
ds1307.day_of_year(year=ds1307.year, month=ds1307.month, day=ds1307.day),
58+
ds1307.year))
59+
```
60+
61+
## Oscillator
62+
63+
Interact with the oscillator of the RTC
64+
65+
```python
66+
from time import sleep
67+
68+
print("The oscillator is currently active at {}? {}".format(
69+
ds1307.datetime, ds1307.halt))
70+
print("Halt the oscillator and wait for 5 seconds ...")
71+
ds1307.halt = True
72+
sleep(5)
73+
74+
print("Current RTC time: {}".format(ds1307.datetime))
75+
76+
print("Enable the oscillator and wait for 5 seconds ...")
77+
ds1307.halt = False
78+
sleep(5)
79+
print("Current RTC time: {}".format(ds1307.datetime))
80+
```
81+
82+
## Square Wave Pin
83+
84+
Control the squarewave pin `SQ`
85+
86+
```python
87+
from time import sleep
88+
89+
print("Set square wave output to 1Hz and wait for 5 seconds ...")
90+
ds1307.square_wave(sqw=1)
91+
sleep(5)
92+
93+
print("Set square wave output to 4.096kHz and wait for 5 seconds ...")
94+
ds1307.square_wave(sqw=4)
95+
sleep(5)
96+
97+
print("Set square wave output to 8.192kHz and wait for 5 seconds ...")
98+
ds1307.square_wave(sqw=8)
99+
sleep(5)
100+
101+
print("Set square wave output to HIGH and wait for 5 seconds ...")
102+
ds1307.square_wave(out=1)
103+
sleep(5)
104+
105+
print("Set square wave output to LOW and wait for 5 seconds ...")
106+
ds1307.square_wave(sqw=0)
107+
sleep(5)
23108
```
24109

25-
| Type | Individual | Prefered food |
26-
| ----- | ---------- | ------------- |
27-
| Car | E-Power | Electricity |
28-
| Animal | Cat | Mice |
110+
[ref-micropython-ds1307-examples]: https://github.com/brainelectronics/micropython-ds1307/tree/main/examples

docs/conf.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@
2121
to_be_mocked = [
2222
'micropython',
2323
'machine',
24-
'time.sleep_ms', 'time.sleep_us',
2524
]
2625
for module in to_be_mocked:
2726
sys.modules[module] = Mock()
2827
print("Mocked '{}' module".format(module))
2928

30-
import be_upy_blink
29+
import ds1307
3130
except ImportError:
32-
raise SystemExit("be_upy_blink has to be importable")
31+
raise SystemExit("ds1307 has to be importable")
3332

3433
# load elements of version.py
35-
exec(open(here / '..' / 'be_upy_blink' / 'version.py').read())
34+
exec(open(here / '..' / 'ds1307' / 'version.py').read())
3635

3736
# -- Project information
3837

39-
project = 'micropython-package-template'
38+
project = 'micropython-ds1307'
4039
copyright = '2023, brainelectronics'
4140
author = 'brainelectronics'
4241

@@ -78,10 +77,10 @@
7877
# A list of regular expressions that match URIs that should not be checked
7978
# when doing a linkcheck build.
8079
linkcheck_ignore = [
81-
# tag 0.4.0 did not exist during docs introduction
82-
'https://github.com/brainelectronics/micropython-package-template/tree/0.4.0',
80+
# tag 0.1.0 did not exist during docs introduction
81+
'https://github.com/brainelectronics/micropython-ds1307/tree/0.1.0',
8382
# RTD page did not exist during docs introduction
84-
'https://micropython-package-template.readthedocs.io/en/latest/',
83+
'https://micropython-ds1307.readthedocs.io/en/latest/',
8584
]
8685

8786
templates_path = ['_templates']

docs/ds1307.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
API
2+
=======================
3+
4+
.. autosummary::
5+
:toctree: generated
6+
7+
DS1307
8+
---------------------------------
9+
10+
.. automodule:: ds1307.ds1307
11+
:members:
12+
:private-members:
13+
:show-inheritance:

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MicroPython package template
1+
MicroPython DS1307
22
===================================
33

44
Contents
@@ -11,7 +11,7 @@ Contents
1111
EXAMPLES
1212
DOCUMENTATION
1313
CONTRIBUTING
14-
be_upy_blink
14+
ds1307
1515
changelog_link
1616

1717
Indices and tables

0 commit comments

Comments
 (0)