Skip to content

Commit 1ad3eb1

Browse files
committed
On branch aht20_update
Updated to v2.0.0. Supports thread safe I2C apis. Changes to be committed: modified: CHANGELOG.md modified: CMakeLists.txt modified: README.md modified: aht20.c modified: idf_component.yml modified: include/aht20.h deleted: priv_include/aht20_reg.h deleted: test_apps/CMakeLists.txt deleted: test_apps/main/CMakeLists.txt deleted: test_apps/main/Kconfig.projbuild deleted: test_apps/main/aht20_test.c deleted: test_apps/pytest_aht20.py deleted: test_apps/sdkconfig.defaults
1 parent fae0bd2 commit 1ad3eb1

File tree

13 files changed

+531
-398
lines changed

13 files changed

+531
-398
lines changed

components/sensors/humiture/aht20/CHANGELOG.md

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

3+
## v2.0.0 (2025-04-28
4+
5+
* Updated to use thread safe i2c api.
6+
37
## v1.0.0 (2024-08-09)
48

59
* Added description of AHT30
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
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})
2+
SRCS "aht20.c"
3+
INCLUDE_DIRS "include"
4+
REQUIRES "esp_driver_i2c" "esp_driver_gpio")
Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,91 @@
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+
│ esp-i2c-driver │
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_master_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+
76+
printf("tempertature = %uC humidity = %u \n", raw_value.temperature, raw_value.humidity);
2177
```
2278
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;
2879
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-
```
80+
# How to Configure CRC and I2C clock speed
81+
Additionaly, select in menuconfig under Component Config → AHT20,; to use CRC(default is not used)
82+
or change the clock speed of device (deault is 100KHz).
83+
84+
Note : It is recommended to use clock speeds in upper ranges of 100kHz to 200kHz.
85+
Higher clock speeds may cause occasional data inconsistencies depending on your board layout and wiring.
86+
87+
![image](https://github.com/user-attachments/assets/fc8680fb-1567-477c-92f8-52dd126e6f9d)
88+
89+
or
90+
In sdkconfig under Component Config → AHT20,
91+
![image](https://github.com/user-attachments/assets/1f9612df-8d73-4ad1-bec7-75cbe6ed327a)

0 commit comments

Comments
 (0)