I would like to read some register from a LSM6DSO32 captor. But I've a problem for me tha values I got are strange. I user Atmel SAMD21 Cortex M0 and i2C for communicate with the captor. First off all I set my captor to 8g and 500° for gyroscope like that
#define DSO_ADDRESS 0x6A
void setup() {
SerialUSB.begin(115200);
while(!SerialUSB);
Wire.begin();
//gyro 500°
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x11);
Wire.write(0x44);
Wire.endTransmission();
//accel 8g
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x10);
Wire.write(0x48);
Wire.endTransmission();
}
For me this is works beceause if I read 0x10 after I get 0x48 value, and if I try to read who i am register I get the good value 0x6C.
After that I try to read registers value, my readSensor function
//gloabl variables to store values
int temperature;
int gyro_raw[3] = {0, 0, 0};
int acc_raw[3] = {0 , 0 , 0};
void readSensor(){
Wire.beginTransmission(DSO_ADDRESS);
Wire.write(0x20);
Wire.endTransmission();
Wire.requestFrom(DSO_ADDRESS, 14);
uint8_t buff[14];
Wire.readBytes(buff, 14);
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];
}
So if I called this function 2000 times for exemple to get an offset I got very strange values
long gyro_offset[3] = {0, 0, 0};
int max_samples = 500;
for (int i = 0; i < max_samples; i++) {
readSensor();
gyro_offset[X] += gyro_raw[X];
gyro_offset[Y] += gyro_raw[Y];
gyro_offset[Z] += gyro_raw[Z];
delay(50);
}
gyro_offset[X] /= max_samples;
gyro_offset[Y] /= max_samples;
gyro_offset[Z] /= max_samples;
X
Y
and Z
are defined by value 0,1 and 2. So if I print gyro_offset[X]
I get value 23 for me this is normal, but for gyro_offset[Y]
and gyro_offset[Z]
I got a big value around 65514 and for me these aren't good no ?