lsm6dsox_mlc.py

# Este trabalho está licenciado sob a licença MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Todos os direitos reservados.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Exemplo de IMU LSM6DSOX com MLC (Machine Learning Core).
# Baixe o arquivo UCF bruto, copie para o armazenamento e reinicie.

# NOTA: Os modelos pré-treinados (arquivos UCF) para os exemplos podem ser encontrados aqui:
# 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  # Executa em modo de interrupção.
INT_FLAG = False  # Define True na interrupção.


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))

# Exemplo de detecção de vibração
UCF_FILE = "lsm6dsox_vibration_monitoring.ucf"
UCF_LABELS = {0: "no vibration", 1: "low vibration", 2: "high vibration"}
# NOTA: A taxa de dados e a escala selecionadas devem corresponder à taxa de dados e escala do MLC.
lsm = LSM6DSOX(i2c, gyro_odr=26, accel_odr=26, gyro_scale=2000, accel_scale=4, ucf=UCF_FILE)

# Exemplo de gestos de cabeça
# UCF_FILE = "lsm6dsox_head_gestures.ucf"
# UCF_LABELS = {0:"Nod", 1:"Shake", 2:"Stationary", 3:"Swing", 4:"Walk"}
# NOTA: A taxa de dados e a escala selecionadas devem corresponder à taxa de dados e escala do 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 ""