pdf-icon

Arduino入門

2. デバイス&サンプル

6. アプリケーション

Cardputer-Adv IMU 六軸姿勢センサー

Cardputer-Adv IMU 六軸姿勢センサーに関する API とサンプルプログラムです。Cardputer-Adv のみに対応し、Cardputer では使用できません。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.2.2
  • ボードオプション = M5Cardputer
  • M5Cardputer ライブラリバージョン >= 1.1.0
  • M5Unified ライブラリバージョン >= 0.2.8
  • M5GFX ライブラリバージョン >= 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);
}

実行結果:

API

Cardputer-Adv IMU 六軸姿勢センサーは、M5Unified ライブラリ内の Imu_Class を使用して駆動されています。詳細な API については以下のドキュメントを参照してください:

On This Page