Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/sensors/humiture/aht20/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog

## v1.1.1 (2025-05-02)
* replace the i2c interface with i2c_bus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Replace the i2c interface with i2c_bus

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


## v1.0.0 (2024-08-09)

* Added description of AHT30
Expand Down
11 changes: 2 additions & 9 deletions components/sensors/humiture/aht20/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
idf_component_register(
SRCS "aht20.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES "driver"
)

include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
idf_component_register(SRCS "aht20.c"
INCLUDE_DIRS "include")
18 changes: 18 additions & 0 deletions components/sensors/humiture/aht20/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
menu "AHT20 : CONFIGURATION"

config AHT20_CHECK_CRC
bool "perform crc check on AHT20 readings"
help
CRC check to be performed on results or not?.
default n


config AHT20_I2C_CLK_SPEED
int "I2C clock speed"
default 100000
range 1 400000
help
Clock speed used for i2c communication by AHT20 device.
Limited to maximum of 400KHZ.

endmenu
102 changes: 80 additions & 22 deletions components/sensors/humiture/aht20/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,90 @@
[![Component Registry](https://components.espressif.com/components/espressif/aht20/badge.svg)](https://components.espressif.com/components/espressif/aht20)
# aht20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, no modifications are needed at this point.

Suggested change
# aht20
[![Component Registry](https://components.espressif.com/components/espressif/aht20/badge.svg)](https://components.espressif.com/components/espressif/aht20)
# Component: AHT20

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

I2C driver for Aosong AHT20 humidity and temperature sensor using esp-idf.
Tested with AHT20 using ESP32 and ESP32-S3 devkits.

# Component: AHT20
I2C driver and definition of AHT20 humidity and temperature sensor.
# Features

Components compatible with AHT30 and AHT21 (AHT21 is deprecated).
Temperature and humidity measurement

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

CRC checksum verification (optional via menuconfig)

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

### Initialization
> Note: Note: You need to initialize the I2C bus first.
Unit tested


┌───────────────────┐
│ Application │
└────────┬──────────┘
┌───────────────────┐
│ AHT20 Driver │
│ (this component) │
└────────┬──────────┘
┌───────────────────┐
│ i2c_bus component │
└────────┬──────────┘
┌───────────────────┐
│ I2C Bus │
└────────┬──────────┘
┌────────────────────────────┐
│ AHT20 Temperature/Humidity │
│ Sensor │
└────────────────────────────┘



# How To Use

This driver includes a demo example project.

Follow the example to learn how to initialize the driver and read the sensor data.

All public APIs are documented in aht20.h.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the indentation means here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.




However, following are the general guiedlines.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However indicates a contrast, but I don't think there's any inconsistency between the preceding and following parts. Perhaps Next would be more appropriate.

Copy link
Author

@jeetrohan jeetrohan May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.
However, I would like to inform you that..
It was perfectly right to use 'however' in above context... because it not always represents inconsistency.
It is also used for adding a comment to what have been just said, although something is true.

It was supposed to reflect that .... although the user should follow the example.. but for those who don't want to.. here are basic guidelines.

```c
aht20_i2c_config_t i2c_conf = {
.i2c_port = I2C_MASTER_NUM,
.i2c_addr = AHT20_ADDRRES_0,
};
aht20_new_sensor(&i2c_conf, &handle);
//create a AHT20 device object and receive a device handle for it
// my_i2c_bus_handle is a preintialized i2c_bus_handle_t object
aht20_handle_t aht20_handle = aht20_create( my_i2c_bus_handle, AHT20_ADDRESS_LOW ); //addresses are in aht.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aht20_handle_t aht20_handle = aht20_create( my_i2c_bus_handle, AHT20_ADDRESS_LOW ); //addresses are in aht.h
aht20_handle_t aht20_handle = aht20_create( my_i2c_bus_handle, AHT20_ADDRESS_LOW ); //addresses are in aht20.h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


//use the previously created AHT20 device handle for initializing the associated device
aht20_init(aht20_handle);

//read both humidity and temperature at once from device, using AHT20 device handle
aht20_read_humiture(aht20_handle); //Other public APIs are documented in AHT20.h.

//access the results stored in AHT20 device object, using the AHT20 device handle
//other apis require user to explicitly pass variable address to hold data
printf("tempertature = %.2fC humidity = %.3f \n", aht20_handle->humiture.temperature, aht20_handle->humiture.humidity);

//to get reaw values create a object of following data type
aht20_raw_reading_t raw_value;
aht20_read_raw( aht20_handle, &raw_value);
printf("tempertature = %uC humidity = %u \n", raw_value.temperature, raw_value.humidity);
```

### Read data
> The user can periodically call the aht20_read_temp_hum API to retrieve real-time data.
```c
uint32_t temp_raw, hum_raw;
float temp, hum;

aht20_read_temp_hum(aht20, &temp_raw, &temp, &hum_raw, &hum);
ESP_LOGI(TAG, "Humidity : %2.2f %%", hum);
ESP_LOGI(TAG, "Temperature : %2.2f degC", temp);
```
# How to Configure CRC and I2C clock speed
Additionally, select in menuconfig under Component Config → AHT20,; to use CRC(default is not used)
or change the clock speed of device (default is 100KHz).

Note : It is recommended to use clock speeds in upper ranges of 100kHz to 200kHz.
Higher clock speeds may cause occasional data inconsistencies depending on your board layout and wiring.

![image](https://github.com/user-attachments/assets/fc8680fb-1567-477c-92f8-52dd126e6f9d)

or
In sdkconfig under Component Config → AHT20,
![image](https://github.com/user-attachments/assets/1f9612df-8d73-4ad1-bec7-75cbe6ed327a)
Loading