tuupola / micropython-mpu9250

MicroPython I2C driver for MPU9250 9-axis motion tracking device
MIT License
141 stars 47 forks source link

Strange data from the gyroscope of mpu9250 #7

Closed vvkuryshev closed 5 years ago

vvkuryshev commented 5 years ago

Gyroscope send starange data, like this (labels "gx, gy and gz"):

ax= 0.634463 ay= 0.114922 az= 9.80425 gx= -80.0391 gy= 36.3019 gz= 39.8009
ax= 0.64404 ay= 0.112527 az= 9.75397 gx= -77.4149 gy= 35.4271 gz= 19.2444
ax= 0.620098 ay= 0.146046 az= 9.77552 gx= -73.0411 gy= 21.8686 gz= 22.306
ax= 0.577003 ay= 0.122104 az= 9.742 gx= -70.4169 gy= 34.5524 gz= 20.1191
ax= 0.586579 ay= 0.0646434 az= 9.69412 gx= -84.8502 gy= 27.1171 gz= 38.9261
ax= 0.687136 ay= 0.124498 az= 9.75158 gx= -64.7311 gy= 28.8666 gz= 28.4292
ax= 0.572214 ay= 0.095768 az= 9.72285 gx= -72.6038 gy= 40.2382 gz= 16.6201
ax= 0.691924 ay= 0.0909796 az= 9.72524 gx= -67.3553 gy= 28.8666 gz= 23.6181
ax= 0.641646 ay= 0.0933738 az= 9.75158 gx= -68.6674 gy= 27.9918 gz= 28.4292
ax= 0.632069 ay= 0.0861912 az= 9.77792 gx= -89.2239 gy= 38.0514 gz= 23.1807

Each line - poll of mpu9250 approximately in 1 second. The module was stationary, therefore the data from the three channels of the gyroscope should be close to zero.

The script was:

import utime
from machine import I2C, Pin
from mpu9250 import MPU9250

i2c = I2C(scl=Pin(4), sda=Pin(5))
sensor = MPU9250(i2c)

print("MPU9250 id: " + hex(sensor.whoami))

while True:
    axyz = sensor.acceleration
    gxyz = sensor.gyro
    mxyz = sensor.magnetic
    print('ax=', axyz[0], 'ay=', axyz[1], 'az=', axyz[2],
    'gx=', gxyz[0], 'gy=', gxyz[1], 'gz=', gxyz[2])
    del axyz, gxyz
    utime.sleep_ms(1000)
tuupola commented 5 years ago

Gyroscope data is noisy. It will change even when the device in on rest. However the numbers you are seeing are too big. This was because I had radians to degrees conversion backwards (https://github.com/tuupola/micropython-mpu9250/pull/8).

At rest the real numbers should be close to zero. If you try with latest version you should see numbers which are something like the following;

(-0.178077290076335, -0.0142831583969465, -0.323324188931298)
(-0.101741412213739, 0.115487833969466, -0.10958373091603)
(-0.132275763358777, -0.166954914122137, -0.361492127862595)
(-0.24677958015267, -0.0448175095419847, -0.208820372137405)
(-0.407084923664121, -0.136420562977099, -0.0332478530534351)
(-0.193344465648854, 0.0773198950381679, -0.0866829675572519)
(-0.216245229007632, -0.0448175095419847, -0.0866829675572519)
(-0.323115458015266, 0.0849534828244275, -0.224087547709924)