Using an IMU ICM020948 with Multiplexer

I am new to programming and the Project I am working on involves the use of Arduino with several different sensors. At the moment the sensors I am using are the Sparkfun Qwiic Distance Sensor - VL53L1X and the SparkFun Qwiic 9DoF IMU Breakout - ICM-20948 coupled with a Multiplexer.

I am also implementing the programs using a OOP feature so I can gather together all of the state variables and functionality into a C++ class. This is based on the Adafruit Blink Without delay example. This will enable me to easily add more sensors when the Project develops.

I have got the program working for the VL53L1X, but it won’t work for the ICM-20948.

The error reads:

cannot convert 'ICM_20948_AGMT_t' to 'float' in assignment
and occurs at the line:

angle[x] = myICM[x]-> getAGMT();

I am not sure but believe this maybe due to the output from the sensor being a number of data sets (ie accY, accX, Accz etc) rather than just the one for the VL53L1X (you only have the distance measurement)

If you think you can get the code to work, give me your best price.

The code I have is

  Program to use x number of Sparkfun IMU with a Mux.

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

#include "I2Cdev.h"
#include "MPU6050.h"

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


ICM_20948_I2C **myICM;            // Create pointer to a set of pointers to the sensor class

#define SERIAL_PORT Serial

#define WIRE_PORT Wire            // Your desired Wire port.      
#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

class IMU
    // Class Member Variables
    // These are initialized at startup

    float angle[NUMBER_OF_IMU_SENSORS];  // For use with pointers

    unsigned long eventInterval;
    unsigned long previousTime;

    // Constructor - creates a Flasher
    // and initializes the member variables and state 
    IMU(int interval)
      eventInterval = interval;

    void Update()
      for (byte x = 0; x < NUMBER_OF_IMU_SENSORS; x++)   //  For use with Mux
        /* Updates frequently */
        unsigned long currentTime = millis();
        /* This is the event */
        if (currentTime - previousTime >= eventInterval) {
          /* Event code */
          myMux.setPort(x);                  // Tell mux to connect to this port, and this port only

          angle[x] = myICM[x]-> getAGMT(&ax1);      // Get the result of the measurement from the sensor

          /* Update the timing for the next time around */
          previousTime = currentTime;


IMU angle(10);

void setup()
  //  Setup program

  myICM.begin(WIRE_PORT, AD0_VAL);

  myICM.enableDebugging(); // Enable helpful debug messages on Serial

  //Create set of pointers to the class
  myICM = new ICM_20948_I2C *[NUMBER_OF_IMU_SENSORS];

  //Assign pointers to instances of the class
  for (int x = 0; x < NUMBER_OF_IMU_SENSORS; x++)
    myICM[x] = new ICM_20948_I2C(WIRE_PORT);

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

  byte currentPortNumber = myMux.getPort();
  Serial.print("CurrentPort: ");

  bool initialized = true;

  for (byte x = 0; x < NUMBER_OF_IMU_SENSORS; x++)
    if (myICM[x]->begin() != 0) //Begin returns 0 on a good init
      Serial.print("Sensor ");
      Serial.println(" did not begin! Check wiring");
      initSuccess = false;
      Serial.print("Sensor ");
      Serial.println(" configured");

  if (initSuccess == false)
    while (1);

  Serial.println("Mux Shield online");

void loop()


Hi @andrewheron,

I just looked through the Spark-fun library for the ICM-20948 and you're not using the library correctly. Did you write this code? Or copy parts from other people?