Created
March 2, 2022 15:28
-
-
Save ypelletier/dffbb85dbf895a9e34bb5c8530795514 to your computer and use it in GitHub Desktop.
Utilisation d'une centrale inertielle MPU6050 (accéléromètre + gyrometre) avec un Raspberry Pi Pico.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Utilisation d'une centrale inertielle MPU6050 | |
(accéléromètre + gyrometre) avec un Raspberry Pi Pico. | |
Pour plus d'infos: | |
https://electroniqueamateur.blogspot.com/2022/03/accelerometregyro-mpu-6050-et-raspberry.html | |
''' | |
from imu import MPU6050 # https://github.com/micropython-IMU/micropython-mpu9x50 | |
import time | |
from machine import Pin, I2C | |
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000) | |
imu = MPU6050(i2c) | |
# Affichage de la température | |
print("Temperature: ", round(imu.temperature,2), "°C") | |
while True: | |
# lecture des valeurs | |
acceleration = imu.accel | |
gyrometre = imu.gyro | |
print ("Acceleration x: ", round(acceleration.x,2), " y:", round(acceleration.y,2), | |
"z: ", round(acceleration.z,2)) | |
print ("gyrometre x: ", round(gyrometre.x,2), " y:", round(gyrometre.y,2), | |
"z: ", round(gyrometre.z,2)) | |
# interprétation des données (accéléromètre) | |
if abs(acceleration.x) > 0.8: | |
if (acceleration.x > 0): | |
print("L'axe x pointe vers le haut") | |
else: | |
print("L'axe x pointe vers le bas") | |
if abs(acceleration.y) > 0.8: | |
if (acceleration.y > 0): | |
print("L'axe y pointe vers le haut") | |
else: | |
print("L'axe y pointe vers le bas") | |
if abs(acceleration.z) > 0.8: | |
if (acceleration.z > 0): | |
print("L'axe z pointe vers le haut") | |
else: | |
print("L'axe z pointe vers le bas") | |
# interprétation des données (gyrometre) | |
if abs(gyrometre.x) > 20: | |
print("Rotation autour de l'axe x") | |
if abs(gyrometre.y) > 20: | |
print("Rotation autour de l'axe y") | |
if abs(gyrometre.z) > 20: | |
print("Rotation autour de l'axe z") | |
time.sleep(0.2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment