INA226 bus voltage

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);
}

That is good agreement, and the average is very likely within the error bounds of both measurements.

As the old saying goes: give a man a watch and he knows what time it is. Give him two, and he is not sure.

For sure, just over 1% error. Quit complaining.

The INA219 measures voltage on one side of it's 0.1 ohm current shunt.
If you have connected it backwards, then voltage drops with current.
Leo..

1 Like

Hi, @Steveiboy

Yes there is but first take two or three readings to check if error is proportional of an offset.

Tom... :grinning: :+1: :coffee: :australia:

My resistor is mounted in the high side, and the voltage reading is open circuit reading with no load.

I’ve seen some videos and photos where people’s reading match the meter reading.

Thanks Tom I will try that by setting 2/3 voltage setting and compare them for offset

Maybe it is only a few milli-volts here and there that add up.
I assume that the INA226 is calibrated in the factory.

Finding milli-volts:

  • How good is your multimeter ?
  • When measuring the voltage, the black probe of the multimeter should be on the GND pin of the INA226.
  • A noisy power supply can generate so much noise in a circuit, that voltage measurements can vary, for example when measuring the same voltage a few cm further.
  • Check the voltage difference between different GND points. Currents through GND wires can do funny things.

Question is "which factory" :slight_smile:

There are so many fakes out there that you have to assume every chip is fake.
Get the boards from Adafruit/Sparkfun if you're picky.
Or do a final calibration yourself.
Leo..

You can safely put that out of your mind, and relax.

All measuring instruments have errors (+/- 1% of the full scale reading is typical), and all sensors and circuits introduce unavoidable measurement noise.

The readings from two different sensors measuring the same quantity will almost never exactly match. If they do match, it is an accident.

Which meter are you using? Do you believe it's absolutely accurate? The INA226 may be the more accurate instrument. Have you tried a second meter as a referee?

It's a Fluke 179 meter which has recently been calibrated, I get the same readings on my Fluke 233 and Fluke 116.

I've just checked that and that reading is the same as on the meter as I had my leads connected direct at the power supply so that's where the error is coming from

Change
busVoltage_V = ina226.getBusVoltage_V();
to
busVoltage_V = ina226.getBusVoltage_V() * 1.011327;
Leo..

1 Like

I have nothing to contribute this conversation and I apologize if this not the best way to do so but I sincerely wanted to Thank You. I know its random but your explanation on December 2022 regarding resistor values when using a PC817 & 2N2222 was so brilliant. Not only did you put an end to an hours long rabbit hole but something about it just made it click on my brain I have always struggled when doing the math of this type and it just makes since now. Again sorry for the random message, I am a new user, I have read discussions on the site before but never created an account till now, just to be able to write this. Just wanted to thank you for the great work and I hope this message brings a bit if joy, just like you did to me with that explanation.

Cheers!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.