4
\$\begingroup\$

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-521 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?

\$\endgroup\$
5
\$\begingroup\$

The GY-521 sensor breakout is an I2C slave device. As long as you can obtain (or configure) the additional sensors as I2C slaves with different slave addresses, they would be controlled the same way as the first one, other than having separate communication initiation for each of the sensors, and then reading the data back from each sensor by its I2C address.

Unfortunately, the MPU-6050, the Motion Processing Unit IC in the GY-521, supports only two I2C slave addresses, so at best you would be able to find (or modify) break-out boards to support these two addresses (by the logic level applied to pin AD0 / pin 9 of the IC). If you actually need more than 2 devices at the same time, look at other similar devices and their corresponding breakout boards.

The physical wiring involves all the modules being connected in parallel on the same pins you have used already to control the first module, also known as an I2C bus. This would only work if only one of the modules has its pull-up resistors enabled. On the schematic for the module, these pull-up resistors are marked R4 and R5, 4.7 kiloOhms each.

On the GY-521 board shown in the link provided in the question, the pull-up resistors appear to be 2.2 k each, as seen below:

board

The actual board you have would need to be examined, to verify which specific little SMD parts are the pull-up resistors on it: Not too difficult to do, since they are tied to the SDA and SCL header pin pads.

On all but one of the sensor boards, you would need to de-solder those two resistors carefully, without messing with any other parts or other solder junctions on the board. If you are not accustomed to working with SMD components, it might be better to start by practicing on some scrap boards salvaged from condemned printers or other hardware, first.


It is a bit much to ask someone to write the code for you, but there are several Arduino tutorials on communicating with multiple I2C devices sharing a bus. Search on the same site you found the guide for this module.

\$\endgroup\$
9
  • \$\begingroup\$ Hi Anindo, thank you for the reply. I have examined my boards and they are 2.2k resistors. Should I remove the resistors on my second board and link the second board to the first board? Or is there any other way without making physical alteration on the board, code modification maybe? I am sorry, I have never done the I2C communication before and I am confused. Moreover, I had difficulty in understanding your comments. Please kindly use simple and English. Short sentences would help. P.S. I never requested anyone to write the program for me. I just hope that someone would guide me on this. \$\endgroup\$ – Robert Jun 17 '13 at 14:30
  • \$\begingroup\$ @Robert For using just 2 of the modules, you can try without removing the pull-ups: That will cause a 1.1 k pull-up value on the SDA and SCL lines, which may work. You will also have to figure out changing the pin 9 connection on one of the boards, to change the device address: See the datasheet for the MPU-6050. Regarding simplifying my words: I'll try and edit the answer later, if you point out specific parts that are difficult. Thanks for the feedback. \$\endgroup\$ – Anindo Ghosh Jun 18 '13 at 3:08
  • \$\begingroup\$ Hi Anindo, from the datasheet I found out that the slave address of the sensor is 7 bits long. The logic level on pin AD0 of the 1st and 2nd sensor can be set as logic low and logic high respectively. While coding I can define as follows, #define MPU6050_I2C_ADDRESS 0x68 //1st Sensor #define MPU6050_I2C_ADDRESS_2 0x69 //2nd Sensor Am I on the right track here? I am still unsure about the physical wiring of the I2C bus. Can I connect them in parallel to the Arduino? I couldnt find info on this from the datasheet. P.S. Long sentences can be shortened. Thank you. \$\endgroup\$ – Robert Jun 18 '13 at 7:57
  • 1
    \$\begingroup\$ @Robert Correct: You would have to set the AD0 line value for each of the modules from code, and then they'll respond to the two possible addresses. You will need two GPIO pins from the microcontroller for these two pins - or you could use resistors to pull-up the AD0 on one, and pull it down on the other. For wiring the I2C pins, just connect each module in parallel. \$\endgroup\$ – Anindo Ghosh Jun 18 '13 at 8:03
  • \$\begingroup\$ Thank you Anindo. Can I just connect one of the ADO to the Vcc and short another one to the ground? Or do I need to use the resistors? What is the significance do the resistors make? \$\endgroup\$ – Robert Jun 18 '13 at 14:21
2
\$\begingroup\$

Since you require four of these i2c modules, which only support two addresses (Based on the AD0 pin), you have four options.

The first is using multiple i2c buses on your Arduino. There are various software i2c implementations for Arduinos. These are software (or bitbanged) i2c code. They add overhead, but for most projects, should be just fine. These take up another two pins.

The second is using an i2c switch/multiplexer/bus/buffer chip. These chips either physically switch between two (or more) buses, or use buffers or other methods to allow multiple buses on one side to communicate on a single bus on the other side. Some use an extra input to switch, others are i2c devices themselves (you send an i2c message to do the switching).

The third and fourth are a bit different, and require a couple of free pins, and depends on the i2c chip you are using. Not all i2c chips will act the same to this. The third depends on the speed it takes to restart from a power loss, or if it takes a while to calibrate. This would be switching the power off to one of the modules. Any small signal transistor or mosfet would work for this. Since the mpu-6050 has a recommended power up procedure (VDD then VLogic) this might not be the best.

The final option, the ad0 pins on the four modules can be tied to four free gpio on the arduino, and then you can switch the ad0 so that only one of the i2c devices has the unique address at a time. Three would have the same 0x68 address (AD0 Low), the fourth would have 0x69 (AD0 High), read the sensor, then switch it so the third has the 0x69 address, read it, rinse lather repeat. This adds just a little code to your project while requiring no extra parts. This might not work if you do it too fast, or if the ic does not like the AD0 pin being switched after power up, but it's the cheapest and simplest way.

\$\endgroup\$
1
  • \$\begingroup\$ Option 3b) use 2 transistors in place of each one, to switch the i2c lines rather than power. Would that work? What about just SDA, if you remove almost all pullups on SCLs? \$\endgroup\$ – kaay Feb 17 '16 at 8:03
-2
\$\begingroup\$

I don't think you can add 4 identical I2C devices as their bus device IDs will be the same. Why would you need 4 accelerometers - one gives you all axis' of movement?

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for the reply. I am building a lower limb exoskeleton. I am placing 2 of the sensor module on one leg, thigh and shin. The other twos are placed on the other leg to get feedback as I control the motors. \$\endgroup\$ – Robert Jun 17 '13 at 14:16
  • \$\begingroup\$ Actually, for most devices you can place more than one of them on the same I2C bus. Only part of the address is hard-coded in the device. A few bits are settable via external pins. \$\endgroup\$ – Federico Russo Sep 4 '13 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.