#include <Adafruit_INA219.h>
#define INA219_1_ADDRESS 0x40 // Địa chỉ I2C của INA219 #1
#define INA219_2_ADDRESS 0x41 // Địa chỉ I2C của INA219 #2
#define INA219_3_ADDRESS 0x42 // Địa chỉ I2C của INA219 #3
#define INA219_4_ADDRESS 0x43 // Địa chỉ I2C của INA219 #4
// Khởi tạo các đối tượng INA219
Adafruit_INA219 ina219_1(INA219_1_ADDRESS);
Adafruit_INA219 ina219_2(INA219_2_ADDRESS);
Adafruit_INA219 ina219_3(INA219_3_ADDRESS);
Adafruit_INA219 ina219_4(INA219_4_ADDRESS);
void setup(void){
Serial.begin(9600);
ina219_1.begin();
ina219_2.begin();
ina219_3.begin();
ina219_4.begin();
}
void ReadPin1(){
float shuntvoltage1 = 0;
float busvoltage1 = 0;
float current_mA1 = 0;
float loadvoltage1 = 0;
float power_mW1 = 0;
shuntvoltage1 = ina219_1.getShuntVoltage_mV();
busvoltage1 = ina219_1.getBusVoltage_V();
current_mA1 = ina219_1.getCurrent_mA();
power_mW1 = ina219_1.getPower_mW();
loadvoltage1 = busvoltage1 + (shuntvoltage1/ 1000);
Serial.print("The First Bus Voltage: "); Serial.print(busvoltage1); Serial.println(" V");
Serial.print("The First Shunt Voltage: "); Serial.print(shuntvoltage1); Serial.println(" mV");
Serial.print("The First Load Voltage: "); Serial.print(loadvoltage1); Serial.println(" V");
Serial.print("The First Current: "); Serial.print(current_mA1); Serial.println(" mA");
Serial.print("The FirstPower: "); Serial.print(power_mW1); Serial.println(" mW");
Serial.println("");
delay(2000);
}
void ReadPin2 (){
float shuntvoltage2 = 0;
float busvoltage2 = 0;
float current_mA2 = 0;
float loadvoltage2 = 0;
float power_mW2 = 0;
shuntvoltage2 = ina219_2.getShuntVoltage_mV();
busvoltage2 = ina219_2.getBusVoltage_V();
current_mA2 = ina219_2.getCurrent_mA();
power_mW2 = ina219_2.getPower_mW();
loadvoltage2= busvoltage2 + (shuntvoltage2/ 1000);
Serial.print("The Second Bus Voltage: "); Serial.print(busvoltage2); Serial.println(" V");
Serial.print("The Second Shunt Voltage: "); Serial.print(shuntvoltage2); Serial.println(" mV");
Serial.print("The Second Load Voltage: "); Serial.print(loadvoltage2); Serial.println(" V");
Serial.print("The Second Current: "); Serial.print(current_mA2); Serial.println(" mA");
Serial.print("The Second Power: "); Serial.print(power_mW2); Serial.println(" mW");
Serial.println("");
delay(2000);
}
void ReadPin3 (){
float shuntvoltage3 = 0;
float busvoltage3 = 0;
float current_mA3 = 0;
float loadvoltage3 = 0;
float power_mW3 = 0;
shuntvoltage3 = ina219_3.getShuntVoltage_mV();
busvoltage3 = ina219_3.getBusVoltage_V();
current_mA3 = ina219_3.getCurrent_mA();
power_mW3 = ina219_3.getPower_mW();
loadvoltage3= busvoltage3 + (shuntvoltage3/ 1000);
Serial.print("The Third Bus Voltage: "); Serial.print(busvoltage3); Serial.println(" V");
Serial.print("The Third Shunt Voltage: "); Serial.print(shuntvoltage3); Serial.println(" mV");
Serial.print("The Third Pin Voltage: "); Serial.print(loadvoltage3); Serial.println(" V");
Serial.print("The Third Current: "); Serial.print(current_mA3); Serial.println(" mA");
Serial.print("The Third Pin Power: "); Serial.print(power_mW3); Serial.println(" mW");
Serial.println("");
}
void ReadPin4 (){
float shuntvoltage4 = 0;
float busvoltage4 = 0;
float current_mA4 = 0;
float loadvoltage4 = 0;
float power_mW4 = 0;
shuntvoltage4 = ina219_4.getShuntVoltage_mV();
busvoltage4 = ina219_4.getBusVoltage_V();
current_mA4 = ina219_4.getCurrent_mA();
power_mW4 = ina219_4.getPower_mW();
loadvoltage4 = busvoltage4 + (shuntvoltage4/ 1000);
Serial.print("The Fouth Bus Voltage: "); Serial.print(busvoltage4); Serial.println(" V");
Serial.print("The Fouth Pin Voltage: "); Serial.print(loadvoltage4); Serial.println(" V");
Serial.print("The Fouth Shunt Voltage: "); Serial.print(shuntvoltage4); Serial.println(" mV");
Serial.print("The Fouth Current: "); Serial.print(current_mA4); Serial.println(" mA");
Serial.print("The Fouth Pin Power: "); Serial.print(power_mW4); Serial.println(" mW");
Serial.println("");
}
void loop(void)
{
ReadPin1();
delay(10);
ReadPin2();
delay(10);
ReadPin3();
delay(10);
ReadPin4();
delay(10);
}