pdf-icon

Arduino入門

2. デバイス&サンプル

PaperS3 IMU(6軸姿勢センサー)

PaperS3の6軸姿勢センサーに関連するAPIおよびサンプルプログラム。

サンプルプログラム

ビルド要件

  • M5Stack ボードマネージャバージョン >= 2.1.4
  • ボードの選択 = M5PaperS3
  • M5Unified ライブラリバージョン >= 0.2.5
  • M5GFX ライブラリバージョン >= 0.2.7
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 29 30
#include <M5Unified.h>
#include <M5GFX.h>
m5::imu_data_t imuData;
void setup() {
M5.begin();
M5.Display.setRotation(0);
M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
M5.Display.clear();
M5.Display.print(" IMU Live Data\n");
}
void loop() {
M5.Imu.update();
imuData = M5.Imu.getImuData();
M5.Display.setCursor(0, 100);
M5.Display.printf(" Acc X = %6.2f \n", imuData.accel.x);
M5.Display.printf(" Acc Y = %6.2f \n", imuData.accel.y);
M5.Display.printf(" Acc Z = %6.2f \n\n", imuData.accel.z);
M5.Display.printf(" Gyr X = %6.2f \n", imuData.gyro.x);
M5.Display.printf(" Gyr Y = %6.2f \n", imuData.gyro.y);
M5.Display.printf(" Gyr Z = %6.2f \n", imuData.gyro.z);
delay(1000);
}

このプログラムは、加速度計とジャイロスコープのリアルタイムの読み取り値を表示し、1秒ごとに更新されます。

API

PaperS3の姿勢センサーは、M5Unifiedライブラリの Imu_Class を使用しています。関連するAPIの詳細については、以下のドキュメントを参照してください:

On This Page