# Author: peppe8o
# Blog: https://peppe8o.com
# Date: Aug 25th, 2021
# Version: 1.0
from imu import MPU6050
import time
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
imu = MPU6050(i2c)
red = Pin(5, Pin.OUT)
blue = Pin(6, Pin.OUT)
yellow = Pin(11, Pin.OUT)
while True:
# Following print shows original data get from libary. You can uncomment to see raw data
#print(imu.accel.xyz,imu.gyro.xyz,imu.temperature,end='\r')
# Following rows round values get for a more pretty print:
ax=round(imu.accel.x,2)
ay=round(imu.accel.y,2)
az=round(imu.accel.z,2)
gx=round(imu.gyro.x)
gy=round(imu.gyro.y)
gz=round(imu.gyro.z)
tem=round(imu.temperature,2)
if tem >= 24:
red.on()
else:
red.off()
if abs(ax) + abs(ay) + abs(az) != 0:
blue.on()
else:
blue.off()
if abs(gx) + abs(gy) + abs(gz) != 0:
yellow.on()
else:
yellow.off()
print(ax,"\t",ay,"\t",az,"\t",gx,"\t",gy,"\t",gz,"\t",tem," ",end="\r")
# Following sleep statement makes values enought stable to be seen and
# read by a human from shell
time.sleep(0.2)