pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Cardputer-Adv IMU 6-Axis Motion Sensor

APIs and example programs for the Cardputer-Adv IMU 6-axis motion sensor. This is only applicable to Cardputer-Adv and not supported on Cardputer.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.2
  • Board option = M5Cardputer
  • M5Cardputer library version >= 1.1.0
  • M5Unified library version >= 0.2.8
  • M5GFX library version >= 0.2.10
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <M5Cardputer.h>

m5::imu_data_t imuData;

void setup() {
  auto cfg = M5.config();
  M5Cardputer.begin(cfg, true);  // enableKeyboard
  M5Cardputer.Display.setFont(&fonts::FreeMonoBold9pt7b);

  M5Cardputer.Display.clear();
  M5Cardputer.Display.setCursor(0, 0);
  M5Cardputer.Display.print("    IMU Live Data");
}

void loop() {
  // Use M5 for Imu class, not M5Cardputer
  M5.Imu.update();
  imuData = M5.Imu.getImuData();

  M5Cardputer.Display.setCursor(0, 30);
  M5Cardputer.Display.println("      Acc    Gyr");

  M5Cardputer.Display.printf("  x  % 4.2f  % 4.2f\n", imuData.accel.x, imuData.gyro.x);
  M5Cardputer.Display.printf("  y  % 4.2f  % 4.2f\n", imuData.accel.y, imuData.gyro.y);
  M5Cardputer.Display.printf("  z  % 4.2f  % 4.2f\n", imuData.accel.z, imuData.gyro.z);

  delay(100);
}

Execution Result:

API

The Cardputer-Adv IMU 6-axis motion sensor is driven by the Imu_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page