I am using 2 x INA260 current, Voltage and Power combination sensors on my project.
I am using the "Adafruit_INA260" Library.
I have 2 x INA260's connected to the same I2C bus and I have no problem addressing and reading the sensors together for about 70 readings, then it hangs!
I have one at address 0x40 and the other is 0x41.
I have the "ina260.begin(0x40)" and "ina260.begin(0x41)" in the main loop. As I have no idea how else I can address and read each sensor, so they must be in the main loop, or in my case in a function called from the main loop. This seems to be the problem.
If I simply start the sensor in the "SETUP" before the main loop and only read the sensor in the main loop it works fine, but if I place the "ina260.begin()" in the main loop it will hang after a period of reads. Approx 130 if just the one "ina260.begin()" statement or about 70 with 2 x "ina260.begin()" statements.
It is as if there is some sort of a buffer overrun or call to "ina260.begin()" limit before the INA260 spits the dummy and hangs.
#include <Adafruit_INA260.h>
#include <Adafruit_SleepyDog.h>
Adafruit_INA260 ina260 = Adafruit_INA260();
void setup()
{
Serial.begin(115200);
// Wait until serial port is opened
while (!Serial) { delay(10); }
Serial.println("Adafruit INA260 Test");
int countdownMS = Watchdog.enable(4000);
if (!ina260.begin(0x40))
{
Serial.println("Couldn't find INA260 chip 1");
}
if (!ina260.begin(0x41))
{
Serial.println("Couldn't find INA260 chip 2");
}
}
void loop()
{
static int loopcnt=0;
//int countdownMS = Watchdog.enable(4000);
if (ina260.begin(0x40))
{
Serial.println("INA260 Address 1:");
Serial.println();
Serial.print("Current: ");
Serial.print(ina260.readCurrent());
Serial.println(" mA");
Serial.print("Bus Voltage: ");
Serial.print(ina260.readBusVoltage());
Serial.println(" mV");
Serial.print("Power: ");
Serial.print(ina260.readPower());
Serial.println(" mW");
Serial.println();
ina260.setMode(INA260_MODE_SHUTDOWN);
delay(1000);
Watchdog.reset();
}
if (ina260.begin(0x41))
{
Serial.println("INA260 Address 2:");
Serial.println();
Serial.print("Current: ");
Serial.print(ina260.readCurrent());
Serial.println(" mA");
Serial.print("Bus Voltage: ");
Serial.print(ina260.readBusVoltage());
Serial.println(" mV");
Serial.print("Power: ");
Serial.print(ina260.readPower());
Serial.println(" mW");
Serial.println();
ina260.setMode(INA260_MODE_SHUTDOWN);
delay(1000);
Watchdog.reset();
}
loopcnt++;
Serial.println(loopcnt);
Serial.println();
}