#include #include #include #include #include LiquidCrystal_I2C lcd(0x27, 16, 2); Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(); sensors_event_t a, m, g, temp; void setupSensor() { // 1.) Set the accelerometer range lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_2G); //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_4G); //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_8G); //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_16G); // 2.) Set the magnetometer sensitivity //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_4GAUSS); lsm.setupMag(lsm.LSM9DS1_MAGGAIN_8GAUSS); //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_12GAUSS); //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_16GAUSS); // 3.) Setup the gyroscope lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_245DPS); //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_500DPS); //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_2000DPS); } void setup() { Serial.begin(9600); while (!Serial) { delay(1); // will pause Zero, Leonardo, etc until serial console opens } Serial.println("LSM9DS1 data read demo"); // Try to initialise and warn if we couldn't detect the chip if (!lsm.begin()) { Serial.println("Oops ... unable to initialize the LSM9DS1. Check your wiring!"); while (1); } Serial.println("Found LSM9DS1 9DOF"); setupSensor(); lcd.init(); lcd.backlight(); } void loop() { lsm.read(); lsm.getEvent(&a, &m, &g, &temp); lcd.setCursor(0, 0); lcd.print("Om X: "); lcd.setCursor(5, 0); lcd.print(g.gyro.x); Serial.print(g.gyro.x); lcd.setCursor(10,0); lcd.print(" rad/s"); lcd.setCursor(0,1); lcd.print("Om Z: "); lcd.setCursor(5, 1); lcd.print(g.gyro.y); lcd.setCursor(10,1); lcd.print(" rad/s"); delay(500); }