pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

StickS3 IMU

StickS3 IMU attitude sensor related APIs and example program.

Example

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.5
  • Development board option = M5StickS3
  • M5Unified library version >= 0.2.12
  • M5GFX library version >= 0.2.18
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 33 34 35
#include <M5Unified.h>

void setup(void)
{
    M5.begin();
    M5.Lcd.setTextFont(&fonts::FreeMonoBold9pt7b);
}

void loop(void)
{
    auto imu_update = M5.Imu.update();
    if (imu_update) {
        M5.Lcd.setCursor(0, 5);
        M5.Lcd.clear();

        auto ImuData = M5.Imu.getImuData();

        // The ImuData obtained by getImuData can be used as follows.
        ImuData.accel.x;      // accel x-axis value.
        ImuData.accel.y;      // accel y-axis value.
        ImuData.accel.z;      // accel z-axis value.
        ImuData.accel.value;  // accel 3values array [0]=x / [1]=y / [2]=z.

        ImuData.gyro.x;      // gyro x-axis value.
        ImuData.gyro.y;      // gyro y-axis value.
        ImuData.gyro.z;      // gyro z-axis value.
        ImuData.gyro.value;  // gyro 3values array [0]=x / [1]=y / [2]=z.

        M5.Lcd.printf("IMU:\n\n");
        M5.Lcd.printf(" ax:%6.2f\n ay:%6.2f\n az:%6.2f\r\n", ImuData.accel.x, ImuData.accel.y, ImuData.accel.z);
        M5.Lcd.println();
        M5.Lcd.printf(" gx:%6.2f\n gy:%6.2f\n gz:%6.2f\r\n", ImuData.gyro.x, ImuData.gyro.y, ImuData.gyro.z);
    }
    delay(500);
}

This program will display the attitude sensor values for each axis on the screen.

API

The IMU part of StickS3 uses the IMU_Class from the M5Unified library. For more related APIs, you can refer to the following documentation:

On This Page