#include "LSM6DSOXSensor.h"
LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire, LSM6DSOX_I2C_ADD_L);
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000);
lsm6dsoxSensor.begin();
if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_G() == LSM6DSOX_OK) {
Serial.println("Success enabling accelero and gyro");
} else {
Serial.println("Error enabling accelero and gyro");
}
uint8_t id;
lsm6dsoxSensor.ReadID(&id);
if (id != LSM6DSOX_ID) {
Serial.println("Wrong ID for LSM6DSOX sensor. Check that device is plugged");
} else {
Serial.println("Receviced correct ID for LSM6DSOX sensor");
}
lsm6dsoxSensor.Set_X_FS(2);
lsm6dsoxSensor.Set_G_FS(125);
lsm6dsoxSensor.Set_X_ODR(208.0f);
lsm6dsoxSensor.Set_G_ODR(208.0f);
}
void loop() {
// Read accelerometer
uint8_t acceleroStatus;
lsm6dsoxSensor.Get_X_DRDY_Status(&acceleroStatus);
if (acceleroStatus == 1) { // Status == 1 means a new data is available
int32_t acceleration[3];
lsm6dsoxSensor.Get_X_Axes(acceleration);
// Plot data for each axis in mg
Serial.print("AccelerationX="); Serial.print(acceleration[0]); Serial.print("mg, AccelerationY="); Serial.print(acceleration[1]); Serial.print("mg, AccelerationZ="); Serial.print(acceleration[2]); Serial.println("mg");
}
// Read gyroscope
uint8_t gyroStatus;
lsm6dsoxSensor.Get_G_DRDY_Status(&gyroStatus);
if (gyroStatus == 1) { // Status == 1 means a new data is available
int32_t rotation[3];
lsm6dsoxSensor.Get_G_Axes(rotation);
// Plot data for each axis in milli degrees per second
Serial.print("RotationX="); Serial.print(rotation[0]); Serial.print("mdps, RotationY="); Serial.print(rotation[1]); Serial.print("mdps, RotationZ="); Serial.print(rotation[2]); Serial.println("mdps");
}
delay(500);
}
#include <MRI.h>
#include "LSM6DSOXSensor.h"
// Declare LSM6DSOX sensor. Sensor address can have 2 values LSM6DSOX_I2C_ADD_L (corresponds to 0x6A I2C address) or LSM6DSOX_I2C_ADD_H (corresponds to 0x6B I2C address)
// On Adafruit lsm6dsox sensor, LSM6DSOX_I2C_ADD_L is the default address
LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire, LSM6DSOX_I2C_ADD_L);
void setup() {
Serial.begin(115200);
Wire.begin();
// Default clock is 100kHz. LSM6DSOX also supports 400kHz, let's use it
Wire.setClock(400000);
// Init the sensor
lsm6dsoxSensor.begin();
// Enable accelerometer and gyroscope, and check success
if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_G() == LSM6DSOX_OK) {
Serial.println("Success enabling accelero and gyro");
} else {
Serial.println("Error enabling accelero and gyro");
}
// Read ID of device and check that it is correct
uint8_t id;
lsm6dsoxSensor.ReadID(&id);
if (id != LSM6DSOX_ID) {
Serial.println("Wrong ID for LSM6DSOX sensor. Check that device is plugged");
} else {
Serial.println("Receviced correct ID for LSM6DSOX sensor");
}
lsm6dsoxSensor.Set_X_FS(2);
lsm6dsoxSensor.Set_G_FS(125);
lsm6dsoxSensor.Set_X_ODR(208.0f);
lsm6dsoxSensor.Set_G_ODR(208.0f);
}
void loop() {
// Read accelerometer
uint8_t acceleroStatus;
lsm6dsoxSensor.Get_X_DRDY_Status(&acceleroStatus);
if (acceleroStatus == 1) { // Status == 1 means a new data is available
int32_t acceleration[3];
lsm6dsoxSensor.Get_X_Axes(acceleration);
// Plot data for each axis in mg
Serial.print("X="); Serial.print(acceleration[0]); Serial.print("mg, Y="); Serial.print(acceleration[1]); Serial.print("mg, Z="); Serial.print(acceleration[2]); Serial.println("mg");
}
// Read gyroscope
uint8_t gyroStatus;
lsm6dsoxSensor.Get_G_DRDY_Status(&gyroStatus);
if (gyroStatus == 1) { // Status == 1 means a new data is available
int32_t rotation[3];
lsm6dsoxSensor.Get_G_Axes(rotation);
// Plot data for each axis in milli degrees per second
Serial.print("X="); Serial.print(rotation[0]); Serial.print("mdps, Y="); Serial.print(rotation[1]); Serial.print("mdps, Z="); Serial.print(rotation[2]); Serial.println("mdps");
}
delay(500);
}