Connecting 3x (multiple) INA219 Sensors

Hi,

I've got 3 INA219 sensors at three different address 0x40, 0x41, 0x42. This data will be displayed on my tft screen (I've omitted the code for this bit for now to focus on the INA219 sensors). I'm still getting the same reading for 0x40 and 0x41 (I haven't tried with the third sensor yet) but it shouldn't be giving the same reading according to my PSU.

I'm using a Metro M0 Express, a RA8875 driver board, a few other sensors and 3x INA219 chips.

This is what my code looks like -
If any obvious errors can be spotted, please do let me know.

#include <Wire.h>
#include <Adafruit_INA219.h>
// #include <SPI.h>
// #include "Adafruit_GFX.h"
// #include "Adafruit_RA8875.h"

#define INA219_5 0x40
#define INA219_12 0x41
#define INA219_24 0x42

Adafruit_INA219 ina219_5;
Adafruit_INA219 ina219_12;
Adafruit_INA219 ina219_24;


void setup() {
  Serial.begin(9600);

  Wire.begin();

  // Initialise the 4th sensor
  if (! ina219_5.begin()) {
    Serial.println("Failed to find INA219 5V chip");
    while (1) { delay(10); }
  }
  Serial.println("INA219 5V Found!");
  
  // Initialise the 5th sensor
  if (! ina219_12.begin()) {
    Serial.println("Failed to find INA219 12V chip");
    while (1) { delay(10); }
  }
  Serial.println("INA219 12V Found!");

  // Initialise the 6th sensor
  if (! ina219_24.begin()) {
    Serial.println("Failed to find INA219 24V chip");
    while (1) { delay(10); }
  }
  Serial.println("INA219 24V Found!");

}

void loop() {
  float current_mA_5V = 0;
  current_mA_5V = ina219_5.getCurrent_mA();
    float shuntvoltage_5 = 0;
    float busvoltage_5 = 0;
    float current_mA_5 = 0;
    float loadvoltage_5 = 0;
    float power_mW_5 = 0;
    current_mA_5 = ina219_5.getCurrent_mA();
    //  tft.textSetCursor(400, 160);tft.textColor(CYAN, RA8875_BLACK);tft.textEnlarge(2);tft.textEnlarge(1);tft.print(current_mA_5);
  
 float current_mA_12V = 0;
  current_mA_12V = ina219_12.getCurrent_mA();
    float shuntvoltage_12 = 0;
    float busvoltage_12 = 0;
    float current_mA_12 = 0;
    float loadvoltage_12 = 0;
    float power_mW_12 = 0;
    current_mA_12 = ina219_12.getCurrent_mA();
      // tft.textSetCursor(400, 260);tft.textColor(CYAN, RA8875_BLACK);tft.textEnlarge(2);tft.textEnlarge(1);tft.print(current_mA_12);

    float current_mA_24V = 0;
  current_mA_24V = ina219_24.getCurrent_mA();
    float shuntvoltage_24 = 0;
    float busvoltage_24 = 0;
    float current_mA_24 = 0;
    float loadvoltage_24 = 0;
    float power_mW_24 = 0;
    current_mA_24 = ina219_24.getCurrent_mA();
      //  tft.textSetCursor(400, 350);tft.textColor(CYAN, RA8875_BLACK);tft.textEnlarge(2);tft.textEnlarge(1);tft.print(current_mA_24);

  delay(1000);
}

Thank you

Try using this:

Adafruit_INA219 ina219_5(0x40);
Adafruit_INA219 ina219_12(0x41);
Adafruit_INA219 ina219_24(0x42);

1 Like

Will I need to change the wire.begin as well? Such as this:

#define INA219_5_ADDRESS(0x40)
#define INA219_12_ADDRESS(0x41)

(...)

  Wire.begin(INA219_5_ADDRESS);
  // Initialise the 4th sensor
  if (! ina219_5.begin()) {
    Serial.println("Failed to find INA219 5V chip");
    while (1) { delay(10); }
  }
  Serial.println("INA219 5V Found!");
  
  Wire.begin(INA219_12_ADDRESS);
  // Initialise the 5th sensor
  if (! ina219_12.begin()) {
    Serial.println("Failed to find INA219 12V chip");
    while (1) { delay(10); }
  }
  Serial.println("INA219 12V Found!");

Will give it a try, thanks.

You don't use #defines and you don't need to put the address in begin()

Adafruit_INA219 ina219_5(0x40);
Adafruit_INA219 ina219_12(0x41);
Adafruit_INA219 ina219_24(0x42);
1 Like

Thanks Jim! That has resolved it.

Glad I could help.
Have a nice day.

Sorry to bother you again-

It seems to work for address 0x40 and 0x41 and gives the correct values. But not for 0x42. Any possible explanation why that might be?

Is it finding all three INA_219s?
Are you sure you set the address to 0x42?
You can only set the addresses on the the Adafruit boards to 0x40, or 0x41 or 0x44 or 0x45.
Could it be 0x44 or 0x45 and NOT 0x42?

1 Like

Use an I2C scanner to discover what addresses are on the bus

1 Like

Thanks Jim! It did turn out to be 0x44, used the I2C scanner as UKHeliBob suggested.

Have fun!

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