pdf-icon

Arduino 上手教程

AtomS3 IMU 姿态传感器

M5AtomS3 IMU姿态传感器输入相关API与案例程序。

案例程序

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 31 32
#include <M5AtomS3.h>
void setup(void) {
AtomS3.begin();
}
void loop(void) {
auto imu_update = AtomS3.Imu.update();
if (imu_update) {
auto data = AtomS3.Imu.getImuData();
// The data obtained by getImuData can be used as follows.
data.accel.x; // accel x-axis value.
data.accel.y; // accel y-axis value.
data.accel.z; // accel z-axis value.
data.accel.value; // accel 3values array [0]=x / [1]=y / [2]=z.
data.gyro.x; // gyro x-axis value.
data.gyro.y; // gyro y-axis value.
data.gyro.z; // gyro z-axis value.
data.gyro.value; // gyro 3values array [0]=x / [1]=y / [2]=z.
data.value; // all sensor 9values array [0~2]=accel / [3~5]=gyro /
// [6~8]=mag
Serial.printf("ax:%f ay:%f az:%f\r\n", data.accel.x, data.accel.y,
data.accel.z);
Serial.printf("gx:%f gy:%f gz:%f\r\n", data.gyro.x, data.gyro.y,
data.gyro.z);
}
delay(100);
}

API

M5AtomS3库基于M5Unified库实现, IMU部分使用了M5Unified库中的IMU_Class, 更多按键相关的API可以参考下方文档:

On This Page