INA219 sensor value validity

Hello
I use INA219 sensor with the library from Adafruit.
When I get Voltage value or current value I get always an answer. Even when the INA219 sensor is not connected ....

Is there a way to know if the received value from this function is valid ?

Upload your code.

the problem is not my software :slight_smile:
I get the standard adafruit exemple wich display Volt and Amp.
If I connect the INA219 between a load and the arduino
I get the real Voltage and the real current.
But if I did not connect the INA219 to the arduino I get also some values for Volt and Amp...
Which is not possible!

So my question is : how to be sure that value are real one or "fake" because the INA219 is not responding...

The INA219 is a current sensing transducer using I2C comms, therefore the lack of this device on your network will mean that zero data will come over the network. I think this is the reason why dyso has asked you to upload your code. Clearly there is some default condition which allows the system to display something even though nothing has been received.

What have you got to lose by showing your code? There are some clever and talented people on here that will help you if you allow them to.

Thanks for help !
Of course I have no problem to show my code (below) :slight_smile:
It was just I was wondering if my first explanation of the problem was clear enough

The code :

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219_Solar(0x41);
float solar_shuntVoltage = 0;
float solar_busVoltage = 0;
float solar_current = 0;

Adafruit_INA219 ina219_Battery(0x45);
float battery_shuntVoltage = 0;
float battery_busVoltage = 0;
float battery_current = 0;

Adafruit_INA219 ina219_Load;
float load_shuntVoltage = 0;
float load_busVoltage = 0;
float load_current = 0;

//************* SETUP *************
void setup() {

Serial.begin(9600);
Serial.println("Serial");
delay(50);
ina219_Solar.begin();
// ina219_Solar.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA
Serial.println("Solar");
delay(50);
ina219_Battery.begin();
// ina219_Battery.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA
Serial.println("Battery");
delay(50);
ina219_Load.begin();
// ina219_Load.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA
Serial.println("Load");
delay(50);
Serial.println("*******");
delay(50);
}

//************* LOOP *************

void loop()
{
solar_busVoltage = ina219_Solar.getBusVoltage_V();
solar_shuntVoltage = ina219_Solar.getShuntVoltage_mV();
solar_current = ina219_Solar.getCurrent_mA();

battery_busVoltage = ina219_Battery.getBusVoltage_V();
battery_shuntVoltage = ina219_Battery.getShuntVoltage_mV();
battery_current = ina219_Battery.getCurrent_mA();

load_busVoltage = ina219_Load.getBusVoltage_V();
load_shuntVoltage = ina219_Load.getShuntVoltage_mV();
load_current = ina219_Load.getCurrent_mA();

Serial.print("solar ");
Serial.print(solar_busVoltage);
Serial.print(" V ");
Serial.print(solar_shuntVoltage);
Serial.print(" V ");
Serial.print(solar_current);
Serial.println(" mA ");
Serial.print("battery ");
Serial.print(battery_busVoltage);
Serial.print(" V ");
Serial.print(battery_shuntVoltage);
Serial.print(" V ");
Serial.print(battery_current);
Serial.println(" mA ");
Serial.print("load ");
Serial.print(load_busVoltage);
Serial.print(" V ");
Serial.print(load_shuntVoltage);
Serial.print(" V ");
Serial.print(load_current);
Serial.println(" mA ");
Serial.println("*******");
delay(5000);

}

And the result with no INA219 sensor connected to Arduino:

16:17:27.543 -> Serial
16:17:27.609 -> Solar
16:17:27.643 -> Battery
16:17:27.709 -> Load
16:17:27.743 -> *******
16:17:27.843 -> solar 0.14 V 2.72 V inf mA
16:17:27.843 -> battery 8.35 V 167.06 V inf mA
16:17:27.909 -> load 8.35 V 167.06 V inf mA
16:17:27.909 -> *******
16:17:32.870 -> solar 0.14 V 2.72 V inf mA
16:17:32.870 -> battery 8.35 V 167.06 V inf mA
16:17:32.935 -> load 8.35 V 167.06 V inf mA

@Glorymill
That's exactly why I asked. Thank you.

@ewok2
You have 2 boards connected? Did you remove both of them while testing it? Do you have anything else connected to the I²C bus?

I plane to have 3 board connected and none of them were connected

That's very strange, however, try this and see what happens:

  if (!ina219_Solar.begin()) {
	Serial.println("Could not find a Solar sensor, check wiring!");
	while (1) {}
  }

Instead of:

ina219_Solar.begin();

Yes I know it is a solution but this sketch is only a way to chek INA219 works.
After it will be a raspberry that will automaticly get the value send by arduino in serial
And the begin test is only at arduino initialisation.
I would like a way to test the validity of the get INA219 command....

You should try with a different Arduino board. Or just try with the raspberry pi.

ewok2:
When I get Voltage value or current value I get always an answer. Even when the INA219 sensor is not connected .

Random values is normal behaviour for a 'floating' input.
Leo..

Wawa ramdom is normal for mesurment value of voltage at arduino pin or even at INA219 pin.
But if arduino request via a numerical bus to INA219 and INA219 did not answer (as he is not connected) I expect somme error or warning or constant value from the arduino software function requesting the value...

Dyso I will have a look of the cpp source code of the function to understand.
I don't think it will change with HW executing the same software

ewok2:
Wawa ramdom is normal for mesurment value of voltage at arduino pin or even at INA219 pin.
But if arduino request via a numerical bus to INA219 and INA219 did not answer (as he is not connected) I expect somme error or warning or constant value from the arduino software function requesting the value...

Dyso I will have a look of the cpp source code of the function to understand.
I don't think it will change with HW executing the same software

So your assumption is that since there is no I2C device connected to the I2C pins, then the Adafruit Library should be able to know that, and return ideally a value of ZERO when it queries the device for a value. HOWEVER, when you leave the I2C pins floating, there is still random noise on the pins and the Adafruit Library could be interpreting that noise as a value that it reports back to you.

Look at the library code and see what it's doing.

I would be curious, however, if you set the I2C pins to INPUT_PULLUP (Like this for an Arduino Nano):

pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);

Then connected those pins to ground, if you would still get the same behavior from the library.

Mike

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