29static const uint8_t INA226_REGISTER_CONFIG = 0x00;
30static const uint8_t INA226_REGISTER_SHUNT_VOLTAGE = 0x01;
31static const uint8_t INA226_REGISTER_BUS_VOLTAGE = 0x02;
32static const uint8_t INA226_REGISTER_POWER = 0x03;
33static const uint8_t INA226_REGISTER_CURRENT = 0x04;
34static const uint8_t INA226_REGISTER_CALIBRATION = 0x05;
36static const uint16_t INA226_ADC_TIMES[] = {140, 204, 332, 588, 1100, 2116, 4156, 8244};
37static const uint16_t INA226_ADC_AVG_SAMPLES[] = {1, 4, 16, 64, 128, 256, 512, 1024};
76 ESP_LOGV(TAG,
" Using LSB=%" PRIu32
" calibration=%" PRIu32, lsb, calibration);
78 if (!this->
write_byte_16(INA226_REGISTER_CALIBRATION, calibration)) {
85 ESP_LOGCONFIG(TAG,
"INA226:");
90 LOG_UPDATE_INTERVAL(
this);
93 " ADC Conversion Time Bus Voltage: %d\n"
94 " ADC Conversion Time Shunt Voltage: %d\n"
95 " ADC Averaging Samples: %d",
107 uint16_t raw_bus_voltage;
108 if (!this->
read_byte_16(INA226_REGISTER_BUS_VOLTAGE, &raw_bus_voltage)) {
114 bus_voltage_v *= 0.00125f;
119 uint16_t raw_shunt_voltage;
120 if (!this->
read_byte_16(INA226_REGISTER_SHUNT_VOLTAGE, &raw_shunt_voltage)) {
126 shunt_voltage_v *= 0.0000025f;
131 uint16_t raw_current;
132 if (!this->
read_byte_16(INA226_REGISTER_CURRENT, &raw_current)) {
144 if (!this->
read_byte_16(INA226_REGISTER_POWER, &raw_power)) {
148 float power_mw = int16_t(raw_power) * (this->
calibration_lsb_ * 25.0f / 1000.0f);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void status_clear_warning()
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_byte_16(uint8_t a_register, uint16_t data) const
AdcTime adc_time_voltage_
AdcTime adc_time_current_
sensor::Sensor * power_sensor_
sensor::Sensor * bus_voltage_sensor_
void dump_config() override
float shunt_resistance_ohm_
sensor::Sensor * current_sensor_
sensor::Sensor * shunt_voltage_sensor_
AdcAvgSamples adc_avg_samples_
uint32_t calibration_lsb_
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "ina226")
constexpr int32_t sign_extend(uint32_t value)
Sign-extend the low BITS bits of value, e.g. sign_extend<24>(0xFFFFFE) == -2. Higher bits are ignored...
void HOT delay(uint32_t ms)
AdcAvgSamples avg_samples
AdcTime shunt_voltage_conversion_time
AdcTime bus_voltage_conversion_time