i2cdevlib icon indicating copy to clipboard operation
i2cdevlib copied to clipboard

how to connect two mpu6050 to arduino uno

Open reut10 opened this issue 12 years ago • 38 comments

Hi! I want to connect my arduino uno to two mpu 6050 in order to learn about the relative angles and velocity, there is some ready program for this? how to connect the 2 mpu 6050 ? thank you, reut :)

reut10 avatar Mar 17 '14 19:03 reut10

You can pull one of the AD0 pins up and one of them down; then you can address the two MPUs with different I2C addresses.

Ernest314 avatar Mar 19 '14 16:03 Ernest314

thank!!! but, how I can address the two MPUs with different I2C addresses?

reut10 avatar Mar 20 '14 10:03 reut10

Create two MPU6050 objects that can be called separately. See below:

MPU6050 accelgyroIC1(0x68);
MPU6050 accelgyroIC2(0x69); // <-- use for second MPU6050 device where AD0 must be high (3.3V)

Then, initialize both the objects with:

accelgyroIC1.initialize();
accelgyroIC2.initialize();

You may test the connection in the same way. Then call the getMotion6() function twice.

udawat avatar Mar 20 '14 11:03 udawat

Hi!

I'm doing the same!

See the modifications below:

// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class // 10/7/2011 by Jeff Rowberg [email protected] // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib // // Changelog: // 2011-10-07 - initial release

/* ============================================ I2Cdev device library code is placed under the MIT license Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

THE SOFTWARE.

*/

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files // for both classes must be in the include path of your project #include "I2Cdev.h" #include "MPU6050.h"

// class default I2C address is 0x68 // specific I2C addresses may be passed as a parameter here // AD0 low = 0x68 (default for InvenSense evaluation board) // AD0 high = 0x69 //MPU6050 accelgyro; MPU6050 accelgyroIC1(0x68); MPU6050 accelgyroIC2(0x69);

int16_t ax1, ay1, az1; int16_t gx1, gy1, gz1;

int16_t ax2, ay2, az2; int16_t gx2, gy2, gz2;

#define LED_PIN 13 bool blinkState = false;

void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) Wire.begin();

// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz,

but // it's really up to you depending on your project) Serial.begin(38400);

// initialize device
Serial.println("Initializing I2C devices...");
//accelgyro.initialize();
accelgyroIC1.initialize();
accelgyroIC2.initialize();

// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyroIC1.testConnection() ? "MPU6050 #1 connection

successful" : "MPU6050 connection failed"); Serial.println(accelgyroIC2.testConnection() ? "MPU6050 #2 connection successful" : "MPU6050 connection failed");

// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);

}

void loop() { // read raw accel/gyro measurements from device accelgyroIC1.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1); accelgyroIC2.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);

// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);

// display tab-separated accel/gyro x/y/z values
Serial.print("MPU1:\t");
Serial.print(ax1); Serial.print("\t");
Serial.print(ay1); Serial.print("\t");
Serial.print(az1); Serial.print("\t");
Serial.print(gx1); Serial.print("\t");
Serial.print(gy1); Serial.print("\t");
Serial.println(gz1);


// display tab-separated accel/gyro x/y/z values
Serial.print("MPU2:\t");
Serial.print(ax2); Serial.print("\t");
Serial.print(ay2); Serial.print("\t");
Serial.print(az2); Serial.print("\t");
Serial.print(gx2); Serial.print("\t");
Serial.print(gy2); Serial.print("\t");
Serial.println(gz2);


// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);

}

2014-03-20 8:21 GMT-03:00 udawat [email protected]:

Create two MPU6050 objects that can be called separately. See below:

MPU6050 accelgyroIC2(0x69); // <-- use for second MPU6050 device where AD0
must be high (3.3V)

Then, initialize both the objects with:

``` accelgyroIC1.initialize();
 accelgyroIC2.initialize();

You may test the connection in the same way. Then call the getMotion6()
function twice.

--
Reply to this email directly or view it on GitHub<https://github.com/jrowberg/i2cdevlib/issues/63#issuecomment-38156087>
.

loowiz avatar Mar 20 '14 18:03 loowiz

thanks!!

looowiz, in your project you gen the two angles for example and not the relative one; do you know how to get it?

there is graphical view in order to see the current location/relative angles and velocity of the two mpu?

reut10 avatar Mar 22 '14 20:03 reut10

loowiz could you please add your circuit scheme? I found here: http://forum.arduino.cc/index.php?topic=118937.0 three ways to connect the two MPU6050 to the Arduino Uno but non of them works..

Thank you

reut10 avatar Mar 23 '14 10:03 reut10

Hi Reut10!!

To correct your error I recommend you to download the original sketch files on https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 Then you can make the changes using the code I sent! I think you forgot to put the libraries on the same directory of your sketch.

For the hardware, Im using connections similar to the Erguezga post ( http://forum.arduino.cc/index.php?PHPSESSID=t6lmv7i431eqeaf05ui619q2h6&topic=118937.msg1368958#msg1368958). The difference is that Im not using the orange wires (Int outputs) and I connected MPU#1s AD0 to GND and MPU#2s AD0 to VCC. After this, one MPU take the address 0x68 and the other take 0x69. Im using an Arduino Mega board, but its the same code!

I'm curious, what purpose of your project?

2014-03-23 7:25 GMT-03:00 reut10 [email protected]:

loowiz could you please add your circuit scheme? I found here: http://forum.arduino.cc/index.php?topic=118937.0 three ways to connect the two MPU6050 to the Arduino Uno but non of them works..

Thank you

Reply to this email directly or view it on GitHubhttps://github.com/jrowberg/i2cdevlib/issues/63#issuecomment-38378705 .

loowiz avatar Mar 24 '14 03:03 loowiz

Thank you!! I will try this soon and let you know how it worked out. We are trying to calculate the wrist range of motion by the relative velocity and angle for bio-feedback rehabilitation, also we want to visualize this data on a graph. Did you calibrate the raw data in order to get Physical values?

reut10 avatar Mar 24 '14 06:03 reut10

Hi! we did as loowiz said, now we can read data from each mpu 6050 in 68/69. when we try to connect the 2 mpu 6050 together we can read just one of then. the connection we did is: A4- SDA1-SDA2 A5-SCL1-SCL2 3.3-VDD1-VIO1-GND2 GND-VDD2-VIO2-GND1

and use loowiz code...but it's doesn't work. We try to use I2C scanner and we can't read the 2 mpu 6050, but for each we can read. what's wrong?

Thanks again!

reut10 avatar Apr 09 '14 10:04 reut10

@reut10 Power connections seem to be improper. Try the following configuration: 3.3V -> VDD1-VDD2-VIO1-VIO2 GND -> GND1-GND2

udawat avatar Apr 09 '14 11:04 udawat

I can read data from the two IMU!!!!! thanks!!!! @udawat you right!!!!!

Now, I have to get the date from the two MPU6050 after complementary filter. (I use processing in order to see a graph of the movement, for one mpu I get a roll and pitch angle) do you know how to do it?

Thank you! Reut

reut10 avatar Apr 17 '14 20:04 reut10

You have to connect VCC - Arduino 5v GND - Arduino GND SCL - A5 SDA - A4

and here is some example video and arduino code.

https://www.youtube.com/watch?v=D5HY_tjW1lc https://www.youtube.com/watch?v=EbIGiKwFj3c

circuitmagic avatar Apr 20 '14 16:04 circuitmagic

@reut10 How does your circuit looks? I'm totally confused with connecting 2 MPU6050 to a Arduino Uno R3 board

54272115 avatar Sep 14 '14 17:09 54272115

@54272115 Do you have the 2 MPU6050 in different address ?

ranqingfa avatar Sep 15 '14 01:09 ranqingfa

we connect the 2 MPU 6050 in parallel and they have different address

On Mon, Sep 15, 2014 at 4:22 AM, RudeBoy [email protected] wrote:

@54272115 https://github.com/54272115 Do you have the 2 MPU6050 in different address ?

— Reply to this email directly or view it on GitHub https://github.com/jrowberg/i2cdevlib/issues/63#issuecomment-55546098.

reut10 avatar Sep 15 '14 12:09 reut10

Be careful if you are using MotionApps. There are hard coded I2C addresses in the current version for some of the initialization. Search for 0x68 in the code....

tsimon57 avatar Sep 29 '14 23:09 tsimon57

Thanks!! I finished my project :)

On Tue, Sep 30, 2014 at 2:09 AM, tsimon57 [email protected] wrote:

Be careful if you are using MotionApps. There are hard coded I2C addresses in the current version for some of the initialization. Search for 0x68 in the code....

— Reply to this email directly or view it on GitHub https://github.com/jrowberg/i2cdevlib/issues/63#issuecomment-57244285.

reut10 avatar Sep 30 '14 06:09 reut10

Hello everybody, We should connect two mpu6050 to an Arduino mega but we don't know how to connect them physically. We know that we have to turn the i2c adress from 0x68 to 0x69 in order to have 2 different adress, one for each sensor. Someone says that it must connect them in parallel but other thinks that it is usefull to set two digital pins high or low to "swich on/off" a sensor in order to read information alternated. moreover we would like to read quarternion or euler data but now we are only able to receive raw data. May anyone help us? thanks

serenaricci avatar Aug 06 '15 09:08 serenaricci

Hi, I am also trying to read values from two MPU6050. I just started looking into this, and for what I've read, raw values can be read from both devices.

My question is, is it possible to read values computed by DMP for two MPU6050?

Thanks!

jorgediosdado avatar May 22 '16 10:05 jorgediosdado

Yes, it is possible to connect more than one MPU6050 to an Arduino. I'm currently testing an extended example of MPU6050_DMP.ino that can connect to any number of accelerometers. The only limit is the number of interrupt pins.

I'll upload a temporary repository here: https://github.com/eadf/MPU6050_DMP6_Multiple Feedback is welcome.

eadf avatar May 22 '16 12:05 eadf