
Arduino Quick Start
Arduino Nesso N1 IMU-related API and example program.
#include "M5Unified.h"
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
M5.Display.setRotation(1);
M5.Display.setTextColor(GREEN);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::FreeSansBold9pt7b);
M5.Display.setTextSize(1);
}
void loop(void) {
auto imu_update = M5.Imu.update();
if (imu_update) {
M5.Display.setCursor(0, 40);
M5.Display.clear(); // Delay 100ms
auto data = M5.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);
M5.Display.printf("IMU:\r\n");
M5.Display.printf("ax:%0.2f ay:%0.2f az:%0.2f\r\n", data.accel.x,
data.accel.y, data.accel.z);
M5.Display.printf("gx:%0.2f gy:%0.2f gz:%0.2f\r\n", data.gyro.x,
data.gyro.y, data.gyro.z);
}
delay(100);
}
The IMU driver of Arduino Nesso N1 uses the IMU_Class in the M5Unified library. For more IMU-related APIs, please refer to the following document: