๐Ÿ“ฃ๐Ÿ“ช ๐Ÿšš Adafruit will not be shipping USPS orders Monday January 20, 2020 ๐Ÿ—“. Expedited USPS orders placed after 11am ET ๐Ÿ•š Friday January 17 will go out Tuesday January 21 ๐Ÿ“ฃ๐Ÿ“ช๐Ÿšš
0

using multiple INA219 in a circuit
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

using multiple INA219 in a circuit

by criton07 on Wed Jul 17, 2019 11:05 am

hi there, I'am a newbie to arduino and circuits. I am using 3 ina219 in a circuit to measure current and voltage. i have gone through the adafruit ina219 datasheet.

My circuit consists of 3 mosfets which acts as electronic switches and is connected to 3 leds the each of the leds are further connected to ina219s respectively.the switches are turned on serially if i turn on mosfet 1(switch 1) all the ina219 gives out same values. please help me out..... the code used 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");
   }
}
}

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

Re: using multiple INA219 in a circuit

by adafruit_support_bill on Wed Jul 17, 2019 11:15 am

Please do not double post: viewtopic.php?f=25&t=117005#p760590

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

Please be positive and constructive with your questions and comments.