Pas d'idée pour le reste ?
[Edit : Les valeurs ont encore changé.
t : 23864; x : 12465; y : -9675; z : -3395
À croire qu'il faut chaque fois que j'attende un certain temps... Je comprends vraiment plus rien.
[Edit2 : Mon prof a trouvé... :)
Voici le code dans sa version actuelle :
// I2C library, gyroscope
#define GYRO_ADDR 0x68 // gyro address, binary = 110100x when AD0 is connected to Vcc (see schematics of your breakout board)
#define SMPLRT_DIV 0x15
#define DLPF_FS 0x16
#define INT_CFG 0x17
#define PWR_MGM 0x3E
#define TO_READ 8 // 2 bytes for each axis x, y, z
// offsets are chip specific.
int offx = 120;
int offy = 20;
int offz = 93;
//initializes the gyroscope
void initGyro()
{
/*****************************************
* ITG 3200
* power management set to:
* clock select = internal oscillator
* no reset, no sleep mode
* no standby mode
* sample rate to = 125Hz
* parameter to +/- 2000 degrees/sec
* low pass filter = 5Hz
* no interrupt
******************************************/
writeTo(GYRO_ADDR, PWR_MGM, 0x00);
writeTo(GYRO_ADDR, SMPLRT_DIV, 0x07); // EB, 50, 80, 7F, DE, 23, 20, FF
writeTo(GYRO_ADDR, DLPF_FS, 0x1E); // +/- 2000 dgrs/sec, 1KHz, 1E, 19
writeTo(GYRO_ADDR, INT_CFG, 0x00);
}
void getGyroscopeData()
{
/**************************************
Gyro ITG-3200 I2C
registers:
temp MSB = 1B, temp LSB = 1C
x axis MSB = 1D, x axis LSB = 1E
y axis MSB = 1F, y axis LSB = 20
z axis MSB = 21, z axis LSB = 22
*************************************/
int regAddress = 0x1B;
int temp, x, y, z;
byte buff[TO_READ];
char str[50]; // 50 should be enough to store all the data from the gyro
readFrom(GYRO_ADDR, regAddress, TO_READ, buff); //read the gyro data from the ITG3200
temp = (buff[0] << 8) | buff[1];
x = ((buff[2] << 8) | buff[3]) -88;// + offx;
y = ((buff[4] << 8) | buff[5]) -7;// + offy;
z = ((buff[6] << 8) | buff[7]) -5;// + offz;
//we send the x y z values as a string to the serial port
sprintf(str, "t : %d;\t x : %d;\t y : %d;\t z : %d", temp, x, y, z);
Serial.print(str);
Serial.print(10, BYTE);
}
void setup()
{
Serial.begin(9600);
Wire.begin();
initGyro();
}
void loop()
{
getGyroscopeData();
delay(1000);
}
//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device
Wire.send(address); // send register address
Wire.send(val); // send value to write
Wire.endTransmission(); //end transmission
}
//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device); //start transmission to device
Wire.send(address); //sends address to read from
Wire.endTransmission(); //end transmission
Wire.beginTransmission(device); //start transmission to device
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.receive(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
}[/code]
Et vous savez où était le problème ?
À la deuxième ligne...
#define GYRO_ADDR 0x68 // gyro address (...)
Dans le code d'origine, c'était 0x69 donc il y avait juste un problème avec l'adresse du Gyro.
J'suis soulagé ! :p