aht: Driver for AHT10/AHT15/AHT20 temperature and humidity sensor
Defines
- AHT_I2C_ADDRESS_GND
Device address when ADDR pin connected to GND.
- AHT_I2C_ADDRESS_VCC
Device address when ADDR pin connected to VCC.
Enums
- enum aht_type_t
Device types.
Values:
- enumerator AHT_TYPE_AHT1x
AHT10, AHT15.
- enumerator AHT_TYPE_AHT20
AHT20.
- enum aht_mode_t
Device modes.
- Deprecated:
The sensor modes are not supported by the driver: it always triggers a measurement in the command mode. The field is kept for the source compatibility only.
Values:
- enumerator AHT_MODE_NORMAL
Normal mode.
- enumerator AHT_MODE_CYCLE
Continuous measurements mode, not supported by the driver.
Functions
- esp_err_t aht_init_desc(aht_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
Initialize device descriptor.
- Parameters:
dev – Device descriptor
addr – Device I2C address
port – I2C port
sda_gpio – SDA GPIO
scl_gpio – SCL GPIO
- Returns:
ESP_OKon success
- esp_err_t aht_free_desc(aht_t *dev)
Free device descriptor.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OKon success
- esp_err_t aht_init(aht_t *dev)
Init device.
Waits for the sensor to power up, sends the calibration command and checks the calibration bit. The command differs between the device types:
0xE1for AHT10/AHT15 and0xBEfor AHT20.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OKon success
ESP_ERR_INVALID_STATEif the sensor has not been calibrated
ESP_ERR_TIMEOUTif the sensor has not become idle
- esp_err_t aht_reset(aht_t *dev)
Soft reset device.
Resets the sensor and initializes it again.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OKon success
ESP_ERR_TIMEOUTif the sensor has not become idle
- esp_err_t aht_get_status(aht_t *dev, bool *busy, bool *calibrated)
Get device status.
- Parameters:
dev – Device descriptor
busy – [out] Busy flag
true: device currently measuring
false: device is idle
calibrated – [out] Calibration success flag
true: sensor calibrated
false: sensor not calibrated
- Returns:
ESP_OKon success
- esp_err_t aht_get_data(aht_t *dev, float *temperature, float *humidity)
Get temperature and relative humidity.
Triggers a measurement, waits for the sensor to finish it and reads the result. The output values are set only when
ESP_OKis returned. For the AHT20 the frame contains a CRC-8 checksum, and a corrupted frame is rejected.
- Parameters:
dev – Device descriptor
temperature – [out] Temperature, degrees Celsius
humidity – [out] Relative humidity, percents
- Returns:
ESP_OKon success
ESP_ERR_TIMEOUTif the sensor has not finished the measurement
ESP_ERR_INVALID_STATEif the sensor is not calibrated
ESP_ERR_INVALID_RESPONSEif the AHT20 frame has a wrong CRC
- struct aht_t
#include <aht.h>Device descriptor.