Skip to content

Commit 378c8c8

Browse files
committed
feat(aht20): update to v1.1.0 with internal i2c_bus and new sensor APIs
Bumped driver version from 1.0.0 to 1.1.0. Switched to internal i2c_bus component from esp-iot-solution, replacing legacy I2C code. Added new APIs to retrieve temperature and humidity. Introduced Kconfig options for CRC check and I2C clock frequency configuration. Updated README to reflect new APIs and configuration options. Changes to be committed: modified: CHANGELOG.md modified: CMakeLists.txt new file: Kconfig modified: README.md modified: aht20.c modified: idf_component.yml modified: include/aht20.h
1 parent fae0bd2 commit 378c8c8

File tree

7 files changed

+566
-205
lines changed

7 files changed

+566
-205
lines changed

components/sensors/humiture/aht20/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ChangeLog
22

3+
## v1.1.1 (2025-05-02)
4+
* replace the i2c interface with i2c_bus
5+
36
## v1.0.0 (2024-08-09)
47

58
* Added description of AHT30
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
idf_component_register(
2-
SRCS "aht20.c"
3-
INCLUDE_DIRS "include"
4-
PRIV_INCLUDE_DIRS "priv_include"
5-
REQUIRES "driver"
6-
)
7-
8-
include(package_manager)
9-
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
1+
idf_component_register(SRCS "aht20.c"
2+
INCLUDE_DIRS "include")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
menu "AHT20 : CONFIGURATION"
2+
3+
config AHT20_CHECK_CRC
4+
bool "perform crc check on AHT20 readings"
5+
help
6+
CRC check to be performed on results or not?.
7+
default n
8+
9+
10+
config AHT20_I2C_CLK_SPEED
11+
int "I2C clock speed"
12+
default 100000
13+
range 1 400000
14+
help
15+
Clock speed used for i2c communication by AHT20 device.
16+
Limited to maximum of 400KHZ.
17+
18+
endmenu
Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,90 @@
1-
[![Component Registry](https://components.espressif.com/components/espressif/aht20/badge.svg)](https://components.espressif.com/components/espressif/aht20)
1+
# aht20
2+
I2C driver for Aosong AHT20 humidity and temperature sensor using esp-idf.
3+
Tested with AHT20 using ESP32 and ESP32-S3 devkits.
24

3-
# Component: AHT20
4-
I2C driver and definition of AHT20 humidity and temperature sensor.
5+
# Features
56

6-
Components compatible with AHT30 and AHT21 (AHT21 is deprecated).
7+
Temperature and humidity measurement
78

8-
See [AHT20 datasheet](http://www.aosong.com/en/products-32.html), [AHT30 datasheet](http://www.aosong.com/en/products-131.html).
9+
Thread-safe via esp-i2c-driver
910

11+
CRC checksum verification (optional via menuconfig)
1012

11-
## Usage
13+
Configurable I2C clock speed (pre-compilation, not runtime,via menuconfig))
1214

13-
### Initialization
14-
> Note: Note: You need to initialize the I2C bus first.
15+
Unit tested
16+
17+
18+
┌───────────────────┐
19+
│ Application │
20+
└────────┬──────────┘
21+
22+
23+
┌───────────────────┐
24+
│ AHT20 Driver │
25+
│ (this component) │
26+
└────────┬──────────┘
27+
28+
29+
┌───────────────────┐
30+
│ i2c_bus component │
31+
└────────┬──────────┘
32+
33+
34+
┌───────────────────┐
35+
│ I2C Bus │
36+
└────────┬──────────┘
37+
38+
39+
┌────────────────────────────┐
40+
│ AHT20 Temperature/Humidity │
41+
│ Sensor │
42+
└────────────────────────────┘
43+
44+
45+
46+
# How To Use
47+
48+
This driver includes a demo example project.
49+
50+
Follow the example to learn how to initialize the driver and read the sensor data.
51+
52+
All public APIs are documented in aht20.h.
53+
54+
55+
56+
However, following are the general guiedlines.
1557
```c
16-
aht20_i2c_config_t i2c_conf = {
17-
.i2c_port = I2C_MASTER_NUM,
18-
.i2c_addr = AHT20_ADDRRES_0,
19-
};
20-
aht20_new_sensor(&i2c_conf, &handle);
58+
//create a AHT20 device object and receive a device handle for it
59+
// my_i2c_bus_handle is a preintialized i2c_bus_handle_t object
60+
aht20_handle_t aht20_handle = aht20_create( my_i2c_bus_handle, AHT20_ADDRESS_LOW ); //addresses are in aht.h
61+
62+
//use the previously created AHT20 device handle for initializing the associated device
63+
aht20_init(aht20_handle);
64+
65+
//read both humidity and temperature at once from device, using AHT20 device handle
66+
aht20_read_humiture(aht20_handle); //Other public APIs are documented in AHT20.h.
67+
68+
//access the results stored in AHT20 device object, using the AHT20 device handle
69+
//other apis require user to explicitly pass variable address to hold data
70+
printf("tempertature = %.2fC humidity = %.3f \n", aht20_handle->humiture.temperature, aht20_handle->humiture.humidity);
71+
72+
//to get reaw values create a object of following data type
73+
aht20_raw_reading_t raw_value;
74+
aht20_read_raw( aht20_handle, &raw_value);
75+
printf("tempertature = %uC humidity = %u \n", raw_value.temperature, raw_value.humidity);
2176
```
2277
23-
### Read data
24-
> The user can periodically call the aht20_read_temp_hum API to retrieve real-time data.
25-
```c
26-
uint32_t temp_raw, hum_raw;
27-
float temp, hum;
2878
29-
aht20_read_temp_hum(aht20, &temp_raw, &temp, &hum_raw, &hum);
30-
ESP_LOGI(TAG, "Humidity : %2.2f %%", hum);
31-
ESP_LOGI(TAG, "Temperature : %2.2f degC", temp);
32-
```
79+
# How to Configure CRC and I2C clock speed
80+
Additionally, select in menuconfig under Component Config → AHT20,; to use CRC(default is not used)
81+
or change the clock speed of device (default is 100KHz).
82+
83+
Note : It is recommended to use clock speeds in upper ranges of 100kHz to 200kHz.
84+
Higher clock speeds may cause occasional data inconsistencies depending on your board layout and wiring.
85+
86+
![image](https://github.com/user-attachments/assets/fc8680fb-1567-477c-92f8-52dd126e6f9d)
87+
88+
or
89+
In sdkconfig under Component Config → AHT20,
90+
![image](https://github.com/user-attachments/assets/1f9612df-8d73-4ad1-bec7-75cbe6ed327a)

0 commit comments

Comments
 (0)