microrobotics

LSM6DS3 Arduino Code Sample

Jun 14th, 2017
3,218
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Based on Sparkfun LSM6DS3 Arduino Library
  2. // More info - https://goo.gl/x71qto
  3. // Sparfun product Code : https://www.sparkfun.com/products/13339
  4.  
  5. #include "SparkFunLSM6DS3.h"
  6. #include "Wire.h"
  7. #include "SPI.h"
  8.  
  9. //Create a instance of class LSM6DS3
  10. LSM6DS3 myIMU( I2C_MODE, 0x6A );  //I2C device address 0x6A
  11.  
  12. void setup() {
  13.   // put your setup code here, to run once:
  14.   Serial.begin(9600);  
  15.   //Call .begin() to configure the IMUs
  16.   if( myIMU.begin() != 0 )
  17.   {
  18.       Serial.println("Device error");
  19.   }
  20.   else  
  21.   {
  22.       Serial.println("Device OK!");
  23.   }
  24. }
  25.  
  26. void loop()
  27. {
  28.   //Accelerometer
  29.   Serial.print("\nAccelerometer:\n");
  30.   Serial.print(" X1 = ");
  31.   Serial.println(myIMU.readFloatAccelX(), 4);
  32.   Serial.print(" Y1 = ");
  33.   Serial.println(myIMU.readFloatAccelY(), 4);
  34.   Serial.print(" Z1 = ");
  35.   Serial.println(myIMU.readFloatAccelZ(), 4);
  36.  
  37.   //Gyroscope
  38.   Serial.print("\nGyroscope:\n");
  39.   Serial.print(" X1 = ");
  40.   Serial.println(myIMU.readFloatGyroX(), 4);
  41.   Serial.print(" Y1 = ");
  42.   Serial.println(myIMU.readFloatGyroY(), 4);
  43.   Serial.print(" Z1 = ");
  44.   Serial.println(myIMU.readFloatGyroZ(), 4);
  45.  
  46.   //Thermometer  
  47.   Serial.print("\nThermometer:\n");
  48.   Serial.print(" Degrees C1 = ");
  49.   Serial.println(myIMU.readTempC(), 4);
  50.   Serial.print(" Degrees F1 = ");
  51.   Serial.println(myIMU.readTempF(), 4);
  52.  
  53.   delay(1000);
  54. }
RAW Paste Data