Pages: [1]   Go Down
Author Topic: Multiple GY-521 sensors on Arduino  (Read 2027 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

I have tried the GY-521 sensor on Arduino by using the guide from (http://playground.arduino.cc/Main/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?
Logged

Eindhoven Netherlands
Offline Offline
Jr. Member
**
Karma: 2
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
#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.

Code:
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()
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Muddy, smiley 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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Mr. Muddy,

Millions of thanks to you. I have managed to make the two sensor modules work.   smiley-lol
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Online Online
Edison Member
*
Karma: 64
Posts: 2448
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
http://en.wikipedia.org/wiki/I2C

By adding additional circuitry to enable/disable, to route, the SCL and SDA then it may be possible to have more devices.
http://www.ti.com/lit/ds/symlink/sn74hc125.pdf

Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.77 KB - downloaded 53 times.)

* Scheme 2 GY-521.jpg (756.78 KB, 1359x1803 - viewed 317 times.)
Logged

Pages: [1]   Go Up
Jump to: