HighLevelExample.ino 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*****************************************************************************/
  2. // HighLevelExample.ino
  3. // Hardware: Grove - 6-Axis Accelerometer&Gyroscope
  4. // Arduino IDE: Arduino-1.65
  5. // Author: Lambor
  6. // Date: Oct,2015
  7. // Version: v1.0
  8. //
  9. // Modified by:
  10. // Data:
  11. // Description:
  12. //
  13. // by www.seeedstudio.com
  14. //
  15. // This library is free software; you can redistribute it and/or
  16. // modify it under the terms of the GNU Lesser General Public
  17. // License as published by the Free Software Foundation; either
  18. // version 2.1 of the License, or (at your option) any later version.
  19. //
  20. // This library is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. // Lesser General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU Lesser General Public
  26. // License along with this library; if not, write to the Free Software
  27. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. //
  29. /*******************************************************************************/
  30. #include "LSM6DS3.h"
  31. #include "Wire.h"
  32. //Create a instance of class LSM6DS3
  33. LSM6DS3 myIMU(I2C_MODE, 0x6A); //I2C device address 0x6A
  34. void setup() {
  35. // put your setup code here, to run once:
  36. Serial.begin(9600);
  37. while (!Serial);
  38. //Call .begin() to configure the IMUs
  39. if (myIMU.begin() != 0) {
  40. Serial.println("Device error");
  41. } else {
  42. Serial.println("Device OK!");
  43. }
  44. }
  45. void loop() {
  46. //Accelerometer
  47. Serial.print("\nAccelerometer:\n");
  48. Serial.print(" X1 = ");
  49. Serial.println(myIMU.readFloatAccelX(), 4);
  50. Serial.print(" Y1 = ");
  51. Serial.println(myIMU.readFloatAccelY(), 4);
  52. Serial.print(" Z1 = ");
  53. Serial.println(myIMU.readFloatAccelZ(), 4);
  54. //Gyroscope
  55. Serial.print("\nGyroscope:\n");
  56. Serial.print(" X1 = ");
  57. Serial.println(myIMU.readFloatGyroX(), 4);
  58. Serial.print(" Y1 = ");
  59. Serial.println(myIMU.readFloatGyroY(), 4);
  60. Serial.print(" Z1 = ");
  61. Serial.println(myIMU.readFloatGyroZ(), 4);
  62. //Thermometer
  63. Serial.print("\nThermometer:\n");
  64. Serial.print(" Degrees C1 = ");
  65. Serial.println(myIMU.readTempC(), 4);
  66. Serial.print(" Degrees F1 = ");
  67. Serial.println(myIMU.readTempF(), 4);
  68. delay(1000);
  69. }