IMU.ino 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // define must ahead #include <M5Stack.h>
  2. #define M5STACK_MPU6886
  3. // #define M5STACK_MPU9250
  4. // #define M5STACK_MPU6050
  5. // #define M5STACK_200Q
  6. #include <M5Stack.h>
  7. float accX = 0.0F;
  8. float accY = 0.0F;
  9. float accZ = 0.0F;
  10. float gyroX = 0.0F;
  11. float gyroY = 0.0F;
  12. float gyroZ = 0.0F;
  13. float pitch = 0.0F;
  14. float roll = 0.0F;
  15. float yaw = 0.0F;
  16. float temp = 0.0F;
  17. // the setup routine runs once when M5Stack starts up
  18. void setup(){
  19. // Initialize the M5Stack object
  20. M5.begin();
  21. /*
  22. Power chip connected to gpio21, gpio22, I2C device
  23. Set battery charging voltage and current
  24. If used battery, please call this function in your project
  25. */
  26. M5.Power.begin();
  27. M5.IMU.Init();
  28. M5.Lcd.fillScreen(BLACK);
  29. M5.Lcd.setTextColor(GREEN , BLACK);
  30. M5.Lcd.setTextSize(2);
  31. }
  32. // the loop routine runs over and over again forever
  33. void loop() {
  34. // put your main code here, to run repeatedly:
  35. M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
  36. M5.IMU.getAccelData(&accX,&accY,&accZ);
  37. M5.IMU.getAhrsData(&pitch,&roll,&yaw);
  38. M5.IMU.getTempData(&temp);
  39. M5.Lcd.setCursor(0, 20);
  40. M5.Lcd.printf("%6.2f %6.2f %6.2f ", gyroX, gyroY, gyroZ);
  41. M5.Lcd.setCursor(220, 42);
  42. M5.Lcd.print(" o/s");
  43. M5.Lcd.setCursor(0, 65);
  44. M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ);
  45. M5.Lcd.setCursor(220, 87);
  46. M5.Lcd.print(" G");
  47. M5.Lcd.setCursor(0, 110);
  48. M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw);
  49. M5.Lcd.setCursor(220, 132);
  50. M5.Lcd.print(" degree");
  51. M5.Lcd.setCursor(0, 155);
  52. M5.Lcd.printf("Temperature : %.2f C", temp);
  53. delay(1);
  54. }