Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Multiple INA219 Current Sensors
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Multiple INA219 Current Sensors

by sigurdk on Wed May 10, 2017 12:40 pm

I am designing a small Solar project, and want to use two INA219 sensors (ina219 and ina219_B). Using an arduino UNO and 1.6.5 IDE for testing. Plan to use something with WiFi later. Using the getcurrent sketch at learn.adafruit.com

Problems:

Loop executes only once after resetting UNO. If I disconnect ina219_B, then get multiple measurement, but values are wrong after the first measurement which is correct ( measuring 12 vdc from bench supply, but get values up as high as 36 volts

I originally named the two objects ina219_A and ina219_B, but the IDE would not compile for ina219_A, so I named the two objects ina219 and ina219_B.

Any help would be appreciated. I really appreciate the software that you folks write to support the hardware.

Sigurd, callsign KJ1K
Attachments
2017-05-10 INA219 first measurement ok then not.jpg
2017-05-10 INA219 first measurement ok then not.jpg (79.08 KiB) Viewed 1440 times

sigurdk
 
Posts: 6
Joined: Thu Dec 27, 2012 11:02 pm

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed May 10, 2017 12:50 pm

Please post the code you are using - and some photos showing your connections and addressing of the boards.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple INA219 Current Sensors

by sigurdk on Wed May 10, 2017 3:01 pm

Previously I successfully checked my Solar Panel Interface which includes another INA219 assembly with the default I2C address and an I2C LED/Switch (Keyboard) assembly which I purchased from i2cchip.com

I can send you more pictures or whatever.

Thanks,

Sigurd
Attachments
getcurrent_0x41.txt
This is file used with data previously sent.
(1.67 KiB) Downloaded 294 times
Mega2560 shield and UNO with I2C distribution.jpg
INA219 assembly has I2C address of 0x41
Mega2560 shield and UNO with I2C distribution.jpg (693.94 KiB) Viewed 1425 times

sigurdk
 
Posts: 6
Joined: Thu Dec 27, 2012 11:02 pm

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed May 10, 2017 3:53 pm

I can only see the soldering & addressing on one of the boards. And most of the joints appear to have not flowed onto the solder pads.
Please review this guide for tips on fixing these: http://learn.adafruit.com/adafruit-guid ... n-problems

Also, please post your code.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple INA219 Current Sensors

by sigurdk on Wed May 10, 2017 7:26 pm

getcurrent_0x41.txt
(1.67 KiB) Downloaded 312 times


Please note that I use wire wrap, not solder connections where practical, so you may have been looking at wire wrap connections.

Hope this helps.

Sigurd
ina219_B connections.jpg
ina219_B connections.jpg (224.26 KiB) Viewed 1396 times
Attachments
ina219 connections on Solar Panel Interface.jpg
ina219 connections on Solar Panel Interface.jpg (546.67 KiB) Viewed 1396 times

sigurdk
 
Posts: 6
Joined: Thu Dec 27, 2012 11:02 pm

Re: Multiple INA219 Current Sensors

by sigurdk on Wed May 10, 2017 7:39 pm

BTW, I have attached attachments with the code I am using for testing, but apparently you don't see them, so I am pasting the code into this message:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219_A;
Adafruit_INA219 ina219_B(0x041);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

void setup(void)
{
  #ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif
  uint32_t currentFrequency;
   
  Serial.begin(9600);
  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_A.begin();
  ina219_B.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;

  shuntvoltage = ina219_B.getShuntVoltage_mV();
  busvoltage = ina219_B.getBusVoltage_V();
  current_mA = ina219_B.getCurrent_mA();
  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.println("");

  delay(2000);
}
Last edited by adafruit_support_bill on Wed May 10, 2017 7:44 pm, edited 2 times in total.
Reason: please use [code] tags when posting code to the forums.

sigurdk
 
Posts: 6
Joined: Thu Dec 27, 2012 11:02 pm

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed May 10, 2017 7:46 pm

Please note that I use wire wrap, not solder connections where practical, so you may have been looking at wire wrap connections.

Wire wrap assures good connectivity between the wire and the pin. It does not assure good contact between the pin and the board. For that you need solder.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple INA219 Current Sensors

by sigurdk on Wed May 10, 2017 10:15 pm

Mea Culpa. I mis-connected the ground wire going from the arduino shield to the INA219_B breakout. I have now connected it properly and all works fine. I had checked the resistance from Vcc to ground at the breakout, but should have checked it back at the source.

Sorry for the inconvenience.

Thank you for your help.

Sigurd

sigurdk
 
Posts: 6
Joined: Thu Dec 27, 2012 11:02 pm

Re: Multiple INA219 Current Sensors

by criton07 on Wed Jul 17, 2019 10:02 am

hi there,
I am new to this as well i am using 3 ina219 modules but all the modules show the same value which is not correct.
can you please help me out. the code is given below thanks in advance



Code: Select all | TOGGLE FULL SIZE
#include<Wire.h>
#include<Adafruit_INA219.h>


Adafruit_INA219 ina219_A;
Adafruit_INA219 ina219_B(0x41);
Adafruit_INA219 ina219_C(0x44);

int switch_1 = 6; //switch pins
int switch_2 = 7; //switch pins
int switch_3 = 5; //switch pins



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

pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

ina219_A.begin();
ina219_B.begin();
ina219_C.begin();


 }

 void loop(){
 
 // put your main code here, to run repeatedly:
 

 
 float shuntvoltage_1 = 0;// current voltage monitor 1
  float busvoltage_1 = 0;
  float current_mA_1 = 0;
  float loadvoltage_1 = 0;
  float power_mW_1 = 0;

  shuntvoltage_1 = ina219_A.getShuntVoltage_mV();
  busvoltage_1 = ina219_A.getBusVoltage_V();
  current_mA_1 = ina219_A.getCurrent_mA();
  power_mW_1 = ina219_A.getPower_mW();
  loadvoltage_1 = busvoltage_1 + (shuntvoltage_1 / 1000);
 
  Serial.print("Bus Voltage1:   "); Serial.print(busvoltage_1); Serial.println(" V");
  Serial.print("Shunt Voltage1: "); Serial.print(shuntvoltage_1); Serial.println(" mV");
  Serial.print("Load Voltage1:  "); Serial.print(loadvoltage_1); Serial.println(" V");
  Serial.print("Current1:       "); Serial.print(current_mA_1); Serial.println(" mA");
  Serial.print("Power1:         "); Serial.print(power_mW_1); Serial.println(" mW");
  Serial.println("");

    // put your main code here, to run repeatedly:
 float shuntvoltage_2 = 0;// current voltage monitor 1
  float busvoltage_2 = 0;
  float current_mA_2 = 0;
  float loadvoltage_2 = 0;
  float power_mW_2 = 0;

  shuntvoltage_2 = ina219_B.getShuntVoltage_mV();
  busvoltage_2 = ina219_B.getBusVoltage_V();
  current_mA_2 = ina219_B.getCurrent_mA();
  power_mW_2 = ina219_B.getPower_mW();
  loadvoltage_2 = busvoltage_2 + (shuntvoltage_2 / 1000);
 
  Serial.print("Bus Voltage2:   "); Serial.print(busvoltage_2); Serial.println(" V");
  Serial.print("Shunt Voltage2: "); Serial.print(shuntvoltage_2); Serial.println(" mV");
  Serial.print("Load Voltage2:  "); Serial.print(loadvoltage_2); Serial.println(" V");
  Serial.print("Current2:       "); Serial.print(current_mA_2); Serial.println(" mA");
  Serial.print("Power2:         "); Serial.print(power_mW_2); Serial.println(" mW");
  Serial.println("");

    // put your main code here, to run repeatedly:
 float shuntvoltage_3 = 0;// current voltage monitor 1
  float busvoltage_3 = 0;
  float current_mA_3 = 0;
  float loadvoltage_3 = 0;
  float power_mW_3 = 0;

  shuntvoltage_3 = ina219_C.getShuntVoltage_mV();
  busvoltage_3 = ina219_C.getBusVoltage_V();
  current_mA_3 = ina219_C.getCurrent_mA();
  power_mW_3 = ina219_C.getPower_mW();
  loadvoltage_3 = busvoltage_3 + (shuntvoltage_3 / 1000);
 
  Serial.print("Bus Voltage3:   "); Serial.print(busvoltage_3); Serial.println(" V");
  Serial.print("Shunt Voltage3: "); Serial.print(shuntvoltage_3); Serial.println(" mV");
  Serial.print("Load Voltage3:  "); Serial.print(loadvoltage_3); Serial.println(" V");
  Serial.print("Current3:       "); Serial.print(current_mA_3); Serial.println(" mA");
  Serial.print("Power3:         "); Serial.print(power_mW_3); Serial.println(" mW");
  Serial.println("");
delay(3000);
 
 if (Serial.available () )
{
char state = Serial.read();
 
 
  if (state=='H' || state=='h') // switch 1 on and off control
   {
    digitalWrite(switch_1, HIGH);
    Serial.println("Switch 1 ON");
   }
   if (state=='L' || state=='l')
   {
    digitalWrite(switch_1, LOW);
    Serial.println("Switch 1 OFF");
   }


   if (state=='W' || state=='w') // switch 2 on and off control
   {
    digitalWrite(switch_2, HIGH);
    Serial.println("switch 2 ON");
   }

   if (state=='E' || state=='e')
   {
    digitalWrite(switch_2, LOW);
    Serial.println("switch 2 OFF");
   }


   if (state=='A' || state=='a') // switch 3 on and off control
   {
    digitalWrite(switch_3, HIGH);
    Serial.println("switch 3 ON");
   }

   if (state=='S' || state=='s')
   {
    digitalWrite(switch_3, LOW);
    Serial.println("switch 3 OFF");
   }
}
}
Last edited by adafruit_support_bill on Wed Jul 17, 2019 10:51 am, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

criton07
 
Posts: 15
Joined: Wed Jul 17, 2019 9:40 am

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed Jul 17, 2019 10:54 am

What is the output you are getting? Please post a sample.
What is the output you are expecting?

Also please show how you have things wired.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple INA219 Current Sensors

by criton07 on Wed Jul 17, 2019 2:43 pm

hi there, when i switch on one mosfet all the three ina219 has the same value. I think the ina219 in that line should only change the value

criton07
 
Posts: 15
Joined: Wed Jul 17, 2019 9:40 am

Re: Multiple INA219 Current Sensors

by criton07 on Wed Jul 17, 2019 2:55 pm


criton07
 
Posts: 15
Joined: Wed Jul 17, 2019 9:40 am

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed Jul 17, 2019 3:24 pm

hi there, when i switch on one mosfet all the three ina219 has the same value.

Per your diagram, the bus and load voltages should be the same. This is consistent with the output.
The shunt voltages and calculated power are different between the 3 sensors. Since we don't know what the load is, it is hard to guess whether it is correct or not.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple INA219 Current Sensors

by criton07 on Wed Jul 17, 2019 5:44 pm

thank you...

what do you think about the code?
Is everything okay with code?

criton07
 
Posts: 15
Joined: Wed Jul 17, 2019 9:40 am

Re: Multiple INA219 Current Sensors

by adafruit_support_bill on Wed Jul 17, 2019 6:24 pm

I don't see any obvious issues with the code.

adafruit_support_bill
 
Posts: 77907
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.