Multiple GY-521 sensors on Arduino

Hi there,

I have tried the GY-521 sensor on Arduino by using the guide from (Arduino Playground - MPU-6050). It worked well. Can anyone guide me on how can I add another GY-512 module please? I am planning to use a total of four of them connected to my Arduino Uno. How do I define the additional sensor modules in the program?

It is only possible to connect two of these sensors to your Arduino, not four. On the first, you connect the AD0 pin to the GND, on the second, you connect the AD0 pin to the 3,3V pin. The first will have I2C address 0x68, the second will have address 0x69.

I don't know for sure, but I think you should add some extra things:

#define MPU6050_I2C_ADDRESS_unit2 0x69 // the address of your second MPU

The rest of the code is also used in a slightly different way. Everywhere where it says "MPU6050_I2C_ADDRESS", you can choose which MPU you want to use.

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
}

This code will 'do something' with the first MPU, when you use MPU6050_I2C_ADDRESS, and it will 'do something' with the second MPU when MPU6050_I2C_ADDRESS is changed to MPU6050_I2C_ADDRESS_unit2. The same goes for MPU_write()

Hi Muddy, :slight_smile: thank you for the reply. You have mentioned that I could only connect 2 of these sensors and not 4. Why do you say so?

Can you explain more on the AD0 pin on the board please? I hope to understand it better.

Regarding the wiring, can I connect the SDL and SDA of the both the sensor modules in parallel to the Arduino board? I am sorry, I have never done the I2C communication before. Can you guide me on the wiring as well?

Dear Mr. Muddy,

Millions of thanks to you. I have managed to make the two sensor modules work. XD

Can you please post your code for two GY-521 sensors?

Are you using the DMP feature or just reading raw data?

yu_buffon:
Can you explain more on the AD0 pin on the board please? I hope to understand it better.

Regarding the wiring, can I connect the SDL and SDA of the both the sensor modules in parallel to the Arduino board?

AD0 is the device address pin, the device is thereby identified, or "named", as "#0" or "#1".

By adding additional circuitry to enable/disable, to route, the SCL and SDA then it may be possible to have more devices.

Hi!

I'm trying to connect two GY-521 too but I have problems with quaternions obtained. Sometimes the values are greater than one and other times the values leap.
I think it could be because there are problems in my code (attached, sorry for the "spanglish") with the use of I2C bus but I can't identify the problem yet.

Could anyone connect two GY-521 without these problems?

Can anyone help me?

Thanks in advance.

Code.txt (11.8 KB)