From d57da325063c3b01c4a8301e018306e4934f9d07 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 24 Sep 2022 18:55:10 -0400 Subject: [PATCH] print when I2C devices not present --- cubesatsim/cubesatsim.ino | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index cf3c3a64..2c981d41 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2306,7 +2306,7 @@ void read_ina219() loadvoltage = busvoltage + (shuntvoltage / 1000); if ((debug_mode) || (voltage_read)) { - Serial.print("-X (2 0x41) Voltage: "); + Serial.print("-X (2 0x41) Voltage: "); Serial.print(loadvoltage); Serial.print("V Current: "); Serial.print(current_mA); @@ -2323,7 +2323,7 @@ void read_ina219() loadvoltage = busvoltage + (shuntvoltage / 1000); if ((debug_mode) || (voltage_read)) { - Serial.print("-Y (2 0x44) Voltage: "); + Serial.print("-Y (2 0x44) Voltage: "); Serial.print(loadvoltage); Serial.print("V Current: "); Serial.print(current_mA); @@ -2340,7 +2340,7 @@ void read_ina219() loadvoltage = busvoltage + (shuntvoltage / 1000); if ((debug_mode) || (voltage_read)) { - Serial.print("-Z (2 0x45) Voltage: "); + Serial.print("-Z (2 0x45) Voltage: "); Serial.print(loadvoltage); Serial.print("V Current: "); Serial.print(current_mA); @@ -3011,9 +3011,12 @@ void start_ina219() { #endif sleep(0.1); - i2c_1 = ina219_1_0x40.begin(); // check i2c bus 1 - i2c2 = ina219_1_0x41.begin(); - i2c3 = ina219_1_0x44.begin(); + if (!i2c_1 = ina219_1_0x40.begin()) // check i2c bus 1 + Serial.println("I2C bus 1 0x40 not found"); + if (!i2c2 = ina219_1_0x41.begin()) + Serial.println("I2C bus 1 0x41 not found"); + if (!i2c3 = ina219_1_0x44.begin()) + Serial.println("I2C bus 1 0x44 not found"); // ina219_1_0x45.begin(); i2c_bus1 = i2c1 || i2c2 || i2c3 || i2c4; @@ -3022,12 +3025,16 @@ void start_ina219() { Wire1.setSCL(3); Wire1.begin(); - i2c5 = ina219_2_0x40.begin(&Wire1); // check i2c bus 2 - i2c6 = ina219_2_0x41.begin(&Wire1); - i2c7 = ina219_2_0x44.begin(&Wire1); - i2c8 = ina219_2_0x45.begin(&Wire1); + if (!i2c5 = ina219_2_0x40.begin(&Wire1)) // check i2c bus 2 + Serial.println("I2C bus 2 0x40 not found"); + if (!i2c6 = ina219_2_0x41.begin(&Wire1)) + Serial.println("I2C bus 2 0x41 not found"); + if (!i2c7 = ina219_2_0x44.begin(&Wire1)) + Serial.println("I2C bus 2 0x44 not found"); + if (!i2c8 = ina219_2_0x45.begin(&Wire1)) + Serial.println("I2C bus 2 0x45 not found"); - i2c_bus1 = i2c5 || i2c6 || i2c7 || i2c8; + i2c_bus3 = i2c5 || i2c6 || i2c7 || i2c8; Serial.print("I2C bus 1: "); Serial.print(i2c_bus1);