Example: 50-Arduino-Boards/Nano-RP2040/51-Sensors/lsm6dsox_mlc.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# LSM6DSOX IMU MLC(机器学习核心)示例。
# 下载原始 UCF 文件,复制到存储并重置。

# 注意:示例的预训练模型(UCF 文件)可以在这里找到:
# https://github.com/STMicroelectronics/STMems_Machine_Learning_Core/tree/master/application_examples/lsm6dsox

from lsm6dsox import LSM6DSOX
from machine import Pin
from machine import I2C

INT_MODE = True  # 以中断模式运行。
INT_FLAG = False  # 在中断时设置为 True。


def imu_int_handler(pin):
    global INT_FLAG
    INT_FLAG = True


if INT_MODE is True:
    int_pin = Pin(24, mode=Pin.IN, pull=Pin.PULL_UP)
    int_pin.irq(handler=imu_int_handler, trigger=Pin.IRQ_RISING)

i2c = I2C(0, scl=Pin(13), sda=Pin(12))

# 振动检测示例
UCF_FILE = "lsm6dsox_vibration_monitoring.ucf"
UCF_LABELS = {0: "no vibration", 1: "low vibration", 2: "high vibration"}
# 注意:选择的数据速率和比例必须与 MLC 数据速率和比例匹配。
lsm = LSM6DSOX(i2c, gyro_odr=26, accel_odr=26, gyro_scale=2000, accel_scale=4, ucf=UCF_FILE)

# 头部手势示例
# UCF_FILE = "lsm6dsox_head_gestures.ucf"
# UCF_LABELS = {0:"点头", 1:"摇头", 2:"静止", 3:"摆动", 4:"行走"}
# 注意:选择的数据速率和比例必须与 MLC 数据速率和比例匹配。
# lsm = LSM6DSOX(i2c, gyro_odr=26, accel_odr=26, gyro_scale=250, accel_scale=2, ucf=UCF_FILE)

print("MLC configured...")

while True:
    if INT_MODE:
        if INT_FLAG:
            INT_FLAG = False
            print(UCF_LABELS[lsm.mlc_output()[0]])
    else:
        buf = lsm.mlc_output()
        if buf is not None:
            print(UCF_LABELS[buf[0]])

results matching ""

    No results matching ""