Skip to content

Commit 20f01dc

Browse files
committed
docs: unit weight i2c API documents
1 parent 866f3f1 commit 20f01dc

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed

docs/en/refs/unit.weight_i2c.ref

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. |WEIGHT I2C| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/Unit-Weight%20I2C/img-0634712b-2a27-48cf-894f-d6708a771d47.webp
2+
:target: https://docs.m5stack.com/en/unit/Unit-Weight%20I2C
3+
:height: 200px
4+
:width: 200 px
5+
6+
.. |init_i2c_address.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/init.svg
7+
8+
.. |get_adc_raw.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_adc_raw.svg
9+
10+
.. |get_weight_float.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_weight_float.svg
11+
12+
.. |get_weight_int.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_weight_int.svg
13+
14+
.. |get_weight_str.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_weight_str.svg
15+
16+
.. |set_reset_offset.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_reset_offset.svg
17+
18+
.. |set_calibration.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_calibration.svg
19+
20+
.. |set_lowpass_filter.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_lowpass_filter.svg
21+
22+
.. |get_lowpass_filter.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_lowpass_filter.svg
23+
24+
.. |set_average_filter_level.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_average_filter_level.svg
25+
26+
.. |get_average_filter_level.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_average_filter_level.svg
27+
28+
.. |set_ema_filter_alpha.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_ema_filter_alpha.svg
29+
30+
.. |get_ema_filter_alpha.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_ema_filter_alpha.svg
31+
32+
.. |set_i2c_address.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/set_i2c_address.svg
33+
34+
.. |get_device_spec.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/get_device_spec.svg
35+
36+
.. |example.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/weight_i2c/example.svg

docs/en/units/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Unit
2121
op180.rst
2222
miniscale.rst
2323
dac2.rst
24+
weight_i2c.rst

docs/en/units/weight_i2c.rst

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
Weight I2C Unit
2+
===============
3+
4+
.. include:: ../refs/unit.weight_i2c.ref
5+
6+
The ``Weight I2C`` Unit is a weighing acquisition transmitter unit that adopts the "STM32+HX711 chip" solution to achieve 24-bit precision weight measurement through I2C communication and does not include a load cell sensor. This unit is capable of measuring weight and also includes various filters.
7+
8+
Support the following products:
9+
10+
11+
|WEIGHT I2C|
12+
13+
14+
15+
Micropython Example::
16+
17+
import os, sys, io
18+
import M5
19+
from M5 import *
20+
from hardware import *
21+
from unit import WEIGHT_I2CUnit
22+
import time
23+
24+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
25+
weight_i2c0 = WEIGHT_I2CUnit(i2c0)
26+
print(weight_i2c_0.get_adc_raw)
27+
print(weight_i2c_0.get_weight_float)
28+
time.sleep_ms(100)
29+
30+
31+
UIFLOW2 Example:
32+
33+
|example.svg|
34+
35+
36+
.. only:: builder_html
37+
38+
39+
class WEIGHT_I2CUnit
40+
--------------------
41+
42+
Constructors
43+
---------------------------
44+
45+
.. class:: WEIGHT_I2CUnit(i2c0, 0x26)
46+
47+
Create an WEIGHT_I2CUnit object.
48+
49+
- ``I2C0`` is I2C Port.
50+
- ``0x26`` is default I2C address
51+
52+
53+
UIFLOW2:
54+
55+
|init_i2c_address.svg|
56+
57+
58+
Methods
59+
----------------------
60+
61+
.. method:: WEIGHT_I2CUnit.get_adc_raw
62+
63+
64+
Gets the raw adc value.
65+
66+
UIFLOW2:
67+
68+
|get_adc_raw.svg|
69+
70+
.. method:: WEIGHT_I2CUnit.get_weight_float
71+
72+
73+
Gets the weight in grams float value.
74+
75+
UIFLOW2:
76+
77+
|get_weight_float.svg|
78+
79+
.. method:: WEIGHT_I2CUnit.get_weight_int
80+
81+
82+
Gets the weight in grams int value.
83+
84+
UIFLOW2:
85+
86+
|get_weight_int.svg|
87+
88+
.. method:: WEIGHT_I2CUnit.get_weight_str
89+
90+
91+
Gets the weight in grams string value.
92+
93+
UIFLOW2:
94+
95+
|get_weight_str.svg|
96+
97+
.. method:: WEIGHT_I2CUnit.set_reset_offset()
98+
99+
Reset the offset value(Tare).
100+
101+
102+
UIFLOW2:
103+
104+
|set_reset_offset.svg|
105+
106+
.. method:: WEIGHT_I2CUnit.set_calibration(weight1_g, weight1_adc, weight2_g, weight2_adc)
107+
108+
109+
Calibrates the Load sensor.
110+
111+
- ``weight1_g``: Weight1 in grams.
112+
- ``weight1_adc``: Weight1 in ADC value.
113+
- ``weight2_g``: Weight2 in grams.
114+
- ``weight2_adc``: Weight2 in ADC value.
115+
116+
calibration steps:
117+
118+
1.Reset offset(Tare).
119+
2.Get the raw ADC value at no-load weight, this is the Raw ADC of zero weight in 0g.
120+
3.Put some weight on it, then get adc, this is the load weight adc value and the gram weight you put on it.
121+
122+
123+
UIFLOW2:
124+
125+
|set_calibration.svg|
126+
127+
.. method:: WEIGHT_I2CUnit.set_lowpass_filter(Enable)
128+
129+
Enable or disable the low pass filter.
130+
131+
132+
UIFLOW2:
133+
134+
|set_lowpass_filter.svg|
135+
136+
137+
.. method:: WEIGHT_I2CUnit.get_lowpass_filter
138+
139+
Returns the status of the low pass filter (enable or disable).
140+
141+
142+
UIFLOW2:
143+
144+
|get_lowpass_filter.svg|
145+
146+
.. method:: WEIGHT_I2CUnit.set_average_filter_level(level)
147+
148+
Sets the level of the average filter.
149+
150+
- ``level``: Level of the average filter (0 - 50). Larger value for smoother result but more latency
151+
152+
UIFLOW2:
153+
154+
|set_average_filter_level.svg|
155+
156+
.. method:: WEIGHT_I2CUnit.get_average_filter_level
157+
158+
Returns the level of the average filter.
159+
160+
UIFLOW2:
161+
162+
|get_average_filter_level.svg|
163+
164+
.. method:: WEIGHT_I2CUnit.set_ema_filter_alpha(alpha)
165+
166+
Sets the alpha value for the EMA filter.
167+
168+
The EMA (Exponential Moving Average) filter is more sensitive to changes in data compared to the average filter.
169+
170+
- ``alpha``: Alpha value for the EMA filter (0 - 99). Smaller value for smoother result but more latency
171+
172+
UIFLOW2:
173+
174+
|set_ema_filter_alpha.svg|
175+
176+
.. method:: WEIGHT_I2CUnit.get_ema_filter_alpha
177+
178+
Returns the alpha value for the EMA filter.
179+
180+
UIFLOW2:
181+
182+
|get_ema_filter_alpha.svg|
183+
184+
.. method:: WEIGHT_I2CUnit.set_i2c_address(address)
185+
186+
The i2c address can be changed by the user and this address should be between 0x01 and 0x7F.
187+
188+
- ``address``: range of address(0x01 - 0x7F).
189+
190+
UIFLOW2:
191+
192+
|set_i2c_address.svg|
193+
194+
.. method:: WEIGHT_I2CUnit.get_device_spec(info)
195+
196+
Get the firmware version details and I2c address of this device.
197+
198+
- ``info``: (0xFE, 0xFF)
199+
200+
UIFLOW2:
201+
202+
|get_device_spec.svg|

0 commit comments

Comments
 (0)