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?
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: 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. |
|||||||||||||||||||||
|
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. |
|||
|
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? |
|||||||||
|