7 static const char *
const TAG =
"sht3xd";
16 static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING = 0x3780;
17 static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER = 0x3682;
19 static const uint16_t SHT3XD_COMMAND_READ_STATUS = 0xF32D;
20 static const uint16_t SHT3XD_COMMAND_CLEAR_STATUS = 0x3041;
21 static const uint16_t SHT3XD_COMMAND_HEATER_ENABLE = 0x306D;
22 static const uint16_t SHT3XD_COMMAND_HEATER_DISABLE = 0x3066;
23 static const uint16_t SHT3XD_COMMAND_SOFT_RESET = 0x30A2;
24 static const uint16_t SHT3XD_COMMAND_POLLING_H = 0x2400;
25 static const uint16_t SHT3XD_COMMAND_FETCH_DATA = 0xE000;
28 ESP_LOGCONFIG(TAG,
"Setting up SHT3xD...");
29 uint16_t raw_serial_number[2];
30 if (!this->
get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING, raw_serial_number, 2)) {
32 if (!this->
get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER, raw_serial_number, 2)) {
39 this->
serial_number_ = (uint32_t(raw_serial_number[0]) << 16) | uint32_t(raw_serial_number[1]);
49 ESP_LOGCONFIG(TAG,
"SHT3xD:");
50 switch (this->error_code_) {
52 ESP_LOGD(TAG,
" Error reading serial number");
55 ESP_LOGD(TAG,
" Error writing heater mode");
61 ESP_LOGE(TAG,
" Communication with SHT3xD failed!");
64 ESP_LOGD(TAG,
" Setup successful");
65 ESP_LOGD(TAG,
" Serial Number: 0x%08" PRIX32, this->
serial_number_);
66 ESP_LOGD(TAG,
" Heater Enabled: %s", this->
heater_enabled_ ?
"true" :
"false");
69 LOG_UPDATE_INTERVAL(
this);
79 ESP_LOGD(TAG,
"Retrying to reconnect the sensor.");
94 float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
95 float humidity = 100.0f * float(raw_data[1]) / 65535.0f;
97 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity);
sensor::Sensor * temperature_sensor_
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
bool status_has_warning() const
bool write_command(T i2c_register)
Write a command to the i2c device.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_data(uint16_t *data, uint8_t len)
Read data words from i2c device.
void status_clear_warning()
float get_setup_priority() const override
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
bool get_register(uint16_t command, uint16_t *data, uint8_t len, uint8_t delay=0)
get data words from i2c register.
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
sensor::Sensor * humidity_sensor_