lsm6dsox_mlc.py
# Ce travail est publié sous licence MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Tous droits réservés.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Exemple LSM6DSOX IMU MLC (Machine Learning Core).
# Téléchargez le fichier UCF brut, copiez-le sur le stockage et redémarrez.
# REMARQUE : Les modèles pré-entraînés (fichiers UCF) pour les exemples se trouvent ici :
# https://github.com/STMicroelectronics/STMems_Machine_Learning_Core/tree/master/application_examples/lsm6dsox
from machine import Pin
from machine import SPI
from lsm6dsox import LSM6DSOX
INT_MODE = True # Exécuter en mode interruption.
INT_FLAG = False # Mettre à True lors d'une interruption.
def imu_int_handler(pin):
global INT_FLAG
INT_FLAG = True
if INT_MODE is True:
int_pin = Pin("PA1", mode=Pin.IN, pull=Pin.PULL_UP)
int_pin.irq(handler=imu_int_handler, trigger=Pin.IRQ_RISING)
# Exemple de détection de vibration
UCF_FILE = "lsm6dsox_vibration_monitoring.ucf"
UCF_LABELS = {0: "no vibration", 1: "low vibration", 2: "high vibration"}
# REMARQUE : Le taux de données et l'échelle sélectionnés doivent correspondre au taux de données et à l'échelle du MLC.
lsm = LSM6DSOX(
SPI(5),
cs=Pin("PF6", Pin.OUT_PP, Pin.PULL_UP),
gyro_odr=26,
accel_odr=26,
gyro_scale=2000,
accel_scale=4,
ucf=UCF_FILE,
)
# Exemple de gestes de la tête
# UCF_FILE = "lsm6dsox_head_gestures.ucf"
# UCF_LABELS = {0:"Nod", 1:"Shake", 2:"Stationary", 3:"Swing", 4:"Walk"}
# REMARQUE : Le taux de données et l'échelle sélectionnés doivent correspondre au taux de données et à l'échelle du MLC.
# lsm = LSM6DSOX(SPI(5), cs_pin=Pin("PF6", Pin.OUT_PP, Pin.PULL_UP),
# 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]])