The goal is to measure the capacity of a LiFePo 12V 100Ah Battery by accumulating charging and discharging current over time.
As code I tried all examples i could find in the libs.
This is one of it:
/*
INA226 Bi-directional Current/Power Monitor. Simple Example.
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/cyfrowy-czujnik-pradu-mocy-ina226.html
GIT: https://github.com/jarzebski/Arduino-INA226
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
*/
#include <Wire.h>
#include <INA226.h>
INA226 ina;
void checkConfig()
{
Serial.print("Mode: ");
switch (ina.getMode())
{
case INA226_MODE_POWER_DOWN: Serial.println("Power-Down"); break;
case INA226_MODE_SHUNT_TRIG: Serial.println("Shunt Voltage, Triggered"); break;
case INA226_MODE_BUS_TRIG: Serial.println("Bus Voltage, Triggered"); break;
case INA226_MODE_SHUNT_BUS_TRIG: Serial.println("Shunt and Bus, Triggered"); break;
case INA226_MODE_ADC_OFF: Serial.println("ADC Off"); break;
case INA226_MODE_SHUNT_CONT: Serial.println("Shunt Voltage, Continuous"); break;
case INA226_MODE_BUS_CONT: Serial.println("Bus Voltage, Continuous"); break;
case INA226_MODE_SHUNT_BUS_CONT: Serial.println("Shunt and Bus, Continuous"); break;
default: Serial.println("unknown");
}
Serial.print("Samples average: ");
switch (ina.getAverages())
{
case INA226_AVERAGES_1: Serial.println("1 sample"); break;
case INA226_AVERAGES_4: Serial.println("4 samples"); break;
case INA226_AVERAGES_16: Serial.println("16 samples"); break;
case INA226_AVERAGES_64: Serial.println("64 samples"); break;
case INA226_AVERAGES_128: Serial.println("128 samples"); break;
case INA226_AVERAGES_256: Serial.println("256 samples"); break;
case INA226_AVERAGES_512: Serial.println("512 samples"); break;
case INA226_AVERAGES_1024: Serial.println("1024 samples"); break;
default: Serial.println("unknown");
}
Serial.print("Bus conversion time: ");
switch (ina.getBusConversionTime())
{
case INA226_BUS_CONV_TIME_140US: Serial.println("140uS"); break;
case INA226_BUS_CONV_TIME_204US: Serial.println("204uS"); break;
case INA226_BUS_CONV_TIME_332US: Serial.println("332uS"); break;
case INA226_BUS_CONV_TIME_588US: Serial.println("558uS"); break;
case INA226_BUS_CONV_TIME_1100US: Serial.println("1.100ms"); break;
case INA226_BUS_CONV_TIME_2116US: Serial.println("2.116ms"); break;
case INA226_BUS_CONV_TIME_4156US: Serial.println("4.156ms"); break;
case INA226_BUS_CONV_TIME_8244US: Serial.println("8.244ms"); break;
default: Serial.println("unknown");
}
Serial.print("Shunt conversion time: ");
switch (ina.getShuntConversionTime())
{
case INA226_SHUNT_CONV_TIME_140US: Serial.println("140uS"); break;
case INA226_SHUNT_CONV_TIME_204US: Serial.println("204uS"); break;
case INA226_SHUNT_CONV_TIME_332US: Serial.println("332uS"); break;
case INA226_SHUNT_CONV_TIME_588US: Serial.println("558uS"); break;
case INA226_SHUNT_CONV_TIME_1100US: Serial.println("1.100ms"); break;
case INA226_SHUNT_CONV_TIME_2116US: Serial.println("2.116ms"); break;
case INA226_SHUNT_CONV_TIME_4156US: Serial.println("4.156ms"); break;
case INA226_SHUNT_CONV_TIME_8244US: Serial.println("8.244ms"); break;
default: Serial.println("unknown");
}
Serial.print("Max possible current: ");
Serial.print(ina.getMaxPossibleCurrent());
Serial.println(" A");
Serial.print("Max current: ");
Serial.print(ina.getMaxCurrent());
Serial.println(" A");
Serial.print("Max shunt voltage: ");
Serial.print(ina.getMaxShuntVoltage());
Serial.println(" V");
Serial.print("Max power: ");
Serial.print(ina.getMaxPower());
Serial.println(" W");
}
void setup()
{
Serial.begin(115200);
Serial.println(“Initialize INA226”);
Serial.println("-----------------------------------------------");
// Default INA226 address is 0x40
ina.begin();
// Configure INA226
ina.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
// Calibrate INA226. Rshunt = 0.01 ohm, Max excepted current = 4A
ina.calibrate(0.01, 4);
// Display configuration
checkConfig();
Serial.println("-----------------------------------------------");
}
void loop()
{
Serial.print("Bus voltage: ");
Serial.print(ina.readBusVoltage(), 5);
Serial.println(" V");
Serial.print("Bus power: ");
Serial.print(ina.readBusPower(), 5);
Serial.println(" W");
Serial.print("Shunt voltage: ");
Serial.print(ina.readShuntVoltage(), 5);
Serial.println(" V");
Serial.print("Shunt current: ");
Serial.print(ina.readShuntCurrent(), 5);
Serial.println(" A");
Serial.println("");
delay(1000);
}
Next step will be to ignore any libs and to try to wirte to communication with the device completely new…