8static const char *
const TAG =
"hdc2010";
10static const uint8_t HDC2010_ADDRESS = 0x40;
11static const uint8_t HDC2010_CMD_CONFIGURATION_MEASUREMENT = 0x8F;
12static const uint8_t HDC2010_CMD_START_MEASUREMENT = 0xF9;
13static const uint8_t HDC2010_CMD_TEMPERATURE_LOW = 0x00;
14static const uint8_t HDC2010_CMD_TEMPERATURE_HIGH = 0x01;
15static const uint8_t HDC2010_CMD_HUMIDITY_LOW = 0x02;
16static const uint8_t HDC2010_CMD_HUMIDITY_HIGH = 0x03;
17static const uint8_t CONFIG = 0x0E;
18static const uint8_t MEASUREMENT_CONFIG = 0x0F;
21 ESP_LOGCONFIG(TAG,
"Running setup");
23 const uint8_t
data[2] = {
28 if (!this->
write_bytes(HDC2010_CMD_CONFIGURATION_MEASUREMENT,
data, 2)) {
29 ESP_LOGW(TAG,
"Initial config instruction error");
35 uint8_t config_contents;
37 config_contents = (config_contents & 0xF9);
38 this->
write_bytes(MEASUREMENT_CONFIG, &config_contents, 1);
42 config_contents &= 0x8F;
47 config_contents &= 0x3F;
52 config_contents &= 0xCF;
57 ESP_LOGCONFIG(TAG,
"HDC2010:");
60 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
62 LOG_UPDATE_INTERVAL(
this);
69 uint8_t config_contents;
71 config_contents |= 0x01;
72 this->
write_bytes(MEASUREMENT_CONFIG, &config_contents, 1);
79 ESP_LOGD(TAG,
"Temp=%.1f°C", temp);
85 ESP_LOGD(TAG,
"Humidity=%.1f%%", humidity);
93 this->
read_register(HDC2010_CMD_TEMPERATURE_LOW, &
byte[0], 1);
94 this->
read_register(HDC2010_CMD_TEMPERATURE_HIGH, &
byte[1], 1);
97 return (
float) temp * 0.0025177f - 40.0f;
107 return (
float) humidity * 0.001525879f;
void status_set_warning(const char *message=nullptr)
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void update() override
Retrieve the latest sensor values. This operation takes approximately 16ms.
sensor::Sensor * temperature_sensor_
void dump_config() override
void setup() override
Setup the sensor and check for connection.
sensor::Sensor * humidity_sensor_
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
void publish_state(float state)
Publish a new state to the front-end.
Providing packet encoding functions for exchanging data with a remote host.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.