Erroneous gyro readings from 9 DoF Razor IMU M0

Hi all,

In using an Arduino Uno to interface with the 9DoF Razor IMU M0 over the I2C bus, I’m finding that occasionally I get erroneous readings from the gyro. When the gyro is stationary, an excerpt from the Arduino serial monitor is as follows:

Pitch: -1.06 Roll: -1.47 Yaw: 0.23

Pitch: -1.09 Roll: -1.40 Yaw: 0.22

Pitch: -123.51 Roll: -46.56 Yaw: -156.27

Pitch: -1.11 Roll: -1.45 Yaw: 0.17

Pitch: -0.98 Roll: -1.47 Yaw: 0.20

Pitch: -1.14 Roll: -1.46 Yaw: 0.19

Pitch: -1.14 Roll: -1.44 Yaw: 0.17

Pitch: -1.11 Roll: -1.40 Yaw: 0.18

Pitch: -123.51 Roll: -46.56 Yaw: -156.27

Pitch: -1.05 Roll: -1.40 Yaw: 0.21

Pitch: -1.06 Roll: -1.37 Yaw: 0.23

You can see that occasionally a grossly incorrect reading of “Pitch: -123.51 Roll: -46.56 Yaw: -156.27” is provided.

I’ve also tried printing out the contents of the WHOAMI register, and occasionally get a value of 192 (decimal) rather than the correct value.

I’ve soldered female headers to the I2C ‘pins’ on the IMU, and have the SDA and SCL pins connected via jumpers to the pins on the Uno labelled SDA and SCL (along with Vcc and Gnd connections).

I’ll put the full Arduino code listing to read the contents of the gyro register in the next post since I don’t seem to have enough room here . Can I please trouble someone who has the IMU and a Uno to try this code and let me know how it goes? That was I can hopefully determine whether it is an issue with the IMU, or something to do with my setup, e.g. grounding, etc.

Or if anyone has any suggestions for resolving this I would be incredibly grateful.

For some reason the opening and closing braces for functions and the if-statement are not permitted, but it’s fairly obvious where they need to be added.

#include <Wire.h>

int IMU_Address = 104; //decimal conversion of B1101000
int8_t X0, X2, X4 = 0;
uint8_t X1, X3, X5 = 0;
byte gyro_mask = B00000000;
float gyro_pitch, gyro_roll, gyro_yaw = 0;

#define GYRO_CONFIG 0x1B //Hex address of gyro config register
#define GYRO_XOUT_H 0x43 //Starting register of gyro readings
#define XG_OFFSET_H 0x13

void setup() 
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(IMU_Address);
  Wire.write(GYRO_CONFIG);
  Wire.write(gyro_mask);
  Wire.endTransmission();


void loop() 
  read_gyro();
  gyro_pitch /= 131;
  gyro_roll /= 131;
  gyro_yaw /= 131;

  Serial.print("Pitch: ");
  Serial.print(gyro_pitch);
  Serial.print("\t");

  Serial.print("Roll: ");
  Serial.print(gyro_roll);
  Serial.print("\t");

  Serial.print("Yaw: ");
  Serial.println(gyro_yaw);

  delay(100);



void read_gyro()
  Wire.beginTransmission(IMU_Address);
  Wire.write(GYRO_XOUT_H);
  Wire.endTransmission();
  Wire.requestFrom(IMU_Address, 6);

  if(Wire.available() <= 6)
    X0 = Wire.read();
    X1 = Wire.read();

    X2 = Wire.read();
    X3 = Wire.read();

    X4 = Wire.read();
    X5 = Wire.read();
 

  gyro_pitch = X0 << 8 | X1;
  gyro_roll = X2 << 8 | X3;
  gyro_yaw = X4 << 8 | X5;

Do you experience the same errors when using the library provided function to sample data and returned the scaled value?

myICM.getAGMT();

myICM.gyrX();

myICM.gyrY();

myICM.gyrZ();

I have to confess that I think I’ve made an embarrassing mistake that likely is causing this issue.

The only power supply to the Razor in my configuration was from the 3.3v (and ground return) pins on the Arduino, connected to the respective pins adjacent to the I2C SDA and SCL pins. Neither a USB nor Lipo supply was connected to the board.

When I connected a 5V 1A USB supply to the board (in addition to the 3.3V and Gnd), everything seemed to work fine.

I’d like to test this a bit more, and check out how much current the 3.3V rail on the Arduino can supply, and how much the Razor requires, but so far it seems like this could be the issue.

Sorry for wasting your time on this, but is very much appreciated.

And I have made another slightly embarrasing mistake… I saw 9DoF and immediately concluded that you meant the 9DoF ICM-20948. Sorry! I’m not very familiar with the Razor but a brownout seems like a plausible cause. Let us know what you find out!