8static const char *
const TAG =
"ina3221";
10static const uint8_t INA3221_REGISTER_CONFIG = 0x00;
11static const uint8_t INA3221_REGISTER_CHANNEL1_SHUNT_VOLTAGE = 0x01;
12static const uint8_t INA3221_REGISTER_CHANNEL1_BUS_VOLTAGE = 0x02;
13static const uint8_t INA3221_REGISTER_CHANNEL2_SHUNT_VOLTAGE = 0x03;
14static const uint8_t INA3221_REGISTER_CHANNEL2_BUS_VOLTAGE = 0x04;
15static const uint8_t INA3221_REGISTER_CHANNEL3_SHUNT_VOLTAGE = 0x05;
16static const uint8_t INA3221_REGISTER_CHANNEL3_BUS_VOLTAGE = 0x06;
25 ESP_LOGCONFIG(TAG,
"Setting up INA3221...");
37 config |= 0b0100000000000000;
40 config |= 0b0010000000000000;
43 config |= 0b0001000000000000;
46 config |= 0b0000000000000000;
48 config |= 0b0000000111000000;
50 config |= 0b0000000000111000;
52 config |= 0b0000000000000111;
60 ESP_LOGCONFIG(TAG,
"INA3221:");
63 ESP_LOGE(TAG,
"Communication with INA3221 failed!");
65 LOG_UPDATE_INTERVAL(
this);
67 LOG_SENSOR(
" ",
"Bus Voltage #1", this->
channels_[0].bus_voltage_sensor_);
68 LOG_SENSOR(
" ",
"Shunt Voltage #1", this->
channels_[0].shunt_voltage_sensor_);
69 LOG_SENSOR(
" ",
"Current #1", this->
channels_[0].current_sensor_);
70 LOG_SENSOR(
" ",
"Power #1", this->
channels_[0].power_sensor_);
71 LOG_SENSOR(
" ",
"Bus Voltage #2", this->
channels_[1].bus_voltage_sensor_);
72 LOG_SENSOR(
" ",
"Shunt Voltage #2", this->
channels_[1].shunt_voltage_sensor_);
73 LOG_SENSOR(
" ",
"Current #2", this->
channels_[1].current_sensor_);
74 LOG_SENSOR(
" ",
"Power #2", this->
channels_[1].power_sensor_);
75 LOG_SENSOR(
" ",
"Bus Voltage #3", this->
channels_[2].bus_voltage_sensor_);
76 LOG_SENSOR(
" ",
"Shunt Voltage #3", this->
channels_[2].shunt_voltage_sensor_);
77 LOG_SENSOR(
" ",
"Current #3", this->
channels_[2].current_sensor_);
78 LOG_SENSOR(
" ",
"Power #3", this->
channels_[2].power_sensor_);
86 for (
int i = 0; i < 3; i++) {
88 float bus_voltage_v = NAN, current_a = NAN;
95 bus_voltage_v = int16_t(
raw) / 1000.0f;
104 const float shunt_voltage_v = int16_t(
raw) * 40.0f / 8.0f / 1000000.0f;
127 return this->shunt_voltage_sensor_ !=
nullptr || this->current_sensor_ !=
nullptr || this->power_sensor_ !=
nullptr;
130 return this->bus_voltage_sensor_ !=
nullptr || this->power_sensor_ !=
nullptr;
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_byte_16(uint8_t a_register, uint16_t data)
float get_setup_priority() const override
struct esphome::ina3221::INA3221Component::INA3221Channel channels_[3]
void set_shunt_resistance(int channel, float resistance_ohm)
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
uint8_t ina3221_shunt_voltage_register(int channel)
uint8_t ina3221_bus_voltage_register(int channel)
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)
sensor::Sensor * shunt_voltage_sensor_
bool should_measure_shunt_voltage()
sensor::Sensor * bus_voltage_sensor_
bool should_measure_bus_voltage()
sensor::Sensor * power_sensor_
sensor::Sensor * current_sensor_