IMU

IMU is used to control the built-in accelerometer and gyroscope inside the host device. Below is the detailed IMU support for the host:

MPU6886

BMI270

BMM150

AtomS3

AtomS3 Lite

AtomS3U

StampS3

CoreS3

Core2

TOUGH

StickC Plus

StickC Plus2

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8
 9
10title0 = None
11label2 = None
12label0 = None
13label3 = None
14label1 = None
15label4 = None
16label5 = None
17
18
19def setup():
20    global title0, label2, label0, label3, label1, label4, label5
21
22    M5.begin()
23    Widgets.fillScreen(0x222222)
24    title0 = Widgets.Title("IMU CoreS3 example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
25    label2 = Widgets.Label("Acc_z:", 1, 98, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
26    label0 = Widgets.Label("Acc_x:", 1, 32, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
27    label3 = Widgets.Label("Gyro_x:", 1, 135, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
28    label1 = Widgets.Label("Acc_y:", 1, 66, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
29    label4 = Widgets.Label("Gyro_y:", 1, 168, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
30    label5 = Widgets.Label("Gyro_z:", 1, 198, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
31
32
33def loop():
34    global title0, label2, label0, label3, label1, label4, label5
35    M5.update()
36    label0.setText(str((str("Acc_x:") + str(((Imu.getAccel())[0])))))
37    label1.setText(str((str("Acc_y:") + str(((Imu.getAccel())[1])))))
38    label2.setText(str((str("Acc_z:") + str(((Imu.getAccel())[2])))))
39    label3.setText(str((str("Gyro_x:") + str(((Imu.getGyro())[0])))))
40    label4.setText(str((str("Gyro_y:") + str(((Imu.getGyro())[1])))))
41    label5.setText(str((str("Gyro_z:") + str(((Imu.getGyro())[2])))))
42
43
44if __name__ == "__main__":
45    try:
46        setup()
47        while True:
48            loop()
49    except (Exception, KeyboardInterrupt) as e:
50        try:
51            from utility import print_error_msg
52
53            print_error_msg(e)
54        except ImportError:
55            print("please update to latest firmware")

UIFLOW2 Example:

example.png

imu_cores3_example.m5f2

class IMU

Important

Methods of the IMU Class heavily rely on M5.begin() M5.begin.png and M5.update() M5.update.png.

All calls to methods of IMU objects should be placed after M5.begin() M5.begin.png, and M5.update() M5.update.png should be called in the main loop.

Methods

IMU.getAccel() tuple[float, float, float]

Get the tuple of x, y, and z values of the accelerometer.

UIFLOW2:

getAccel.png

getAccel2.png

getAccel3.png

IMU.getGyro() tuple[float, float, float]

Get the tuple of x, y, and z values of the gyroscope.

UIFLOW2:

getGyro.png

getGyro2.png

getGyro3.png

IMU.getMag() tuple[float, float, float]

Get the tuple of x, y, and z values of the magnetometer.

UIFLOW2:

getMag.png

getMag2.png

getMag3.png

class IMU_TYPE

Constants

IMU_TYPE.NULL: int
IMU_TYPE.UNKNOWN: int
IMU_TYPE.SH200Q: int
IMU_TYPE.MPU6050: int
IMU_TYPE.MPU6886: int
IMU_TYPE.MPU9250: int
IMU_TYPE.BMI270: int

The model of the IMU.