jarzebski / Arduino-INA226

INA226 Bi-directional Current/Power Monitor Arduino Librar
MIT License
48 stars 46 forks source link

Problem using 2 module INA226 in I2C protocol #8

Open Gagge89 opened 4 years ago

Gagge89 commented 4 years ago

Hi.. I have a problem to use 2 module INA226 with protocol I2C. I write this sketch but it doesn't work. the Arduino IDE give me errors. Can you help me?

`/ INA226 Bi-directional Current/Power Monitor. Simple Example. Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/cyfrowy-czujnik-pradu-mocy-ina226.html GIT: https://github.com/jarzebski/Arduino-INA226 Web: http://www.jarzebski.pl (c) 2014 by Korneliusz Jarzebski /

include

include

INA226 ina_5V; INA226 ina_3.3V(0x45);

void checkConfig() {

Serial.print("Max possible current 5V: "); Serial.print(ina_5V.getMaxPossibleCurrent()); Serial.println(" A");

Serial.print("Max current 5V: "); Serial.print(ina_5V.getMaxCurrent()); Serial.println(" A");

Serial.print("Max shunt voltage 5V: "); Serial.print(ina_5V.getMaxShuntVoltage()); Serial.println(" V");

Serial.print("Max power 5V: "); Serial.print(ina_5V.getMaxPower()); Serial.println(" W");

Serial.print("Max possible current 3.3V: "); Serial.print(ina_3.3V.getMaxPossibleCurrent()); Serial.println(" A");

Serial.print("Max current 3.3V: "); Serial.print(ina_3.3V.getMaxCurrent()); Serial.println(" A");

Serial.print("Max shunt voltage 3.3V: "); Serial.print(ina_3.3V.getMaxShuntVoltage()); Serial.println(" V");

Serial.print("Max power 3.3V: "); Serial.print(ina_3.3V.getMaxPower()); Serial.println(" W");

}

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

Serial.println("Initialize INA226"); Serial.println("-----------------------------------------------");

// Default INA226 address is 0x40 ina_5V.begin(); ina_3.3V.begin();

// Configure INA226 ina_5V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT); ina_3.3V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);

// Calibrate INA226. Rshunt = 0.1 ohm, Max excepted current = 4A ina_5V.calibrate(0.1, 4); ina_3.3V.calibrate(0.1, 4);

// Display configuration checkConfig();

Serial.println("-----------------------------------------------"); }

void loop() { Serial.print("Bus voltage 5V: "); Serial.print(ina_5V.readBusVoltage(), 2); // valore a 2 cifre decimali Serial.println(" V");

Serial.print("Bus power 5V: "); Serial.print(ina_5V.readBusPower(), 3); // valore a 3 cifre decimali Serial.println(" W");

Serial.print("Shunt voltage 5V: "); Serial.print(ina_5V.readShuntVoltage(), 5); Serial.println(" V");

Serial.print("Shunt current 5V: "); Serial.print(ina_5V.readShuntCurrent(), 4); // valore a 3 cifre decimali Serial.println(" A");

Serial.print("Bus voltage 3.3V: "); Serial.print(ina_3.3V.readBusVoltage(), 2); // valore a 2 cifre decimali Serial.println(" V");

Serial.print("Bus power 3.3V: "); Serial.print(ina_3.3V.readBusPower(), 3); // valore a 3 cifre decimali Serial.println(" W");

Serial.print("Shunt voltage 3.3V: "); Serial.print(ina_3.3V.readShuntVoltage(), 5); Serial.println(" V");

Serial.print("Shunt current 3.3V: "); Serial.print(ina_3.3V.readShuntCurrent(), 4); // valore a 3 cifre decimali Serial.println(" A");

Serial.println(""); delay(1000); }`

Rupesh-Jogani commented 3 years ago

Just add the new address in the Header file. You can do that by opening the header file in Notepad by defining the new address You might need to tweak some code in Header as well as CPP file.