IMU (LSM9DS1) Usage (Onboard 33 IOT)

Hi,

I’ve been trying to get this working for a while, but I think I’m missing some fundamental background to get this working. (This is a more specific question, sensor-related, than the one I posted here.)

I am trying to detect various orientations of my Nano 33 IOT board, but I’m struggling getting the right setup. I tried all the axes, and it seems none of them give me 8 different values using the setup in the image below. There always seems to be 2-3 sides that have (within a margin) the same value.

The code I’m using the get the value is below.

// Include onboard Nano 33 IOT IMU
#include <Arduino_LSM6DS3.h>
 
void setup() {
  Serial.begin(9600);
  // start the IMU:
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU");
    // stop here if you can't access the IMU:
    while (true);
  }
}
 
void loop() {
  // values for acceleration &amp; rotation:
  float xAcc, yAcc, zAcc;
  float xGyro, yGyro, zGyro;
 
  // if both accelerometer and gyrometer are ready to be read:
  if (IMU.accelerationAvailable() &&
      IMU.gyroscopeAvailable()) {      
    // read accelerometer and gyrometer:
    IMU.readAcceleration(xAcc, yAcc, zAcc);
    
    // print the results:
    IMU.readGyroscope(xGyro, yGyro, zGyro);
    /Serial.print(xGyro);
    Serial.print(",");
    Serial.print(yGyro);
    Serial.print(",");
    Serial.print(zGyro);
    Serial.print(",");
    Serial.print(xAcc);
    Serial.print(",");
    Serial.print(yAcc);
    Serial.print(",");
    Serial.print(zAcc);
    Serial.print(",");
    Serial.print("\n");
    delay(1000);
  }
}

Am I misunderstanding how the LSM9DS1 IMU works, or am I missing something obvious here?

Thanks for any assistance!

The gyro reports rates of rotation about three axes, which is not likely to be useful in this case.

However, when held still, the accelerometer reports three values, which combined give you the direction of the Earth's gravity. That should be quite useful. You can use it to measure tilt angles by studying this tutorial.