New Top

All Products By Category

Tag Archives | I²C

Motion Plug code updates

Seb Madgwick IMU demoDemo by SebMadgwick

Our Dutch collaborator, Jean-Claude Wippler, recently pointed us to more polished code on GitHub for the MPU9250 (Motion Plug). This board uses the Invensense MPU9250 and includes 3 axis: accelerometers, gyros, and magnetometer. The software was written for something called rpicopter, work that appears to be significant group effort to us.

Screen shot 2015-04-01 at 2.39.57 PM

We have simplified the Arduino sketch and turned it into an Arduino library. The library only supports hardware I2C pins on whatever Arduino or Atmega chip you’re using, because it uses 400khz high speed I2C. There are settings for the low-pass filter which only affects the Gyro, as far as we can see. It default is 188Hz (defined in inv_mpu.cpp). The library also supports the Teensy.

The library outputs Yaw, Pitch, and Roll (standard orientation headings in the flying business) smoothed out in an almost magical way. This comes courtesy of some very fancy math functions.

“A quaternion is a four-dimensional complex number that can be used to represent the
orientation of a rigid body or coordinate frame in three-dimensional space.” says Sebastian O.H. Madgwick, who wrote the sensor fusion algorithms which bear his name.

In any case, all the quaternions are now hidden out of sight (in mpu.cpp), the library works really well, and the Arduino sketch is easier to read and modify.