[Swlug] An interesting time with an accelerometer
Rhys Sage
rhys_sage at yahoo.com
Fri Jun 24 16:31:16 UTC 2022
I'm working with an accelerometer with the Pi Pico. I'm getting output from it but I'm not really sure whether the output is correct. The code came from Github and likely does not have a problem. I'm a bit perplexed by the output. It does not seem to me to be normal output - what do you think? Is there a problem with the accelerometer? It's the same one from the video I made the other day.
MicroPython v1.19 on 2022-06-16; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Place breadboard flat then hit enter
ax 0.99 ay -0.0 az -0.19 gx -4.832 gy 0.992 gz -0.221 Temperature 24.84
Place breadboard on one side then hit enter
ax 0.14 ay 0.03 az 0.95 gx -4.626 gy 3.321 gz -0.168 Temperature 24.98
Place breadboard on the other side then hit enter
ax -0.15 ay -0.02 az -1.04 gx -4.863 gy 0.771 gz -0.221 Temperature 24.98
Place breadboard upside down then hit enter
ax -0.9700001 ay -0.05 az 0.04 gx -6.557 gy 2.031 gz -1.031 Temperature 25.07
Place breadboard on one end then hit enter
ax 0.06 ay -0.99 az -0.05 gx -1.015 gy 1.573 gz 3.221 Temperature 25.12
Place breadboard on the other end then hit enter
ax -0.01 ay 1.02 az -0.04 gx -4.687 gy 0.679 gz 1.038 Temperature 25.12
The code came from here: https://microcontrollerslab.com/mpu6050-raspberry-pi-pico-micropython-tutorial/#MicroPython_MPU6050_Getting_Accelerometer_Gyroscope_and_Temperature_values
The only change I made was to the output display and this is the code...
from imu import MPU6050
from time import sleep
from machine import Pin, I2C
def Printout():
ax=round(imu.accel.x,2)
ay=round(imu.accel.y,2)
az=round(imu.accel.z,2)
gx=round(imu.gyro.x,3)
gy=round(imu.gyro.y,3)
gz=round(imu.gyro.z,3)
tem=round(imu.temperature,2)
print("ax",ax,"\t","ay",ay,"\t","az",az,"\t","gx",gx,"\t","gy",gy,"\t","gz",gz,"\t","Temperature",tem," ",end="\r")
sleep(0.2)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
imu = MPU6050(i2c)
input('Place breadboard flat then hit enter')
Printout()
print("\n")
input('Place breadboard on one side then hit enter')
Printout()
print("\n")
input('Place breadboard on the other side then hit enter')
Printout()
print("\n")
input('Place breadboard upside down then hit enter')
Printout()
print("\n")
input('Place breadboard on one end then hit enter')
Printout()
print("\n")
input('Place breadboard on the other end then hit enter')
Printout()
print("\n")
while True:
Printout()
Rhys Sage
More information about the Swlug
mailing list