0

SparkFun BasicAHRS_I2C giving unstable readings.

I am using the SparkFun Arduino Sketch from here.

It is giving me these results:

X-acceleration: 91.43 mg Y-acceleration: 249.51 mg Z-acceleration: 1042.05 mg 
X-gyro rate: -0.549 degrees/sec Y-gyro rate: 0.557 degrees/sec Z-gyro rate: 1.595 degrees/sec
X-mag field: -164.35 mG Y-mag field: -240.16 mG Z-mag field: -20.73 mG
Temperature is 27.9 degrees C

and then the next result (when MPU9250 is still) is:

X-acceleration: 91.49 mg Y-acceleration: 252.75 mg Z-acceleration: 1039.49 mg 
X-gyro rate: -0.076 degrees/sec Y-gyro rate: -0.130 degrees/sec Z-gyro rate: -0.008 degrees/sec
X-mag field: -175.07 mG Y-mag field: -222.24 mG Z-mag field: -27.64 mG
Temperature is 27.9 degrees C

Notice how the temperature has remained constant, acceleration has remained constant (although im not why there is a reading if the MPU9250 is stationary) and the mag field is fairly close. However, the Gyro values are not close.

Could I have a bad MPU9250?

I am using the Mega.

Edit: Added a complementary filter from here, however they have not added a comp filter for the z value as can be seen from my screenshot of the serial monitor:

Serial Monitor screenshot

I think this is because they have the MPU6050 and not the MPU9250. I believe the MPU9250 has the magnetometer which can be used to 'help' the drift?

How could I use the magnetometer to help counter the drift?

End goal: rotate a gameobject in unity with the MPU9250 with minimal drift and maximum accuracy.

1
  • Have you tried posting a question to SparkFun's customer service department? – Duncan C Aug 12 '19 at 0:58
1

If you haven’t noticed the difference in the two is minuscule. For example, the change in degree is <1. Also the acceleration is measured in g’s which is acceleration due to gravity. The data says the measures are in mg which is 0.01g. This is normal with accelerometers and all sensors when they pick up residual voltage from random vibrations or other sources of noise. It also could be with the error margin within SparkFun’s product since the product is more on the lower end of quality which once again is normal. TLDR: everything is working fine.

1
  • When I use them values in Unity, the object rotates fast almost as if its random. – Jordan Savage Aug 12 '19 at 12:50
1

The values seem fine to me. Generally these MPU chips are really noisy, that is totally normal. Ti really use the data to the the current orientation, you have to use a filter to combine the data from accelerometer and gyroscope.

There are multiple possible filters, that can help. The easiest one to implement is a Complementary filter. It gives you pretty good results. You should be able to find corresponding tutorials on the web.


The code from your link does not use a complementary filter for the z axis. In the comment it says, that the accelerometer doesn't provide z angle data, and that is correct. Since gravity always goes down, you cannot distinguish the angles around that axis.

But - as you already stated - you can use the magnetometers data for this. But you will need the inclination angle of the earths magnetic field (the angle between ground and field vector). You can google the inclination angle for your place and use it as constant. But most likely you will want to use the device inside of buildings. The magnetic field can be very disturbed there due to much steel nearby. Thus it is better to do a calibration step before use, while the device lies flat on the ground.

When you have calculated the angle around the z axis from the magnetometer data, you can use it in a complementary filter, like it was done in the linked code with the accelerometer data.

Note: Due to all the steel, the inclination angle does not have to be constant, when moving around in a building. So this is better for use inside a small space range.

8
  • When I use them gyro values to rate an object in Unity it moves so much as if it is random. – Jordan Savage Aug 12 '19 at 13:11
  • Then you are doing something wrong in your unity game. With that rate from the gyro a full rotation would need about 360 seconds (well over 5min). At least not so fast, that is is random. Please don't use the unity game to test the accelerometer. Instead you should watch the values directy on the serial monitor, to see, how they behave. With a complementary filter you get the absolute orientation. Do this on the arduino, output the calculated orientation, and check, this these values are good over th serial monitor – chrisl Aug 12 '19 at 13:48
  • The above values are from the serial monitor however I haven’t calculated the absolute orientation with the serial monitor. – Jordan Savage Aug 12 '19 at 13:55
  • The above values don't correspond with rapid movement. Try the complementary filter – chrisl Aug 12 '19 at 14:16
  • @Jordan Savage I added a small explanation about using the magnetometer. – chrisl Aug 12 '19 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.