I'm using ITG-3200 three axis gyrosocpe for my project(https://learn.sparkfun.com/tutorials/itg-3200-hookup-guide).
I followed the online tutorial step-by-step and uploaded the example code to my arduino pro(5V 16MHz). Here is the code:
char WHO_AM_I = 0x00;
char SMPLRT_DIV= 0x15;
char DLPF_FS = 0x16;
char GYRO_XOUT_H = 0x1D;
char GYRO_XOUT_L = 0x1E;
char GYRO_YOUT_H = 0x1F;
char GYRO_YOUT_L = 0x20;
char GYRO_ZOUT_H = 0x21;
char GYRO_ZOUT_L = 0x22;
char DLPF_CFG_0 = (1<<0);
char DLPF_CFG_1 = (1<<1);
char DLPF_CFG_2 = (1<<2);
char DLPF_FS_SEL_0 = (1<<3);
char DLPF_FS_SEL_1 = (1<<4);
char itgAddress = 0x69;
//Read the WHO_AM_I register and print the result
id = itgRead(itgAddress, 0x00);
itgWrite(itgAddress, DLPF_FS, (DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0));
itgWrite(itgAddress, SMPLRT_DIV, 9);
//Create variables to hold the output rates.
int xRate, yRate, zRate;
//Read the x,y and z output rates from the gyroscope.
xRate = readX();
yRate = readY();
zRate = readZ();
//Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.)
void itgWrite(char address, char registerAddress, char data)
unsigned char itgRead(char address, char registerAddress)
unsigned char data=0;
data = Wire.read();
//Return the data read during the operation
data = itgRead(itgAddress, GYRO_XOUT_H)<<8;
data |= itgRead(itgAddress, GYRO_XOUT_L);
data = itgRead(itgAddress, GYRO_YOUT_H)<<8;
data |= itgRead(itgAddress, GYRO_YOUT_L);
data = itgRead(itgAddress, GYRO_ZOUT_H)<<8;
data |= itgRead(itgAddress, GYRO_ZOUT_L);
The gyroscope and arduino pro were both powered up by 3.3V, and GND were connected together. However, the values for three axis are all 0, it seems that the chip did not work properly. Could anyone help me figure out my problem? :'( :'( :'(
Please use code tags when you show your sketch.
Did you try the i2c_scanner ? http://playground.arduino.cc/Main/I2cScanner (http://playground.arduino.cc/Main/I2cScanner)
Did you write the sketch yourself, or did you find it somewhere ?
There should be no Wire.endTransmission() after Wire.requestFrom() and no Wire.beginTransmission() before it.
Reading a singly byte is a very large overhead.