

Use of the INA226 library
You can download the library INA226_WE here from GitHub or install it directly with the Library Manager of the Arduino IDE.
/* There are several ways to create your INA226 object:
* INA226_WE ina226 = INA226_WE() -> uses Wire / I2C Address = 0x40
* INA226_WE ina226 = INA226_WE(ICM20948_ADDR) -> uses Wire / I2C_ADDRESS
* INA226_WE ina226 = INA226_WE(&wire2) -> uses the TwoWire object wire2 / I2C_ADDRESS
* INA226_WE ina226 = INA226_WE(&wire2, I2C_ADDRESS) -> all together
* Successfully tested with two I2C busses on an ESP32
INA226_WE ina226 = INA226_WE(I2C_ADDRESS);
/* Set Number of measurements for shunt and bus voltage which shall be averaged
* Mode * * Number of samples *
//ina226.setAverage(AVERAGE_16); // choose mode and uncomment for change of default
/* Set conversion time in microseconds
One set of shunt and bus voltage conversion will take:
number of samples to be averaged x conversion time x 2
* Mode * * conversion time *
CONV_TIME_1100 1.1 ms (default)
//ina226.setConversionTime(CONV_TIME_1100); //choose conversion time and uncomment for change of default
POWER_DOWN - INA226 switched off
TRIGGERED - measurement on demand
CONTINUOUS - continuous measurements (default)
//ina226.setMeasureMode(CONTINUOUS); // choose mode and uncomment for change of default
//ina226.setCurrentRange(MA_800); // choose gain and uncomment for change of default
/* If the current values delivered by the INA226 differ by a constant factor
from values obtained with calibrated equipment you can define a correction factor.
Correction factor = current delivered from calibrated equipment / current delivered by INA226
// ina226.setCorrectionFactor(0.95);
Serial.println("INA226 Current Sensor Example Sketch - Continuous");
ina226.waitUntilConversionCompleted(); //if you comment this line the first data might be zero
float shuntVoltage_mV = 0.0;
float loadVoltage_V = 0.0;
float busVoltage_V = 0.0;
ina226.readAndClearFlags();
shuntVoltage_mV = ina226.getShuntVoltage_mV();
busVoltage_V = ina226.getBusVoltage_V();
current_mA = ina226.getCurrent_mA();
power_mW = ina226.getBusPower();
loadVoltage_V = busVoltage_V + (shuntVoltage_mV/1000);
Serial.print("Shunt Voltage [mV]: "); Serial.println(shuntVoltage_mV);
Serial.print("Bus Voltage [V]: "); Serial.println(busVoltage_V);
Serial.print("Load Voltage [V]: "); Serial.println(loadVoltage_V);
Serial.print("Current[mA]: "); Serial.println(current_mA);
Serial.print("Bus Power [mW]: "); Serial.println(power_mW);
Serial.println("Values OK - no overflow");
Serial.println("Overflow! Choose higher current range");