Arduino nano using Qwiic MUX + Multiple IMU sensors

Hi everyone!

Im using the arduno nano Every with a qwiic shield:

Connect to SparkFun Qwiic Mux Breakout:

With two SparkFun 9DoF IMUs - ICM-20948:

And my problem is that using the following code, I only get a few lines of data printed showing the measurement of the two IMUS before it stops (or 'freeze') for a reason I can't figure out:

My code:

#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
#include <Wire.h>
#define Serial Serial

#include <SparkFun_I2C_Mux_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_I2C_Mux
QWIICMUX myMux;

#define AD0_VAL 1      // The value of the last bit of the I2C address.                \
                       // On the SparkFun 9DoF IMU breakout the default is 1, and when \
                       // the ADR jumper is closed the value becomes 0

ICM_20948_I2C myICM; // Create an ICM_20948_I2C object


void setup()
{

  Serial.begin(115200);
  while (!Serial)
  {
  };

  Wire.begin();
  Wire.setClock(400000);

  if (myMux.begin() == false)
  {
    Serial.println("Mux not detected. Freezing...");
    while (1);
  }
  Serial.println("Mux detected");

  myMux.setPort(0);
  
  bool initialized = false;
  while (!initialized)
  {
    myICM.begin(Wire, AD0_VAL);

    Serial.print(F("Initialization of the sensor returned: "));
    Serial.println(myICM.statusString());
    if (myICM.status != ICM_20948_Stat_Ok)
    {
      Serial.println("Trying again...");
      delay(500);
    }
    else
    {
      initialized = true;
    }
  }
}

void loop()
{

  if (myICM.dataReady())
  {
    myMux.setPort(0);
    myICM.getAGMT();         // The values are only updated when you call 'getAGMT'                 
    Serial.println("IMU 0");
    printScaledAGMT(&myICM); // This function takes into account the scale settings from when the measurement was made to calculate the values with units
    delay(50);

    myMux.setPort(1);
    myICM.getAGMT();         // The values are only updated when you call 'getAGMT'                 
    Serial.println("IMU 1");
    printScaledAGMT(&myICM); // This function takes into account the scale settings from when the measurement was made to calculate the values with units
    delay(50);
    myMux.setPort(0);
   }
  else
  {
    Serial.println("Waiting for data");
    delay(500);
  }
}

a_Print_Formated.ino (652 Bytes)
a_PrintPaddedInt.ino (666 Bytes)
a_Raw.ino (744 Bytes)
a_Scaled.ino (841 Bytes)
Example_IMU.ino (2.5 KB)

I noticed that when using just 1 IMU by commenting the lines:

myMux.setPort(1);
myICM.getAGMT();         // The values are only updated when you call 'getAGMT'                 
Serial.println("IMU 1");
printScaledAGMT(&myICM); // This function takes into account the scale settings from when the measurement was made to calculate the values with units
delay(50);
myMux.setPort(0);

I get good constant readings for that 1 IMU.

What am I doing wrong?

Thanks!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.