Dear all,
I want to output the respective x, y, z-axis acceleration and gyroscope values of IMU (LSM6DSLTR) through I2C communication with arduino uno.
datasheet(https://www.mouser.kr/datasheet/2/389/lsm6dsl-1509291.pdf)
However, as you can see in the picture, all data values are outputted -1 at a constant period of time.
Arduino's current I2C communication speed is 100k Hz, which is standard mode.
I don't know why.
Thank you.
#include <Wire.h>
const int LSM6DSL_ADDR = 0x6A;
void setup() {
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(LSM6DSL_ADDR);
Wire.write(0x10); // CTRL1_XL register
Wire.write(0x50); // 208 Hz, +/-2g, BW =100Hz
Wire.endTransmission();
Wire.beginTransmission(LSM6DSL_ADDR);
Wire.write(0x11); // CTRL2_G regi = 0.96;
Wire.write(0x50); // 208 Hz, 250dps
Wire.endTransmission();
}
void loop() {
Wire.beginTransmission(LSM6DSL_ADDR); // Read accelerometer and gyroscope values from LSM6DSL
Wire.write(0x22); // Read from OUTX_L_G (gyro) register
Wire.endTransmission();
Wire.requestFrom(LSM6DSL_ADDR, 6, true); //One master > "True" auto
int16_t gyro_x = Wire.read() | (Wire.read() << 8); //0x29 HIGH bit & 0x28 LOW bit
int16_t gyro_y = Wire.read() | (Wire.read() << 8); //0x2B HIGH bit & 0x2A LOW bit
int16_t gyro_z = Wire.read() | (Wire.read() << 8); //0x2D HIGH bit & 0x2C LOW bit
Wire.beginTransmission(LSM6DSL_ADDR);
Wire.write(0x28); // Read from OUTX_L_XL (accel) register
Wire.endTransmission();
Wire.requestFrom(LSM6DSL_ADDR, 6, true);
int16_t acc_x = Wire.read() | (Wire.read() << 8);
int16_t acc_y = Wire.read() | (Wire.read() << 8);
int16_t acc_z = Wire.read() | (Wire.read() << 8);
Serial.print(gyro_x);
Serial.print(" ");
Serial.print(gyro_y);
Serial.print(" ");
Serial.print(gyro_z);
Serial.print(" ");
Serial.print(acc_x);
Serial.print(" ");
Serial.print(acc_y);
Serial.print(" ");
Serial.println(acc_z);
}
