22 static const char *
const TAG =
"aht10";
23 static const uint8_t AHT10_INITIALIZE_CMD[] = {0xE1, 0x08, 0x00};
24 static const uint8_t AHT20_INITIALIZE_CMD[] = {0xBE, 0x08, 0x00};
25 static const uint8_t AHT10_MEASURE_CMD[] = {0xAC, 0x33, 0x00};
26 static const uint8_t AHT10_SOFTRESET_CMD[] = {0xBA};
28 static const uint8_t AHT10_DEFAULT_DELAY = 5;
29 static const uint8_t AHT10_READ_DELAY = 80;
30 static const uint8_t AHT10_SOFTRESET_DELAY = 30;
32 static const uint8_t AHT10_ATTEMPTS = 3;
33 static const uint8_t AHT10_INIT_ATTEMPTS = 10;
35 static const uint8_t AHT10_STATUS_BUSY = 0x80;
39 ESP_LOGE(TAG,
"Reset AHT10 failed!");
41 delay(AHT10_SOFTRESET_DELAY);
46 ESP_LOGCONFIG(TAG,
"Setting up AHT20");
47 error_code = this->
write(AHT20_INITIALIZE_CMD,
sizeof(AHT20_INITIALIZE_CMD));
50 ESP_LOGCONFIG(TAG,
"Setting up AHT10");
51 error_code = this->
write(AHT10_INITIALIZE_CMD,
sizeof(AHT10_INITIALIZE_CMD));
55 ESP_LOGE(TAG,
"Communication with AHT10 failed!");
59 uint8_t data = AHT10_STATUS_BUSY;
61 while (data & AHT10_STATUS_BUSY) {
62 delay(AHT10_DEFAULT_DELAY);
64 ESP_LOGE(TAG,
"Communication with AHT10 failed!");
69 if (cal_attempts > AHT10_INIT_ATTEMPTS) {
70 ESP_LOGE(TAG,
"AHT10 initialization timed out!");
75 if ((data & 0x68) != 0x08) {
76 ESP_LOGE(TAG,
"AHT10 initialization failed!");
81 ESP_LOGV(TAG,
"AHT10 initialization");
105 if ((data[0] & 0x80) == 0x80) {
106 ESP_LOGD(TAG,
"AHT10 is busy, waiting...");
110 if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) {
113 ESP_LOGV(TAG,
"ATH10 Unrealistic humidity (0x0), but humidity is not required");
115 ESP_LOGD(TAG,
"ATH10 Unrealistic humidity (0x0), retrying...");
126 uint32_t raw_temperature = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
127 uint32_t raw_humidity = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4;
130 float temperature = ((200.0f * (float) raw_temperature) / 1048576.0f) - 50.0f;
135 if (raw_humidity == 0) {
138 humidity = (float) raw_humidity * 100.0f / 1048576.0f;
140 if (std::isnan(humidity)) {
141 ESP_LOGW(TAG,
"Invalid humidity! Sensor reported 0%% Hum");
162 ESP_LOGCONFIG(TAG,
"AHT10:");
163 LOG_I2C_DEVICE(
this);
165 ESP_LOGE(TAG,
"Communication with AHT10 failed!");
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
sensor::Sensor * humidity_sensor_
method called invalid argument(s)
uint32_t IRAM_ATTR HOT millis()
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void status_set_error(const char *message="unspecified")
No error found during execution of method.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
sensor::Sensor * temperature_sensor_
float get_setup_priority() const override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
void IRAM_ATTR HOT delay(uint32_t ms)