I have a problem in connecting 2 INA226 modules with I2C protocol. In the project will have 4 INA226 modules each of which has a different power supply (12V, 5V, 5V USB and 3.3V). I am attaching the wiring diagram of all 4. At the moment, however, I tried only a connection of 2 of these modules to see in the meantime if the Arduino code worked (if it works for 2 it also works for 4) .... but it doesn't work I found the i2c addresses with the I2C Scan code and then corrected them (one is the default (0x40) the other 0x45). Can you help me? I am attaching both the Arduino INO code and the wiring diagram.
Arduino Code
/* 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 <Wire.h> #include <INA226.h> INA226 ina_5V; INA226 ina_3.3V; 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(0x40); ina_3.3V.begin(0x45); // 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.100, 4); ina_3.3V.calibrate(0.100, 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); }
It's rather seldom to see such a comprehensive description of what went wrong. So my help is about as useful: fix it, it's either the hardware or the software.
No, maybe I wasn't clear ... the code doesn't work. It's not really loaded on arduino. If you want me to post the trick of all the errors that come out ok, but I thought that maybe an expert in the code looking at it can tell me things and where I was wrong to compile. However I will list below the errors I get when I try to load the sketch
MODULO_INA226__PROVA_MULTIPLI:13: error: expected initializer before numeric constant INA226 ina_3.3V; ^ C:\Users\Paolo\Desktop\Progetto Alimentatore\MODULO_INA226__PROVA_MULTIPLI\MODULO_INA226__PROVA_MULTIPLI.ino: In function 'void checkConfig()': MODULO_INA226__PROVA_MULTIPLI:35: error: 'ina_3' was not declared in this scope Serial.print(ina_3.3V.getMaxPossibleCurrent()); ^ MODULO_INA226__PROVA_MULTIPLI:39: error: expected ')' before numeric constant Serial.print(ina_3.3V.getMaxCurrent()); ^ MODULO_INA226__PROVA_MULTIPLI:43: error: expected ')' before numeric constant Serial.print(ina_3.3V.getMaxShuntVoltage()); ^ MODULO_INA226__PROVA_MULTIPLI:47: error: expected ')' before numeric constant Serial.print(ina_3.3V.getMaxPower()); ^ C:\Users\Paolo\Desktop\Progetto Alimentatore\MODULO_INA226__PROVA_MULTIPLI\MODULO_INA226__PROVA_MULTIPLI.ino: In function 'void setup()': MODULO_INA226__PROVA_MULTIPLI:61: error: 'ina_3' was not declared in this scope ina_3.3V.begin(0x45); ^ MODULO_INA226__PROVA_MULTIPLI:65: error: expected ';' before numeric constant ina_3.3V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT); ^ MODULO_INA226__PROVA_MULTIPLI:70: error: expected ';' before numeric constant ina_3.3V.calibrate(0.1, 4); ^ C:\Users\Paolo\Desktop\Progetto Alimentatore\MODULO_INA226__PROVA_MULTIPLI\MODULO_INA226__PROVA_MULTIPLI.ino: In function 'void loop()': MODULO_INA226__PROVA_MULTIPLI:100: error: 'ina_3' was not declared in this scope Serial.print(ina_3.3V.readBusVoltage(), 2); // valore a 2 cifre decimali ^ MODULO_INA226__PROVA_MULTIPLI:104: error: expected ')' before numeric constant Serial.print(ina_3.3V.readBusPower(), 3); // valore a 3 cifre decimali ^ MODULO_INA226__PROVA_MULTIPLI:109: error: expected ')' before numeric constant Serial.print(ina_3.3V.readShuntVoltage(), 5); ^ MODULO_INA226__PROVA_MULTIPLI:113: error: expected ')' before numeric constant Serial.print(ina_3.3V.readShuntCurrent(), 4); // valore a 3 cifre decimali ^ Uso la libreria Wire alla versione 1.0 nella cartella: C:\Users\Paolo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\libraries\Wire Uso la libreria Arduino-INA226-master nella cartella: C:\Users\Paolo\Documents\Arduino\libraries\Arduino-INA226-master (legacy) exit status 1 expected initializer before numeric constant
That was the mistake. I called the variable ina_3V3, replaced everywhere and works perfectly !! Thanks a lot!
Now the code is this
/* 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 <Wire.h> #include <INA226.h> INA226 ina_5V; INA226 ina_3V3; 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_3V3.getMaxPossibleCurrent()); Serial.println(" A"); Serial.print("Max current 3.3V: "); Serial.print(ina_3V3.getMaxCurrent()); Serial.println(" A"); Serial.print("Max shunt voltage 3.3V: "); Serial.print(ina_3V3.getMaxShuntVoltage()); Serial.println(" V"); Serial.print("Max power 3.3V: "); Serial.print(ina_3V3.getMaxPower()); Serial.println(" W"); } void setup() { Serial.begin(115200); Serial.println("Initialize INA226"); Serial.println("-----------------------------------------------"); // Default INA226 address is 0x40 ina_5V.begin(0x40); ina_3V3.begin(0x45); // Configure INA226 ina_5V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT); ina_3V3.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_3V3.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.println(""); Serial.print("Bus voltage 3.3V: "); Serial.print(ina_3V3.readBusVoltage(), 2); // valore a 2 cifre decimali Serial.println(" V"); Serial.print("Bus power 3.3V: "); Serial.print(ina_3V3.readBusPower(), 3); // valore a 3 cifre decimali Serial.println(" W"); Serial.print("Shunt voltage 3.3V: "); Serial.print(ina_3V3.readShuntVoltage(), 5); Serial.println(" V"); Serial.print("Shunt current 3.3V: "); Serial.print(ina_3V3.readShuntCurrent(), 4); // valore a 3 cifre decimali Serial.println(" A"); Serial.println(""); Serial.println(""); delay(3000); }
You still feel one thing ... if I wanted to call the reading now ina_5V.readBusVoltage () for example as Voltage_5V and the current reading ina_5V.readShuntCurrent () for example as Current_5V