Reading Raw Acceleration data from SparkFun's Razor IMU

Hi all,

I’m fairly new to using microcontrollers, but I’m doing a project where I want to get the yaw, pitch, roll and acceleration data of a component using a Razor IMU. While I will be using an arduino mega eventually to read and process the data, I have for now connected the chip to the computer via a FDTI breakout board.

I’ve been following this tutorial ( from which I’ve been able to get the yaw, pitch and roll readings, but I am having trouble getting the acceleration data I what, which is basically just the ax, ay and az values in m/s2.

The acceleration is read here:

// Reads x, y and z accelerometer registers
void Read_Accel()
  int i = 0;
  byte buff[6];
  WIRE_SEND(0x32);  // Send address to read from
  Wire.requestFrom(ACCEL_ADDRESS, 6);  // Request 6 bytes
  while(Wire.available())  // ((Wire.available())&&(i<6))
    buff[i] = WIRE_RECEIVE();  // Read one byte
  if (i == 6)  // All bytes received?
    // No multiply by -1 for coordinate system transformation here, because of double negation:
    // We want the gravity vector, which is negated acceleration vector.
    accel[0] = (((int) buff[3]) << 8) | buff[2];  // X axis (internal sensor y axis)
    accel[1] = (((int) buff[1]) << 8) | buff[0];  // Y axis (internal sensor x axis)
    accel[2] = (((int) buff[5]) << 8) | buff[4];  // Z axis (internal sensor z axis)
    if (output_errors) Serial.println("!ERR: reading accelerometer");

I thought I could just output the accel values in the output function as shown here:

    Serial.print(TO_DEG(yaw)); Serial.print(",");
    Serial.print(TO_DEG(pitch)); Serial.print(",");
    Serial.print(TO_DEG(roll)); Serial.print(","); // Up to here works fine
    Serial.print(accel[0]); Serial.print(",");
    Serial.print(accel[1]); Serial.print(",");
    Serial.print(accel[2]); Serial.println();

However even when I leave the IMU perfectly still on the desk, I still get very high values for acceleration.

It had occurred to be that the values may be in the wrong form, and tried to scale them by dividing by GRAVITY (256) as is done elsewhere in the code, but this makes the values limited to between about -2 to 2 and I still don’t get zero or virtually zero acceleration when I hold the board still.

Is this the right way both to get acceleration from? Do I need to apply some other transformation/scaling?

Any thoughts are appreciated.



Accelerometers measure the acceleration due to gravity, in addition to those caused by other forces.

You will almost always see about 1 g on any axis pointing up or down.