stick_imu.py

M5StickC Plus2 (M5Stack) — ESP32-PICO-V3-02 "stick" wearable kit (SKU K016-P2) · File : stick_imu.py · Language : MicroPython · Use case : Lire l'accéléromètre du stick en MicroPython

The M5Stack MicroPython firmware runs on the Plus2: imu.accel() and lcd.text suffice for a scripted inclinometer. In disk mode, iterate by drag-and-drop, no toolchain.

Hardware required

An M5StickC Plus2 (ESP32-PICO-V3-02, 135×240 display, A/B/C buttons, passive buzzer on G2, IR + red LED on G19, MPU6886 IMU, microphone, 200 mAh battery). None (M5Stack MicroPython firmware flashed).

Wiring

No wiring. Flash via esptool/M5Launcher, copy main.py in USB disk mode.

How it works

The imu module wraps the MPU6886 and returns three axes in g; lcd drawing erases the region then redraws (no framebuffer). The circle follows gravity. In the Arduino IDE (esp32 package), board « M5StickCPlus2 »; « M5StickCPlus2 » or M5Unified library. On the PMIC-less v2, hold button C for >2 s to power on; HOLD (G4) latches the power.

Going further

Add the buzzer (speaker module) for an audible spirit level, or log activity to a .csv file.

stick_imu.py

# MicroPython M5StickC : IMU + ecran sans Arduino IDE.
# Firmware « M5StickC » (base M5Stack) flash sur le Plus2.
from m5stack import lcd, imu
import time

lcd.clear()
lcd.text(10, 10, "IMU MicroPython", lcd.WHITE, 3)

while True:
    ax, ay, az = imu.accel()          # en g, tuple
    roll = int(180 * ay / 9.81)       # approximation petits angles
    pitch = int(180 * ax / 9.81)
    lcd.rect(0, 60, 240, 80, lcd.BLACK, lcd.BLACK)
    lcd.text(10, 66, "ax=%+.2f ay=%+.2f" % (ax, ay), lcd.GREEN, 3)
    lcd.text(10, 96, "roll=%+d pitch=%+d" % (roll, pitch), lcd.CYAN, 2)
    # fleche vers le bas = gravite
    x = 120 + max(-100, min(100, int(ax * 100)))
    y = 120 + max(0, min(14, int(ay * 14)))
    lcd.circle(x, y, 5, lcd.RED, lcd.RED)
    time.sleep_ms(80)

← Back to the board