Jump to content
I2Cdevlib Forums
luisrodenas

Arduino example sketch to read magnetometer while DMP is ON

Recommended Posts

Hello,

 

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.

 

Thank you

MPU6050_DMP_mag.zip

Share this post


Link to post
Share on other sites

Interesting, I'm definitely interested in using the HMC5883L along with the DMP data, so I'll take a look at your sketch once my PCBs come in.

 

Have you seen the following? http://franciscoraulortega.com/pubs/Algo3DFusionsMems.pdf

 

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.

 

Thank you for the info

Share this post


Link to post
Share on other sites
Good afternoon!
sorry for my English
I have an Arduino Nano, 2 MPU6050, 2 HMC5883L
I want to get the output array with 20 values (the first board {3, 3, accelerometer, magnetometer, 3, temperature}), the second board {3, 3, accelerometer, magnetometer, 3, temperature})

Now I'm trying to get it to work the first board (соединение серии MPU6050 + HMC5883L).

I use your file " MPU6050_DMP_mag.zip  ".

1) I set the address of MPU ( в 0x68)  , because MPU6050-> AD0 is connected to ground through 4,7 кОм

2) I set Int interrupt_pin = 0, and I have the answer !!! 

But I have a magnetometer (0.00,0.00,0.00);

What do you think, what's the problem?
my circuit

Q8F3Sna7UU8.jpg

Share this post


Link to post
Share on other sites
On 1/30/2014 at 1:33 PM, luisrodenas said:

Hello,

 

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.

 

Thank you

MPU6050_DMP_mag.zip

Hi, 

Can I make a "serial" connection with two MPU6050 in that way? 

Assuming the Master MPU is 0x68 and a Slave MPU is connected to the master MPU at XCL, XDA?

As "Monax_111" posted but instead of Magnetometer connect at the same Pins the Slave MPU6050.

 

Thanks 

Hadar

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×