Here is the code I'm using to learn INA219 (downloaded code from Internet).
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(9600);
while (!Serial)
{
delay(1);
}
// Initialize the INA219.
if (! ina219.begin())
{
Serial.println("Failed to find INA219 chip");
while (1)
{
delay(10);
}
}
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range, call:
ina219.setCalibration_16V_400mA();
Serial.println("Measuring voltage, current, and power with INA219 ...");
}
void loop(void)
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");
delay(5000);
}
As load I have 3 red LED with individual resistor from 5 V to GND. INA219 is series connected to 5V and the anodes of the LEDs.
Running the sketch I get "Failed to find INA219 chip"
Removing the chip detection from the code, and adding ina219.begin(); the chip seems to function with strange output values, as follows:
Power: -17943.00 mW
Bus Voltage: 0.42 V
Shunt Voltage: 8.48 mV
Load Voltage: 0.43 V
Current: -897.15 mA
Power: -17943.00 mW
I need some help, please!