Skip to content

Commit dae4b41

Browse files
authored
Merge pull request #5 from LysanderLi/master
add aht10&aht20 README
2 parents 19572da + 3b3c5c9 commit dae4b41

File tree

4 files changed

+354
-37
lines changed

4 files changed

+354
-37
lines changed

libraries/aht10/README.md

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,95 @@
1-
# aht10
1+
# AHT10 Temperature and Humidity Sensor Example Code Documentation
22

3-
**类引用:**
3+
## Overview
44

5-
```
6-
from aht10 import Aht10
5+
This document describes how to use the QuecPython-based AHT10 temperature and humidity sensor for environmental monitoring. The AHT10 is a high-precision digital sensor suitable for applications such as smart homes, weather monitoring, and industrial control systems.
6+
7+
## Hardware Connection
8+
9+
Ensure proper hardware connections before using the AHT10 module:
10+
11+
- I2C interface (SCL/SDA)
12+
- VCC connected to 3.3V power supply
13+
- GND grounded
14+
- Address selection pin (ADDR) left floating for default address 0x38
15+
16+
## Quick Start
17+
18+
### 1. Initialize AHT10 Module
19+
20+
```python
21+
from machine import I2C
22+
from drivers.aht10 import Aht10
23+
24+
# Initialize I2C interface (use actual I2C bus)
25+
i2c_obj = I2C(I2C.I2C1, I2C.FAST_MODE)
26+
# Initialize AHT10 sensor (default address 0x38)
27+
aht = Aht10(i2c_obj)
28+
print("AHT10 module initialized")
729
```
830

9-
31+
### 2. Basic Function Usage
1032

11-
**实例化参数:**
33+
#### Single Measurement Mode
1234

13-
| 名称 | 必填 | 类型 | 说明 |
14-
| ----- | ---- | ---- | ----------------------- |
15-
| addre || int | i2c从设备地址,默认0x38 |
35+
```python
36+
# Read temperature and humidity data
37+
humidity, temperature = aht.read()
38+
print(f'Current humidity: {humidity}%RH, temperature: {temperature}°C')
39+
```
40+
41+
#### Continuous Measurement Mode (with timing loop)
1642

1743
```python
18-
aht_dev=Aht10()
44+
import utime
45+
46+
while True:
47+
humidity, temperature = aht.read()
48+
print(f'Current humidity: {humidity}%RH, temperature: {temperature}°C')
49+
utime.sleep(2) # Read every 2 seconds
1950
```
2051

21-
**接口函数:**
52+
## Precautions
53+
54+
1. Ensure correct I2C wiring (avoid SCL/SDA reversal)
55+
2. Operating voltage: 3.3V ±0.1V
56+
3. Allow ≥15ms stabilization time before measurement
57+
4. Avoid extreme temperatures (-40~85°C) or humidity (>95%RH)
58+
59+
## Troubleshooting
2260

23-
l **read()**
61+
1. **Data Read Failure**:
62+
- Verify I2C connections
63+
- Check 3.3V power supply
64+
- Confirm I2C address (default 0x38)
65+
2. **Abnormal Readings**:
66+
- Shield from direct sunlight/heat sources
67+
- Ensure proper ventilation
68+
- Reset device to clear sensor state
2469

25-
​ 读取寄存器值转化成湿度和温度
70+
## API Reference
71+
72+
### Class Initialization
73+
74+
```
75+
class Aht10:
76+
def __init__(self, i2c, address=0x38):
77+
"""
78+
Initialize AHT10 sensor
79+
:param i2c: I2C object
80+
:param address: I2C slave address (default 0x38)
81+
"""
82+
```
2683

27-
参数:
84+
### Core Methods
2885

29-
​ 无。
86+
| Method Name | Parameters | Return Value | Description |
87+
| :--------------------: | :--------: | :---------------------------------: | :------------------------------------: |
88+
| read() | None | (humidity:float, temperature:float) | Get temperature/humidity data |
89+
| get_calibration_data() | None | dict | Retrieve sensor calibration parameters |
3090

31-
返回值:
91+
## Supplementary Information
3292

33-
| 名称 | 类型 | 说明 |
34-
| ---------------------- | ----- | ---------- |
35-
| (humidity,temperature) | tuple | 湿度,温度 |
93+
- Datasheet: `drivers/libraries/aht10/AHT10.pdf`
94+
- Example code: `drivers/libraries/aht10/aht10_demo.py`
95+
- [I2C Interface Reference](https://developer.quectel.com/doc/quecpython/API_reference/en/peripherals/machine.I2C.html)

libraries/aht10/README_zh.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# AHT10 温湿度传感器示例代码说明文档
2+
3+
## 概述
4+
5+
本文档介绍如何使用基于QuecPython的AHT10温湿度传感器进行环境温湿度测量。AHT10是一款高精度数字温湿度传感器,适用于智能家居、气象监测、工业控制等场景。
6+
7+
## 硬件连接
8+
9+
在使用AHT10模块前,请确保正确连接硬件:
10+
11+
- I2C接口连接(SCL/SDA)
12+
- VCC连接至3.3V电源
13+
- GND接地
14+
- 地址选择引脚(ADDR)悬空时默认地址为0x38
15+
16+
## 快速开始
17+
18+
### 1. 初始化AHT10模块
19+
20+
```python
21+
from machine import I2C
22+
from drivers.aht10 import Aht10
23+
24+
# 初始化I2C接口,使用实际的I2C接口
25+
i2c_obj = I2C(I2C.I2C1, I2C.FAST_MODE)
26+
# 初始化AHT10传感器(默认地址0x38)
27+
aht = Aht10(i2c_obj)
28+
print("AHT10模块初始化完成")
29+
```
30+
31+
### 2. 基本功能使用
32+
33+
#### 单次测量模式
34+
35+
```python
36+
# 读取温湿度数据
37+
humidity, temperature = aht.read()
38+
print('当前湿度: {0}%RH,温度: {1}'.format(humidity, temperature))
39+
```
40+
41+
#### 连续测量模式(需配合定时任务实现)
42+
43+
```python
44+
import utime
45+
46+
while True:
47+
humidity, temperature = aht.read()
48+
print('当前湿度: {0}%RH,温度: {1}'.format(humidity, temperature))
49+
utime.sleep(2) # 每2秒读取一次
50+
```
51+
52+
## 注意事项
53+
54+
1. 确保I2C接口连接正确,SCL和SDA线不要接反
55+
2. 传感器供电电压范围:3.3V±0.1V
56+
3. 测量前需等待至少15ms稳定时间
57+
4. 避免暴露在极端温度(-40~85℃)或高湿度(>95%RH)环境
58+
59+
## 故障排除
60+
61+
1. **无法读取数据**
62+
- 检查I2C连接是否正确
63+
- 确认传感器供电正常(3.3V)
64+
- 验证I2C地址是否正确(默认0x38)
65+
2. **测量值异常**
66+
- 检查传感器是否受阳光直射或热源干扰
67+
- 确保测量环境通风良好
68+
- 重启设备重置传感器状态
69+
70+
## API参考
71+
72+
### 类初始化
73+
74+
```python
75+
class Aht10:
76+
def __init__(self, i2c, address=0x38):
77+
"""
78+
初始化AHT10传感器
79+
:param i2c: I2C对象
80+
:param address: I2C从设备地址(默认0x38)
81+
"""
82+
```
83+
84+
### 核心方法
85+
86+
| 方法名 | 参数说明 | 返回值 | 功能描述 |
87+
| :--------------------: | :------: | :---------------------------------: | :----------------: |
88+
| read() || (humidity:float, temperature:float) | 获取温湿度数据 |
89+
| get_calibration_data() || dict | 获取传感器校准参数 |
90+
91+
## 补充说明
92+
93+
- 数据手册参考:`drivers/libraries/aht10/AHT10.pdf`
94+
- 示例代码路径:`drivers/libraries/aht10/aht10_demo.py`
95+
- [I2C接口参考](https://developer.quectel.com/doc/quecpython/API_reference/zh/peripherals/machine.I2C.html)

libraries/aht20/README.md

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,100 @@
1-
# aht20
1+
# AHT20 Temperature and Humidity Sensor Example Code Documentation
22

3-
**类引用:**
3+
## Overview
4+
5+
This document describes how to use the QuecPython-based AHT20 temperature and humidity sensor for environmental monitoring. The AHT20 is a high-precision digital sensor featuring ±2%RH humidity accuracy and ±0.2°C temperature accuracy, making it ideal for smart home, weather monitoring, and industrial control applications requiring high precision.
6+
7+
## Hardware Connection
8+
9+
Ensure proper hardware connections before using the AHT20 module:
10+
11+
- I2C interface (SCL/SDA)
12+
- VCC connected to 3.3V power supply
13+
- GND grounded
14+
- Address selection pin (ADDR) left floating for default address **0x38**
15+
16+
## Quick Start
17+
18+
### 1. Initialize AHT20 Module
419

520
```python
6-
from aht20 import Aht20
21+
from machine import I2C
22+
from drivers.aht20 import Aht20
23+
24+
# Initialize I2C interface (use actual I2C bus)
25+
i2c_obj = I2C(I2C.I2C1, I2C.FAST_MODE)
26+
# Initialize AHT20 sensor (default address 0x38)
27+
aht = Aht20(i2c_obj)
28+
print("AHT20 module initialized")
729
```
830

9-
31+
### 2. Basic Function Usage
32+
33+
#### Single Measurement Mode
1034

11-
**实例化参数:**
35+
```python
36+
# Read temperature and humidity data
37+
humidity, temperature = aht.read()
38+
print(f'Current humidity: {humidity}%RH, temperature: {temperature}°C')
39+
```
1240

13-
| 名称 | 必填 | 类型 | 说明 |
14-
| ----- | ---- | ---- | ----------------------- |
15-
| addre || int | i2c从设备地址,默认0x38 |
41+
#### Continuous Measurement Mode (with timing loop)
1642

1743
```python
18-
aht_dev=Aht20()
44+
import utime
45+
46+
while True:
47+
humidity, temperature = aht.read()
48+
print(f'Current humidity: {humidity}%RH, temperature: {temperature}°C')
49+
utime.sleep(2) # Read every 2 seconds
1950
```
2051

21-
**接口函数:**
52+
## Precautions
53+
54+
1. Ensure correct I2C wiring (avoid SCL/SDA reversal)
55+
2. Operating voltage: **3.3V ±0.1V**
56+
3. Allow ≥15ms stabilization time before measurement
57+
4. Avoid exposure to extreme temperatures (**-40~85°C**) or humidity (**>95%RH**)
58+
59+
## Troubleshooting
60+
61+
### 1. **Data Read Failure**
62+
63+
- Verify I2C connections
64+
- Check 3.3V power supply
65+
- Confirm I2C address (**default 0x38**)
66+
- Ensure `read()` method is called (initial measurement trigger required)
2267

23-
l **read()**
68+
### 2. **Abnormal Readings**
2469

25-
​ 读取寄存器值转化成湿度和温度
70+
- Shield from direct sunlight/heat sources
71+
- Ensure proper ventilation
72+
- Restart device to reset sensor state
73+
- Check against maximum range (**100%RH @ 85°C**)
74+
75+
## API Reference
76+
77+
### Class Initialization
78+
79+
```python
80+
class Aht20:
81+
def __init__(self, i2c, address=0x38):
82+
"""
83+
Initialize AHT20 sensor
84+
:param i2c: I2C object
85+
:param address: I2C slave address (default 0x38)
86+
"""
87+
```
2688

27-
参数:
89+
### Core Methods
2890

29-
​ 无。
91+
| Method Name | Parameters | Return Value | Description |
92+
| :----------------------: | :--------: | :-----------------------------------: | :------------------------------------: |
93+
| `read()` | None | `(humidity:float, temperature:float)` | Get temperature/humidity data |
94+
| `get_calibration_data()` | None | `dict` | Retrieve sensor calibration parameters |
3095

31-
返回值:
96+
## Supplementary Information
3297

33-
| 名称 | 类型 | 说明 |
34-
| ---------------------- | ----- | ---------- |
35-
| (humidity,temperature) | tuple | 湿度,温度 |
98+
- **Datasheet**: `drivers/libraries/aht20/AHT20-datasheet.pdf`
99+
- **Example Code**: `drivers/libraries/aht20/aht20_demo.py`
100+
- [I2C Interface Reference](https://developer.quectel.com/doc/quecpython/API_reference/en/peripherals/machine.I2C.html)

0 commit comments

Comments
 (0)