Measure angle with AltIMU-10 v5

Hi everyone,

I have an altIMU-10 v5 and I would like to measure the angle of my robot with it (to make nearly perfect 90° turns).
I got it working with the Arduino AHRS code, but I don’t understand how it works. I would like to get the z-axis-values in degrees. There are almost no tutorials on internet for this sensor so I’m looking for help here.

This is what I had so far (but it isn’t even close to working).
Maybe it’s easier to do it with the magnetometer but I don’t know how to use it.

Thanks in advance.

#include <Wire.h>
#include <LSM6.h>

LSM6 imu;
int tijd, gyro_x_cal, gyro_y_cal, gyro_z_cal;
float graden;
char report[80];

void setup()

  if (!imu.init())
    Serial.println("Failed to detect and initialize IMU!");
    while (1);
  tijd = millis();
  for (int calGyro = 0; calGyro < 2000; calGyro++) {;     
    snprintf(report, sizeof(report), "A: %6d %6d %6d    G: %6d %6d %6d", imu.a.x, imu.a.y, imu.a.z, imu.g.x, imu.g.y, imu.g.z);
    gyro_x_cal += imu.a.x;
    gyro_y_cal += imu.a.y;
    gyro_z_cal += imu.a.z;
  gyro_x_cal /= 2000;
  gyro_y_cal /= 2000;
  gyro_z_cal /= 2000;

void loop()

  snprintf(report, sizeof(report), "A: %6d %6d %6d    G: %6d %6d %6d",
    imu.a.x, imu.a.y, imu.a.z,
    imu.g.x, imu.g.y, imu.g.z);
  imu.a.x -= gyro_x_cal;
  imu.a.y -= gyro_y_cal;
  imu.a.z -= gyro_z_cal;
//  graden = ((imu.a.z) * (millis() - tijd) * 0.001) / 8.75;
// 0.00006855 = 1/1660/8.75 because the sensor is running at 1660 Hz (got this from the LSM6.cpp file in the library) and 8.75 from the datasheet (stands by the 245 dps (also got this from the LSM6.cpp file) angular rate sensitivity)
  graden += imu.a.z * 0.00006885;;
//  Serial.print(report);
  Serial.print("   ");
//  delay(100);

imu.a.x, etc. are the accelerometer data, and have nothing to do with the gyro data.

Your only options are to simply use the AHRS code, or to take the time to learn how IMUs actually work. One place to start learning (among many others) is here:

Thanks for your reply.

And what about the magnetometer?

You can make a compass using the magnetometer, however it must be carefully calibrated to be useful, and may not work if your robot is near iron-containing or magnetic materials.

See this post: Correcting the Balboa magnetometer