-
Notifications
You must be signed in to change notification settings - Fork 925
Updated aht20 driver to use thread safe api from idf>=5.4. (AEGHB-1062) #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeetrohan
wants to merge
13
commits into
espressif:master
Choose a base branch
from
jeetrohan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
378c8c8
feat(aht20): update to v1.1.0 with internal i2c_bus and new sensor APIs
jeetrohan 3719c16
test(aht20): update test app for new driver APIs and configurations
jeetrohan 3e4c618
feat(aht20): add demo showcasing updated driver features
jeetrohan 4f076d7
fix(aht20): fixed minor changes
jeetrohan 75b9060
feat(aht20): add Sensor Hub support, new test app, and example
jeetrohan e216318
docs(aht20): improve documentation and update changelog
jeetrohan 57caca2
refactor(aht20): update to use i2c_bus, add Kconfig options, bump to…
jeetrohan f97e3c8
Merge branch 'espressif:master' into master
jeetrohan fd72df9
Merge branch 'espressif:master' into update_aht20
jeetrohan e9727a7
refactor(aht20): remove I2C clock Kconfig option and encapsulate se…
jeetrohan da70eb5
Merge branch 'espressif:master' into update_aht20
jeetrohan addf33f
megre (aht20): Merge branch 'e-update_aht20' into update_aht20
jeetrohan 22cd170
Merge branch 'update_aht20'
jeetrohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| idf_component_register( | ||
| SRCS "aht20.c" | ||
| INCLUDE_DIRS "include" | ||
| PRIV_INCLUDE_DIRS "priv_include" | ||
| REQUIRES "driver" | ||
| ) | ||
| idf_component_register(SRCS "aht20.c" | ||
| INCLUDE_DIRS "include") | ||
|
|
||
|
|
||
| if(CONFIG_SENSOR_INCLUDED_HUMITURE) | ||
| target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_aht20_init") | ||
| endif() | ||
|
|
||
| include(package_manager) | ||
| cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,103 @@ | ||
| [](https://components.espressif.com/components/espressif/aht20) | ||
|
|
||
| # Component: AHT20 | ||
| I2C driver and definition of AHT20 humidity and temperature sensor. | ||
| I2C driver with Sensor Hub support for Aosong AHT20 humidity and temperature sensor using esp-idf. | ||
| Tested with AHT20 using ESP32 and ESP32-S3 devkits. | ||
|
|
||
| # Features | ||
|
|
||
| Temperature and humidity measurement | ||
|
|
||
| Thread-safe via esp-i2c-driver | ||
|
|
||
| CRC checksum verification (optional, only via menuconfig) | ||
|
|
||
| Configurable I2C clock speed (pre-compilation, not runtime, only via menuconfig) | ||
|
|
||
| Components compatible with AHT30 and AHT21 (AHT21 is deprecated). | ||
| Unit tested | ||
|
|
||
|
|
||
| ┌───────────────────┐ | ||
| │ Application │ | ||
| └────────┬──────────┘ | ||
| │ | ||
| ▼ | ||
| ┌───────────────────┐ | ||
| │ AHT20 Driver │ | ||
| │ (this component) │ | ||
| └────────┬──────────┘ | ||
| │ | ||
| ▼ | ||
| ┌───────────────────┐ | ||
| │ i2c_bus component │ | ||
| └────────┬──────────┘ | ||
| │ | ||
| ▼ | ||
| ┌───────────────────┐ | ||
| │ I2C Bus │ | ||
| └────────┬──────────┘ | ||
| │ | ||
| ▼ | ||
| ┌────────────────────────────┐ | ||
| │ AHT20 Temperature/Humidity │ | ||
| │ Sensor │ | ||
| └────────────────────────────┘ | ||
|
|
||
| See [AHT20 datasheet](http://www.aosong.com/en/products-32.html), [AHT30 datasheet](http://www.aosong.com/en/products-131.html). | ||
|
|
||
|
|
||
| ## Usage | ||
| # How To Use | ||
|
|
||
| ### Initialization | ||
| > Note: Note: You need to initialize the I2C bus first. | ||
| All public APIs are documented in aht20.h. | ||
|
|
||
| ## Driver | ||
|
|
||
| Following are the general 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 here is a preintialized i2c_bus_handle_t i2c_bus object | ||
| aht20_handle_t aht20_handle = aht20_create( my_i2c_bus_handle, AHT20_ADDRESS_LOW ); //addresses are in aht20.h | ||
|
|
||
| //use the previously created AHT20 device handle for initializing the AHT20 | ||
| aht20_init(aht20_handle); | ||
|
|
||
| float_t temperature; | ||
|
|
||
| aht20_read_temperature( aht20_handle, &temperature); | ||
|
|
||
| printf("Temperature = %.2f°C\n", temperature); | ||
|
|
||
| vTaskDelay(pdMS_TO_TICKS(2000)); | ||
|
|
||
| float_t temperature; | ||
|
|
||
| aht20_read_temperature( aht20_handle, &temperature); | ||
|
|
||
| printf("Temperature = %.2f°C\n", temperature); | ||
| ``` | ||
|
|
||
| ### 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; | ||
| ## Senosr Hub | ||
|
|
||
| Following are the general guidelines. | ||
| ``` | ||
|
|
||
| /*create a sensor with specific sensor_id and configurations*/ | ||
| iot_sensor_create("aht20", &sensor_config, &sensor_handle); | ||
|
|
||
| /*register handler with sensor's handle*/ | ||
| iot_sensor_handler_register(sensor_handle, sensor_event_handler, NULL); | ||
|
|
||
| /*start the sensor, data ready events will be posted once data is acquired successfully*/ | ||
| iot_sensor_start(sensor_handle); | ||
|
|
||
| ``` | ||
|
|
||
| ## 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. | ||
|
|
||
|  | ||
jeetrohan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| ``` | ||
| or | ||
| In sdkconfig under Component Config → AHT20, | ||
|  | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.