Can't read data from ITG-3200 Gyro

I'm trying to read data from a ITG-3200 Gyro. It's configured such that it uses 0xD0 for write and 0xD1 for read. The code that I'm trying to get to read something from it with is as follows:

#include <Wire.h>

#define DEVICE (0xD1)    //device address
#define TO_READ (6)        //num of bytes we are going to read each time (two bytes for each axis)

byte buff[TO_READ] ;    //6 bytes buffer for saving data read from the device
char str[512];                      //string buffer to transform data before sending it to the serial port

void writeTo(int device, byte address, byte val) 
  {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        // send register address
  Wire.write(val);        // send value to write
  Wire.endTransmission(); //end transmission
  } // end of writeTo
 
void readFrom(int device, byte address, int num, byte buff[]) 
  {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission
  
  Wire.requestFrom(device, num);    // request 6 bytes from device
  
  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
    { 
    buff[i] = Wire.read(); // receive a byte
    i++;
    }
  }  // end of readFrom

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output  
}

void loop()
{
  int regAddress = 0x27;    
  int x, y, z;
  
  readFrom(DEVICE, regAddress, TO_READ, buff); 
  
  x = (((int)buff[1]) << 8) | buff[0];   
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];
  
  sprintf(str, "%d %d %d", x, y, z);  
  Serial.write(str);
  Serial.write(byte(10));
  
  delay(15);
}  // end of loop

This code is the result of chopping and changing others, I must be missing something important, the only result i'm getting on my serial monitor is lines of 0 0 0
The data manual for the sensor is here: http://www.sparkfun.com/datasheets/Sensors/Gyro/PS-ITG-3200-00-01.4.pdf

Thanks in advance (and sorry I'm a bit of a noob :))

The low-order read/write bit in the address byte is provided by the library. Try using 0x60 for the address.

Thanks for the suggestion john. I've tried altering #define DEVICE (0xD1) to #define DEVICE (0x60) but it doesn't seem to have worked.

I should mention that the device is on this break out board with the ADXL345 http://www.sparkfun.com/products/10121 . I've managed to get the accelerometer communicating, but it seems I'm doing something wrong with the gyro :slight_smile:

Did you try the library in the tutorial they point to?

http://bildr.org/2012/03/stable-orientation-digital-imu-6dof-arduino/

I have. It works well, but the problem is I don't understand what's going on in alot of that and I'd rather learn something for myself than recycle code.

I also want to process the data myself; the free IMU library they use does that, but what I want to do is take the raw data out and dump it into MATLAB to look at the affects of applying different signal processing techniques on it.

Whitworth:
I have. It works well, but the problem is I don't understand what's going on in alot of that and I'd rather learn something for myself than recycle code.

I also want to process the data myself; the free IMU library they use does that, but what I want to do is take the raw data out and dump it into MATLAB to look at the affects of applying different signal processing techniques on it.

You should look at the library to see how they do things. Compare the library to the datasheet. See what commands are being send and figure out why. Then you can write your own code with an expectation that you know enough to get the data you want.

johnwasser:
You should look at the library to see how they do things. Compare the library to the datasheet. See what commands are being send and figure out why. Then you can write your own code with an expectation that you know enough to get the data you want.

Unfortunately I've tried this approach and it isn't working. I'm seeing addresses that are being referenced that don't exist as inputs on the sensors. Trying to muddle my way through this code to learn is only leading to lots of assumptions that are all failing.