Recommended Posts

I am attaching an Arduino example sketch to show how to read a magnetometer (HMC5883L) while MPU's DMP is active.

This is only useful if you have your magnetometer attached to MPU's I2C internal aux lines, like many 10DOF boards do, and you want to use DMP.

If you can, I believe it is always best to connect your magnetometer to your main I2C lines directly and you won't need this sketch.

This sketch does NOT fuse DMP + magnetometer. You will have to do it by yourself in your host processor.

I would only try to fuse magnetometer if it is going to be used outdoors, as electromagnetic interferences caused by electronics indoor make it quite difficult. Besides, the DMP's yaw measure is very good if you don't need much precision or long running times, in these cases you should fuse magnetometer + DMP.

Please read sketch comments, as many things are explained there.

Remember to put your MPU's address (0x68 or 0x69) and to set your interruption pin.

Please give feedback, wheter it works or you have trouble with it.

If people find it useful maybe Jeff can add it to the library once it is bugfree.

Using their approach you could fuse the DMP data along with the magnetometer data (equations 7 - 9 in the paper), at a relatively cheap cost of a few trig function multiplications, to get an even more accurate response. Could be a good approach before the sensor fusion of all thee sensors is figured out.

Share this post

Link to post

Share on other sites

I have those equations implemented in my project. It is true they improve yaw measure coming from magnetometer, in the way that it does not oscillate so much when you change pitch and roll.

Anyway I reached the conclusion that magnetometer yaw measure shouldn't be used indoors, because of big electromagnetic interference. Or maybe it is just my lab, with cables running under the floor and inside walls.

When I start to use it outdoors I will check its measure again and fuse them.

Share this post

Link to post

Share on other sites

I am attaching an Arduino example sketch to show how to read a magnetometer (HMC5883L) while MPU's DMP is active.

This is only useful if you have your magnetometer attached to MPU's I2C internal aux lines, like many 10DOF boards do, and you want to use DMP.

If you can, I believe it is always best to connect your magnetometer to your main I2C lines directly and you won't need this sketch.

This sketch does NOT fuse DMP + magnetometer. You will have to do it by yourself in your host processor.

I would only try to fuse magnetometer if it is going to be used outdoors, as electromagnetic interferences caused by electronics indoor make it quite difficult. Besides, the DMP's yaw measure is very good if you don't need much precision or long running times, in these cases you should fuse magnetometer + DMP.

Please read sketch comments, as many things are explained there.

Remember to put your MPU's address (0x68 or 0x69) and to set your interruption pin.

Please give feedback, wheter it works or you have trouble with it.

If people find it useful maybe Jeff can add it to the library once it is bugfree.