Go Down

Topic: Unable to make INA219 volt/power meter work (Read 200 times) previous topic - next topic

dkaiss

Sep 25, 2018, 12:55 pm Last Edit: Sep 25, 2018, 12:58 pm by dkaiss
Hi

I have the INA219 I2C Bi-directional DC Current Power Supply Sensor Breakout Module. I'm trying to make it work. I made the right connections to my Arduino UNO R3 board.

On the other hand, I have another power circuit which powers a led. It is connected to a 9V power supply which generates a 5 Volt power using MB102 Breadboard Power Supply Module. When I run the default Adafruit_INA219 getcurrent application (see code bellow), all what I'm getting is constant numbers (zeros) for the voltage and the current. Basically, it is like the chip is not functioning.

I attached all the relevant pictures. Can anybody help with what wrong I'm doing?



Thanks in advance
Daher.

PS. The code that I'm using :

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

Adafruit_INA219 ina219;


void setup(void)
{
Serial.begin(115200);
while (!Serial) {
    // will pause Zero, Leonardo, etc until serial console opens
    delay(1);
}

uint32_t currentFrequency;
 
Serial.println("Hello!");

// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A).  However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();

Serial.println("Measuring voltage and current 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(2000);
}

adwsystems

Based on picture #3, I could touch up all of your solder connections. With that complete, run the I2C_Scanner sketch and report which I2C nodes the scanner can find.

dkaiss

Hi

Thanks for the reply.

I soldered again the connections. See pictures. I ran the I2C_Scannper scetch and got the followings

 
Scanning...
I2C device found at address 0x40  !
done

Can you advise?

Daher.


dkaiss

The pictures of the connections are attached

Daher.

adwsystems

Does your sketch work now? I wonder how you tell the ina219 code the chip is at address 0x40. I don't see any address definition.

dkaiss

Hi

No it is still not working. I still get zeros everywhere.

I followed your advice to run the i2c_scanner, and using it I got the 0x40 address.

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

adwsystems

Please use code tags, see how to use the forum #7.

Have you found how to set, or if the address for the INA219 needs to be set, in your non-working sketch or the INA219 library?

dkaiss

I'm sorry for not using code tags. This is my first question at arduino forums.

I looked into the code at Adafruit_INA219.h and  I do see the the followings:

Code: [Select]
#define INA219_ADDRESS                         (0x40)    // 1000000 (A0+A1=GND)


since I already got the above address in the i2c_scanner test app, then I think I don't need to make any modifications to my code since the default address is the one that is being detected.

BT, also this code doesn't work (returns all zeros)

Code: [Select]

/**********************************************
* INA219 library example
* 10 May 2012 by johngineer
*
* this code is public domain.
**********************************************/


#include <Wire.h>
#include <INA219.h>

INA219 monitor;


void setup()
{
  Serial.begin(9600);
  monitor.begin(64);
  monitor.configure(0, 3, 3, 7);
 
  // test shunt = 115mm of 22AWG solid copper = 0.3 Ohms
  monitor.calibrate(0.3, 0.2, 6, 0.25);
 

}

void loop()
{

  Serial.println("******************");
 
  Serial.print("raw shunt voltage: ");
  Serial.println(monitor.shuntVoltageRaw());
 
  Serial.print("raw bus voltage:   ");
  Serial.println(monitor.busVoltageRaw());
 
  Serial.println("--");
 
  Serial.print("shunt voltage: ");
  Serial.print(monitor.shuntVoltage() * 1000, 4);
  Serial.println(" mV");
 
  Serial.print("shunt current: ");
  Serial.print(monitor.shuntCurrent() * 1000, 4);
  Serial.println(" mA");
 
  Serial.print("bus voltage:   ");
  Serial.print(monitor.busVoltage(), 4);
  Serial.println(" V");
 
  Serial.print("bus power:     ");
  Serial.print(monitor.busPower() * 1000, 4);
  Serial.println(" mW");
 
  Serial.println(" ");
  Serial.println(" ");
 
  delay(10000);

}




Any other advise?

Daher.

Go Up