Jump to content
I2Cdevlib Forums

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

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • 2 years later...
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

Link to comment
Share on other sites

  • 1 year later...
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

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...