Help with filtering MPU6050 data

Hello everyone,

I am currently trying to read data from an MPU6050 accelerometer, mainly the accelerations on each axis, and then storing those values in a SD card. I've been able to obtain that data with the code I wrote, as well as write it, however I can't seem to be able to filter the data I've obtained, which was pretty much unreadable due to noise. I've looked at many tutorials and websites on how to improve the data with Kalman filtering, such as in this website:

http://www.den-uijl.nl/electronics/gyro.html#Kalman

It's a pretty well detailed guide, but that code is written for obtaining pitch and roll values, which have little use for me, and I can't seem to understand how I would use the filters for obtaining the actual accelerations. So I'm pretty much stuck on that, and understanding theory behind the Kalman filter is pretty hard on its own.
Could anyone help me with that?

I have attached my code to this post if anybody is willing to read it. Thanks!

ImuDatalogger.ino (4.7 KB)

I had a similar problem with a BME280 pressure sensor, and used a running average...

    altitude = bme.readAltitude(atpress/100); // this should be adjusted to your local forcase
    ave2 += altitude;
    ave2 *= (1-1/aveLen);
    ave3 = ave2/(aveLen-1);

aveLen (int) is the number of samples over which to average. I used about 50

All else are floats.

Allan

Thanks for the help, allan. But i was really loking forward to implementing the kalman filter due to its precision.
Either way, I'll try it and see if it works.

The best open source Kalman filter software currently available is RTIMUlib for Arduino. I don't think it supports your 6050, but that is outdated anyway. Several of the newer IMUs are supported and will work better.

You can read about my implementation with a Pololu IMU breakout at
https://forum.pololu.com/t/state-of-the-art-ahrs-for-25/8091

Thanks for the reply as well, but I already have the whole board for this project of mine ready, so swapping it for a newer one would be really troublesome.

Also, I have a simpler question as well. How can I change the accelerometer range from 2g to 4g? I know it has something to do with the AFS_SEL register, but I don't know how I would implement that on my code.