Espruino & MPU6050 & Digital Motion Processing
April 24, 2016 Leave a comment
If neither of the 3 terms in the title mean anything to you, then you can stop here, there won’t be any nice video or images in this post 🙂
I’m planning on using the Espruino Pico in combination with a MPU6050 IMU module for my latest version of a self balancing robot.
Among many things that are great about the Espruino platform is that there are ready made modules/libraries for many peripherals, including the MPU6050.
However, the existing module only support reading raw data (acceleration, gyro & temperature) from the module and can’t make use of the more advanced Digital Motion Processing features, which is where this IMU really shines.
Without getting into many details, one can use the acceleration on each axis to determine the inclination of the sensor, but in reality the data is very noisy, not least on a robot where the motors generate lots of vibrations. The gyro data is less noisy, but it drifts over time.
So to get any reliable measurement of the actual inclination / relative orientation of your sensor, you need to combine these 2 sets of data.
This can be done using a Kalman or Complementary filters, or plenty of other variations, the idea being that the acceleration ensures long term stability whereas the gyros correct for the high frequency noises.
Going back to my project, I undertook to add this extra feature to the Espruino platform, mainly by porting the Arduino library.
You can find the code on my Github account, I not only had to update the MPU6050.js module code, but actually to create a new one, MPU6050_DMP.js that wraps the basic functionality. This was simply because if everything was in one module it wouldn’t fit in Espruino Pico’s memory.
I’m not waiting / hoping that this improvement will make it to the official Espruino code base, but in the meanwhile you can simply use the code from my repository…