Skip to content

Commit 308ee87

Browse files
author
luoweiyuan
committed
docs: Fix ENV pressure unit and add I2C guide.
Signed-off-by: luoweiyuan <luoweiyuan@m5stack.com> (cherry picked from commit 38560cb728be6c652f6a976ac4f549f1e80c17f7)
1 parent 7c01ea8 commit 308ee87

4 files changed

Lines changed: 91 additions & 4 deletions

File tree

docs/source/hardware/i2c.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
I2C
2+
===
3+
4+
I2C implements a two-wire serial bus using an SDA data line and an SCL clock line.
5+
Use it to communicate with Unit, Hat, and other I2C peripherals.
6+
7+
MicroPython Example
8+
-------------------
9+
10+
Scan PORT.A on a CoreS3 or most S3-based controllers.
11+
12+
.. code-block:: python
13+
14+
from hardware import I2C, Pin
15+
16+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
17+
print(i2c0.scan())
18+
19+
Scan PORT.A on Tough.
20+
21+
.. code-block:: python
22+
23+
from hardware import I2C, Pin
24+
25+
i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
26+
print(i2c0.scan())
27+
28+
**API**
29+
-------
30+
31+
class I2C
32+
^^^^^^^^^
33+
34+
.. _hardware.I2C:
35+
36+
.. class:: I2C(id, *, scl, sda, freq=400000)
37+
38+
Construct an I2C bus object.
39+
40+
:param int id: I2C peripheral id.
41+
:keyword scl: SCL clock pin.
42+
:type scl: Pin or int
43+
:keyword sda: SDA data pin.
44+
:type sda: Pin or int
45+
:keyword int freq: I2C bus frequency in Hz.
46+
47+
MicroPython Code Block:
48+
49+
.. code-block:: python
50+
51+
from hardware import I2C, Pin
52+
53+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
54+
55+
.. method:: I2C.scan()
56+
57+
Scan all I2C addresses between 0x08 and 0x77 and return a list of responding addresses.
58+
59+
MicroPython Code Block:
60+
61+
.. code-block:: python
62+
63+
print(i2c0.scan())
64+
65+
.. method:: I2C.readfrom_mem(addr, memaddr, nbytes, *, addrsize=8)
66+
67+
Read ``nbytes`` from a device register.
68+
69+
:param int addr: I2C device address.
70+
:param int memaddr: register address.
71+
:param int nbytes: number of bytes to read.
72+
:keyword int addrsize: register address size in bits.
73+
74+
.. method:: I2C.writeto_mem(addr, memaddr, buf, *, addrsize=8)
75+
76+
Write ``buf`` to a device register.
77+
78+
:param int addr: I2C device address.
79+
:param int memaddr: register address.
80+
:param bytes buf: bytes-like object to write.
81+
:keyword int addrsize: register address size in bits.

docs/source/hardware/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Hardware
1010
can.rst
1111
display.rst
1212
imu.rst
13+
i2c.rst
1314
ir.rst
1415
lora.rst
1516
mic.rst

docs/source/hat/env.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Methods
5656

5757
.. method:: ENVHat.read_temperature()
5858

59-
This method allows to read the temperature value collected by ENV and returns a floating point value. The hat of measurement is °C.
59+
This method allows to read the temperature value collected by ENV and returns a floating point value. The unit of measurement is °C.
6060

6161
UIFLOW2:
6262

@@ -65,7 +65,7 @@ Methods
6565

6666
.. method:: ENVHat.read_humidity()
6767

68-
This method allows to read the relative humidity value collected by ENV and returns a floating point value. The hat of measurement is %RH.
68+
This method allows to read the relative humidity value collected by ENV and returns a floating point value. The unit of measurement is %RH.
6969

7070
UIFLOW2:
7171

@@ -74,7 +74,7 @@ Methods
7474

7575
.. method:: ENVHat.read_pressure()
7676

77-
This method allows to read the atmospheric pressure collected by ENV and returns a floating point value. The hat of measurement is Pa.
77+
This method allows to read the atmospheric pressure collected by ENV and returns a floating point value. The unit of measurement is hPa.
7878

7979
UIFLOW2:
8080

docs/source/unit/env.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ Micropython Example::
1414

1515
import M5
1616
from M5 import *
17+
from hardware import I2C, Pin
1718
from unit import *
1819

1920
M5.begin()
2021

22+
# PORT.A on CoreS3 and most S3-based controllers.
2123
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
2224

25+
# PORT.A on Tough.
26+
# i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
27+
2328
env_0 = ENVUnit(i2c=i2c0, type=1) # ENVUnit
2429
env2_0 = ENVUnit(i2c=i2c0, type=2) # ENVUnit II
2530
env3_0 = ENVUnit(i2c=i2c0, type=3) # ENVUnit III
@@ -85,7 +90,7 @@ Methods
8590

8691
.. method:: ENVUnit.read_pressure()
8792

88-
This method allows to read the atmospheric pressure collected by ENV and returns a floating point value. The unit of measurement is Pa.
93+
This method allows to read the atmospheric pressure collected by ENV and returns a floating point value. The unit of measurement is hPa.
8994

9095
UIFLOW2:
9196

0 commit comments

Comments
 (0)