Multiple MPU6050s Sparkfun Breakout Board


Hi!

This is in continuation from my earlier post. As I mentioned, I will be connecting Multiple IMUs on the same I2C bus. Now the problem is this: The IMUs are by default shipped with 0x68 as the I2C address.  Common logic says that we can not have multiple slaves on the I2C bus with same addresses. However, as always there are hacks around this too:

One of the most common hacks is to use software and create a switcher. Switch between the IMUs. Put one IMU on sleep and access the other one. Technically at any given point of time, you will be having only slave device active and talking to the arduino ( here master device ).

Hardware connections: Connect the two slave devices ( here MPU 6050 Breakout Boards ) in parallel, ie SDA and SCL is common to both which is connected to Arduino Pin 4 and 5.

Pseudo Code: Randomly select one IMU. Put the IMU to sleep. Now make the connections as said above. Access 0x68 on the I2C bus. Read the sensor values. Toggle the IMU. Repeat for the other IMU.

I will shortly write a code for the same and upload it here.

Another existing hack is as follows: Have a look here ->

MPU6050 Breakout Board by SparkFun with highlighted AD0.

MPU6050 Breakout Board by SparkFun with highlighted AD0.

The AD0 pin can be very handy in this application. According to Jeff’s library, switching AD0 from the default ground connection to VDD connection changes the address of the IMU from 0x68 to 0x69. Voila! now you can pass this as an argument in your code and use it! 😀

16 comments

  1. Hi, I have the same MPU6050 model as you and i wish to connect 4 of these to 1 arduino uno board. any advise?

    1. One quick solution would be to use 2 Arduino Unos, with 2 IMUs (with addresses 0x68,0x69) on each I2C line.

      1. To use different address i need to connect AD0 pin to voltage high. For Sparkfun IMU, is that mean I need to desoldier the AD0 pin as shown in your figure and connect a wire on it?

      2. Hi,

        Please refer to the image here : https://cdn.sparkfun.com//assets/parts/6/3/5/5/11028-02.jpg

        You can see there are three solder pads for pin AD0, and the center and the right solder pad are shorted by default. If you short the center and the left solder pad, you will essentially be changing the address of the IMU. Hope that helps.

  2. Hi, I do not quite understand what do you mean.
    I see only one solder pad on AD0 pin. I thought I only need to resolder the AD0 solder pad to a wire and connect it to Vcc?

  3. Yeah that too should suffice.

    1. Ok, now i understand what you mean by three solder pad by looking at this diagram…..

      Click to access Triple_Axis_Accelerometer-Gyro_Breakout_-_MPU-6050_v12.pdf

      so you meant the center and the right by default is connected to gnd…so I need to desolder the right one and resolder it to the empty left one…is that rite? but that required a very skill full soldering technique…haha…

      I now simply solder a wire on the whole AD0 pin, connected it to Vcc and it just doesnt work ( i certainly hope I dont spoil it). I will tell you my result once I got the soldering part rite…

      Thanks mate.

  4. FARSHID · · Reply

    Hi there
    i have connected AD0 of one mpu6050 to high. but i dont know how to change the address in library to read both addresses simultaneously.

    I can currently read either from address 0X68 or 0X69. i found somewhere that to switch the address from old to new these functions must be added to library but i have no idea how to do it.

    how can I modify my code as below to read both address at the same time.

    // ——————————————————–
    // MPU6050_read
    //
    // This is a common function to read multiple bytes
    // from an I2C device.
    //
    // It uses the boolean parameter for Wire.endTransMission()
    // to be able to hold or release the I2C-bus.
    // This is implemented in Arduino 1.0.1.
    //
    // Only this function is used to read.
    // There is no function for a single byte.
    //
    int MPU6050_read(int start, uint8_t *buffer, int size)
    {
    int i, n, error;

    Wire.beginTransmission(MPU6050_I2C_ADDRESS);
    n = Wire.write(start);
    if (n != 1)
    return (-10);

    n = Wire.endTransmission(false); // hold the I2C-bus
    if (n != 0)
    return (n);

    // Third parameter is true: relase I2C-bus after data is read.
    Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true);
    i = 0;
    while(Wire.available() && i<size)
    {
    buffer[i++]=Wire.read();
    }
    if ( i != size)
    return (-11);

    return (0); // return : no error
    }

    // ——————————————————–
    // MPU6050_write
    //
    // This is a common function to write multiple bytes to an I2C device.
    //
    // If only a single register is written,
    // use the function MPU_6050_write_reg().
    //
    // Parameters:
    // start : Start address, use a define for the register
    // pData : A pointer to the data to write.
    // size : The number of bytes to write.
    //
    // If only a single register is written, a pointer
    // to the data has to be used, and the size is
    // a single byte:
    // int data = 0; // the data to write
    // MPU6050_write (MPU6050_PWR_MGMT_1, &c, 1);
    //
    int MPU6050_write(int start, const uint8_t *pData, int size)
    {
    int n, error;

    Wire.beginTransmission(MPU6050_I2C_ADDRESS);
    n = Wire.write(start); // write the start address
    if (n != 1)
    return (-20);

    n = Wire.write(pData, size); // write data bytes
    if (n != size)
    return (-21);

    error = Wire.endTransmission(true); // release the I2C-bus
    if (error != 0)
    return (error);

    return (0); // return : no error
    }

    1. Hi,

      In order to address both the MPUs together, you need to do the following:

      Wire.beginTransmission(0x68);
      //Code to read data from MPU
      Wire.endTransmission();
      Wire.beginTransmission(0x69);
      //Code to read data from MPU
      Wire.endTransmission();

    2. Hi, i would like to know if you have solved and if you can actually read from 2 mpu6050 at the same time?
      How did you implement hardware connections?
      Thanks in advance!

  5. simar · · Reply

    Hi, i would like to use the first solution without desoldering and resoldering again.
    I’m looking for the code that you use, but what are the lines that are useful to swithc between IMU?
    Can you also explain me what do you mean with parallel connection?
    Second ASC/ASDA to first SCL/SDA it is right?
    Thanks in advance 🙂

    1. Hi,

      I think this photo should give an explanation : https://goo.gl/W27eCT

      Here, D6 and D7 (They can be any pins) are connected to Q1 and Q2 respectively. They are simple 2N2222 transistors. These are basically controlling your IMU1 and IMU2’s data lines. This is what I meant by parallel connection. I hope it is useful.

  6. simar · · Reply

    Thanks for your super fast reply! 🙂
    I’ll try in the next days.
    I’m starting from the image linked below to use correctly the sensor and it works fine.

    Can you explain me more about code that i’ve to use to implement this type of control?
    Thanks again for your help..

    1. The circuit does look fine.

      I can give you a pseudo code:


      // D6 controls IMU1 when high
      // D7 controls IMU2 when high
      void loop()
      {
      // put D6 high *and* D7 low.
      // Read output from IMU1
      // put D6 low *and* D7 high.
      // Read output from IMU2
      }

      I think this should work, assuming you know how to hook up the transistor in the correct position. You can look that up on google anyhow.

      1. simar · ·

        Thanks for you time, i’ll try. 🙂

  7. simar · · Reply

    I mean the code that you use to control two imu, the single one works fine for me. 🙂

Leave a reply to Ming Cancel reply