Jump to content
I2Cdevlib Forums

Connecting 2 MPU6050s with Arduino using only 1 MPU6050 SW Object


Recommended Posts

Greetings,

My project requires connecting multiple MPU sensors and sending all rotation data to comp using USB.

I have the single sensor code working absolutely fine. Now i am hooking up 2 sensors. Idea is :

  • Tie together the SDA, SCL, Vcc, GND and INT lines of both MPUs together.
  • Connect the AD0 pins of MPUs to different Arduino pins.
  • Declare only 1 MPU6050 object (as given by jeff rowberg) with devAddr = 0x69 (I dont want to maintain X no. of object for X no. of sensors. My project going ahead may need 8+ sensors and i don't want to have 8+ MPU objects in my Arduino)
  • Whenever any sensor needs to be Init / Read / Written to, enable that sensor by writing HIGH to AD0 pin, and writing LOW on all other AD0 pins of other sensors.
  • Once the particular sensor has been enabled, i use the normal mpu functions from my MPU6050 object which have been provided by Jeff.

Now while initializing, i enable sensor 1, call mpu.initialize, testconn, dmpInit.... etc... , then i enable sensor 2, and do the same. Same method is followed to collect data from all sensors.

 

Problem is, only Sensor 2 gives valid output. Sensor 1 gives corrupt values.

 

I debugged the problem a little bit, it seems only the sensor which i initalize the last (sensor 2 in above case) gives valid values.

 

I first thought that when i init the second sensor using the single mpu object, it overwrites some SW vars in this object that were previously set by first sensor. Then when i try to access the Sensor 1 with this object, these overwritten values cause problems and arduino ends up reading garbage.

 

However i went through the whole MPU library to see if there are any private / public vars that are MPU specific and that Jeff's code might be saving. but i found nothing. It seems almost all the seful function straightaway call I2CDev Read/WriteBit. This implies as long as the correct device's AD0 is HIGH, and MPU's SW object's devAddr = 0x69, everything should work fine.

 

And yet it does not. Can someone help ?

Thanks

 

Link to comment
Share on other sites

Well my problem got solved. Turns out there was a problem with MPU FIFO.

it seems that the sensor i init first had an extra 16 bytes in its FIFO (I have no idea why). My code logic was reading 42 bytes (dmp packet size) chunks and was leaving this 16 bytes as is. This was causing corruption.

Now i keep reading the data till fifo is empty. and everything is working fine.

 

Link to comment
Share on other sites

  • 2 weeks later...

Hey sidg_vr_geek (nice username :P

 

I am doing almost the same thing as you. I am reading the data off three MPU 9150. I found out that if I join the INT pins together (means all the mpus in my setup has only on interrupt on arduino, i.e. int 0) then the data will stop printing after a while. I thought it might help u if u face this problem. How I solved this issue, I made a function for mpu initialization (copy paste the mpu initialization steps from example) and then assign different interrupts and ISR to different mpu and physically attach different INT pin of mpus to different interrupts on arduino.

 

Yet I solve the serial HANG issue, I am still getting corrupt data from mpus, (it does not matter from which mpu).

Can u please explain how you solved you issue. I did not get where u said to read the FIFO unless it is empty ? :/

 

Thanks in advance. Hoping for a reply

Link to comment
Share on other sites

  • 3 months later...

 

Well my problem got solved. Turns out there was a problem with MPU FIFO.

it seems that the sensor i init first had an extra 16 bytes in its FIFO (I have no idea why). My code logic was reading 42 bytes (dmp packet size) chunks and was leaving this 16 bytes as is. This was causing corruption.

Now i keep reading the data till fifo is empty. and everything is working fine.

 

Please, describe, how namely you did that, could you show your sketch? 

Link to comment
Share on other sites

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...
 Share

×
×
  • Create New...