Hi everyone!
Im using the arduno nano Every with a qwiic shield connected to SparkFun Qwiic Mux Breakout with two SparkFun 9DoF IMUs - ICM-20948:
And my problem is that using the following code, I can’t seem to address the second IMU and I get none readings (all zeros).
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);
}
}
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!