I've tried the example from the folder and the bus voltage does not read the same has my meter, The current side of things the readings are correct.
Even is there is no load the voltage reading are not the same. Meter reads 6.25V and INA226 read 6.18V.
I thought that the INA226 is 16bit and would give closer or better reading than the INA219 ?
Or am I asking to much of teh INA226 ?
Is there way to calibrate the voltage readings ?
code below
/***************************************************************************
* Example sketch for the INA226_WE library
*
* This sketch is based on the continuous mode example but uses the function setResistorRange to set a different resistor value.
*
* This setup uses a stromsensor6mm board with a 5 mOhm shunt resistor
* More information on this board can be found here: https://github.com/generationmake/stromsensor6mm
*
* More information on the INA226_WE library:
* https://wolles-elektronikkiste.de/en/ina226-current-and-power-sensor (English)
* https://wolles-elektronikkiste.de/ina226 (German)
*
***************************************************************************/
#include <Wire.h>
#include <INA226_WE.h>
#define I2C_ADDRESS 0x40
/* There are several ways to create your INA226 object:
* INA226_WE ina226 = INA226_WE(); -> uses I2C Address = 0x40 / Wire
* INA226_WE ina226 = INA226_WE(I2C_ADDRESS);
* INA226_WE ina226 = INA226_WE(&Wire); -> uses I2C_ADDRESS = 0x40, pass any Wire Object
* INA226_WE ina226 = INA226_WE(&Wire, I2C_ADDRESS);
*/
INA226_WE ina226 = INA226_WE(I2C_ADDRESS);
void setup() {
Serial.begin(115200);
while(!Serial); // wait until serial comes up on Arduino Leonardo or MKR WiFi 1010
Wire.begin();
ina226.init();
/* Set Number of measurements for shunt and bus voltage which shall be averaged
* Mode * * Number of samples *
AVERAGE_1 1 (default)
AVERAGE_4 4
AVERAGE_16 16
AVERAGE_64 64
AVERAGE_128 128
AVERAGE_256 256
AVERAGE_512 512
AVERAGE_1024 1024
*/
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_140 140 µs
CONV_TIME_204 204 µs
CONV_TIME_332 332 µs
CONV_TIME_588 588 µs
CONV_TIME_1100 1.1 ms (default)
CONV_TIME_2116 2.116 ms
CONV_TIME_4156 4.156 ms
CONV_TIME_8244 8.244 ms
*/
ina226.setConversionTime(CONV_TIME_1100); //choose conversion time and uncomment for change of default
/* Set measure mode
POWER_DOWN - INA226 switched off
TRIGGERED - measurement on demand
CONTINUOUS - continuous measurements (default)
*/
ina226.setMeasureMode(CONTINUOUS); // choose mode and uncomment for change of default
/* Set Resistor and Current Range
resistor is 5.0 mOhm
current range is up to 10.0 A
default was 100 mOhm and about 1.3 A
*/
ina226.setResistorRange(0.0245, 10.0); // choose resistor 5 mOhm and gain range up to 10 A
/* 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
}
void loop() {
float shuntVoltage_mV = 0.0;
float loadVoltage_V = 0.0;
float busVoltage_V = 0.0;
float current_mA = 0.0;
float power_mW = 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);
if(!ina226.overflow){
Serial.println("Values OK - no overflow");
}
else{
Serial.println("Overflow! Choose higher current range");
}
Serial.println();
delay(3000);
}