help to read register from LSM6DSO32 i2C
Hi,
I have one LSM6DSO32 with an Atmel SAMD21 Cortex M0. I use i2c to comunicate with the sensor. I use Arduino ide and Arduino librarys Wire for i2C communication.
I've read the datasheet first of all I set some registers of my sensor I set gyro to 500° et accel to 8g
//gyro 500°
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x11);
Wire.write(0x54);
Wire.endTransmission();
//accel 8g
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x10);
Wire.write(0x58);
Wire.endTransmission();DSO_ADDRESS is define by 0x6A. So I think everything works beceause if I try to read 0x11 after I set the value 0x54 I get this value :grinning_face:
My problem comes when I want to read raw data from gyro and accel, I do that :
//global variables
int raw_temperature = 0;
int gyro_raw[3] = {0, 0, 0};
int acc_raw[3] = {0, 0, 0};
//some codes here
void readSensor(){
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x20);
Wire.endTransmission();
Wire.requestFrom(DSO_ADDRESS, 14);
uint8_t buff[14];
Wire.readBytes(buff, 14);
raw_temperature = buff[1] << 8 | buff[0];
gyro_raw[X] = buff[3] << 8 | buff[2];
gyro_raw[Y] = buff[5] << 8 | buff[4];
gyro_raw[Z] = buff[7] << 8 | buff[6];
acc_raw[X] = buff[9] << 8 | buff[8];
acc_raw[Y] = buff[11] << 8 | buff[10];
acc_raw[Z] = buff[13] << 8 | buff[12];
}X, Y and Z are defines by 0, 1 and 2.
This is in a function called readSensor. If I called this function 1000 times to get offset from gyro I got some strange values
//global variables
int gyro_offset[3] = {0, 0, 0};
//in my main function
for(int i = 0; i < 2000; i++){
readSensor();
gyro_offset[X] += gyro_rax[X];
gyro_offset[Y] += gyro_rax[Y];
gyro_offset[Z] += gyro_rax[Y];
}
gyro_offset[X] /= 2000;
gyro_offset[Y] /= 2000;
gyro_offset[Z] /= 2000;Here this my problem if I print the result after my for loop, for X I got 23-30 (for me this is good) but for Y and Z I got a big value something like 65515 or 65521, and for me these values aren't good no? Do you think I missed something ?
For information, if I read Who I am register 0xF I got good value 0x6C
