Skip to content

M5Stack FIRE sensors... #44

@jedie

Description

@jedie

The M5Stack FIRE should have a "MPU6886 3-Axis Accelerometer + 3-Axis Gyroscope" and a "BMM150 3-Axis Magnetometer" see: https://docs.m5stack.com/en/core/fire

I have made a minimal example script for MPU6886:

import time

from machine import I2C, Pin
from mpos import SensorManager

# I2C setup on ESP32 (default I2C bus id is often 0 or 1, adjust if needed)
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)

MPU6886_ADDR = 0x68


# MPU6886 register addresses (typical InvenSense MPU6xxx style)
MPU6886_REG_PWR_MGMT_1 = 0x6B
MPU6886_REG_ACCEL_XOUT_H = 0x3B
MPU6886_REG_GYRO_XOUT_H = 0x43

# Wake up the sensor:
i2c.writeto_mem(MPU6886_ADDR, MPU6886_REG_PWR_MGMT_1, b"\x00")


def twos_complement(val, bits):
    if val & (1 << (bits - 1)):
        val -= 1 << bits
    return val


def read_mpu6886():
    # Read 6 bytes accel, 6 bytes gyro
    raw_accel = i2c.readfrom_mem(MPU6886_ADDR, MPU6886_REG_ACCEL_XOUT_H, 6)
    raw_gyro = i2c.readfrom_mem(MPU6886_ADDR, MPU6886_REG_GYRO_XOUT_H, 6)

    ax = twos_complement(raw_accel[0] << 8 | raw_accel[1], 16)
    ay = twos_complement(raw_accel[2] << 8 | raw_accel[3], 16)
    az = twos_complement(raw_accel[4] << 8 | raw_accel[5], 16)

    gx = twos_complement(raw_gyro[0] << 8 | raw_gyro[1], 16)
    gy = twos_complement(raw_gyro[2] << 8 | raw_gyro[3], 16)
    gz = twos_complement(raw_gyro[4] << 8 | raw_gyro[5], 16)

    print(f"Raw accel: ({ax}, {ay}, {az}), Raw gyro: ({gx}, {gy}, {gz})")


for i in range(3):
    read_mpu6886()
    time.sleep(0.1)

Output looks like:

mpremote u0 run test.py
Raw accel: (-80, -12, 17496), Raw gyro: (-436, -1752, -473)
Raw accel: (-100, -44, 17496), Raw gyro: (-274, -1878, -222)
Raw accel: (-60, -84, 17476), Raw gyro: (-405, -1722, -398)

No idea if the values are valid. But the changes look plausible when I turn the thing around.

I have no idea how to integrate it in mpos.
Just call: SensorManager.init(i2c, address=MPU6886_ADDR, mounted_position=SensorManager.FACING_EARTH) doesn't do the job.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions