Sparkfun Razor IMU and ITG3200 - help!

Hi all,

I’m trying to interface with the gyro on the Razor IMU board myself by programming the ATMEGA328 in Arduino (rather than C). I have the code below which, from my understanding, should just configure the gyro and print raw data to serial. However, all it gives me is a constant (-11823) which never changes (garbage data). Any ideas? My code is pasted below and the wiring schematic is as shown here for the board:

#include <Wire.h>

byte gyroWrite = 0xD0;
byte gyroRead = 0xD1;
byte WHO_AM_I = 0x00;
byte SMPLRT_DIV= 0x15;
byte DLPF_FS = 0x16;
byte GYRO_XOUT_H = 0x1D;
byte GYRO_XOUT_L = 0x1E;
byte GYRO_YOUT_H = 0x1F;
byte GYRO_YOUT_L = 0x20;
byte GYRO_ZOUT_H = 0x21;
byte GYRO_ZOUT_L = 0x22;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  
  byte id = i2cRead(gyroRead, WHO_AM_I);
  Serial.print("ID: ");
  Serial.println(id, HEX);
  delay(1000);
  
  i2cWrite(gyroWrite, SMPLRT_DIV, 0x00);
  i2cWrite(gyroWrite, DLPF_FS, 0x18);  
}

void loop() {
  
  int gyroX, gyroY, gyroZ;
  
  gyroX = getGyroX();
  gyroY = getGyroY();
  gyroZ = getGyroZ();
  
  Serial.print(gyroX);
  Serial.print('\t');
  Serial.print(gyroY);
  Serial.print('\t');
  Serial.println(gyroZ);

}

byte i2cRead(byte devAddress, byte devRegister) {
  
  byte data;
  Wire.beginTransmission(devAddress);
  Wire.write(devRegister);
  Wire.endTransmission();
  
  Wire.beginTransmission(devAddress);
  Wire.requestFrom(devAddress, (byte)1);
  while(Wire.available()){
    data = Wire.read();
  }
  
  Wire.endTransmission();
  return data;
}

void i2cWrite(byte devAddress, byte devRegister, byte value) {
  Wire.beginTransmission(devAddress);
  Wire.write(devRegister);
  Wire.write(value);
  Wire.endTransmission();
}

int getGyroX(void) {
  int data;
  data = i2cRead(gyroRead, GYRO_XOUT_H)<<8;
  data |= i2cRead(gyroRead, GYRO_XOUT_L);
  return data;
}

int getGyroY(void) {
  int data;
  data = i2cRead(gyroRead, GYRO_YOUT_H)<<8;
  data |= i2cRead(gyroRead, GYRO_YOUT_L);
  return data;
}

int getGyroZ(void) {
  int data;
  data = i2cRead(gyroRead, GYRO_ZOUT_H)<<8;
  data |= i2cRead(gyroRead, GYRO_ZOUT_L);
  return data;
}

This is my first I2C interface and I haven’t used an Arduino in a while, so I’d appreciate any help you could give me.

Thanks!!

You’re I2C device address are 0xD0 and 0xD1, for write and read, meaning you’ve already bit shifted the 7 bit address 0x68 into a 8 bit address including the R/W bit. But the Wire library expects the original 7-bit address, which is 0x68.

Gah! Thanks so much. 0x68 works.