GY521 failing with long wire

I have a project involving multiple components on an I2C bus, namely, a TF02 Pro Lidar, a GY521 IMU, and a SX1509 GPIO expander board. The GY521 is soldered directly onto a protoboard with my esp32, and the Lidar is on a short connection of about 4 inches. Both work fine in isolation. The SX1509, however, is on about 3-4ft of wire. When connecting all three components to the I2C bus, the GY521 fails to communicate but the others work fine. However, if I use a much shorter I2C connection, all three devices work fine. My question is (A) why would 3 feet be too long and (B) why would the SX1509 work just fine on the long wire while the GY521 fails? Some notes from my test results:

  • The GY521 still fails if the long wires are connected floating, without the SX1509 on the other end
  • The measured capacitance of the two wires is around 40 picofarads, well under the I2C maximum of 400 picofarads
  • I tried different pull-up configs. The SX1509 has builtin 10k pull-ups and the GY521 has 2.2k pull-ups, and the Esp32 should have builtin pull-ups. I though it was possible the 2.2k was too strong and desoldered them but that doesn't seem to be the case
  • I also tried running the bus at 100kHz rather than 400kHz with no success

Use twisted pair cable. Add a capacitor (0.1µF) to the module power connector. Keep the pullup resistors removed, they go to 3.3V instead of 5V.

If nothing helps add an I2C level shifter for the 3.3V MPU6050.

because I2C ist designed as INTER INTEGRATED CIRCUIT ... to be used on one PCB not for a 3 feet long cable.

Either use shorter cables or I2C extender driver.

1 Like

4ft is 1.2m

Keep SDA away from SCL.
If you use twisted pair as DrDiettrich wrote, then combine SDA with GND and combine SCL with GND. Do not combine SDA with SCL in a twisted pair. If you use a flat ribbon cable, then do not put SDA next to SCL.

In theory, the maximum length of a cable can be calculated with its capacitance. In real life that is useless, because crosstalk between SDA and SCL is the main problem.

All devices have a 3.3V I2C bus and your ESP32 has a 3.3V I2C. You don't need a level shifter. The GY521 module has a voltage regulator. If you power that module with 3.3V, then the MPU-6050 get a lower voltage. Can you bypass that voltage regulator ?

Your MPU-6050 is probably fake. It is also old and outdated and noisy. Please buy a more up to date sensor.
The GY521 has pullup resistors that are often 4k7, but can be anything the manufacturer happens to have laying around. The 2k2 on your board is not so bad.

You have to determine the total pullup for SDA and SCL of all combined pullup resistors. It should not be lower than 1k. The maximum sink current (to make SDA or SCL low) is 3mA.

Thanks for the advice everyone. I boosted the MPU voltage to 5v, and ended up shortening the I2C run down from 1m to about two inches. Regarding pull ups, I'm not certain how to calculate properly given that the TF02 Pro lidar is a black-box system with no schematics and I don't want to teardown. The gyro now works intermittently, but about every other reading fails if the other devices are on the bus. I'm going to conclude that with such a short run and only this sensor failing it must be a cheap, defective MPU and I'll try replacing it. It's a little too late to substitute another sensor at this point in the design process

i2c standard:
"This depends on the load of the bus and the speed you run at. In typical applications, the length is a few meters (9-12ft). The maximum capacitive load has been specified (see also the electrical Spec's in the I2C FAQ). Another thing to be taken into account is the amount of noise picked up by long cabling."

Note that the old PS2 computer Mouse and Keyboard uses i2c. The Nintendo Wii Nunchuk uses i2c so cabling is appropriate to use.


note that the GY-521 requires a 5V power supply and also note that the i2c Buss has 2 4.7k ohm resistors pulling the i2c lines to the 3.3V side of the onboard voltage regulator.

So using additional pullups will only complicate things.
Z

With a unknown system, it is possible to measure the sink current for SDA and SCL.
Upload a empty sketch with only Wire.begin() and use a multimeter to measure the shortcut current from SDA to GND and from SCL to GND.
See also my Wiki at Github about the pullup resistors and the sink current.

I'm curious about the gyro working intermittently. What happens when the gyro does not work. Do you mean that the accelerometer always works ? In that case the I2C bus is okay and the fake MPU-6050 has a bad gyro.

Can you show a photo of your project with the wires ?
A breadboard has bad contacts and jumper wires can be broken. So if you use a breadboard, and you look at the wires, assume that every wire and every connection can be bad.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.