I2C on Power Supply vs Computer Power

Hey everyone!

I've been recently working on a project involving an arduino nano communicating with two VL6180X sensors through I2C. Everything works pretty well when powered from a computer through the USB port, but when I switched over to an external power supply, my sketch stopped working.

I connected it to both the computer and the power supply to try and figure out what was happening with the sensors by printing out the values to the console. Turns out one of the two sensors stopped working when the external supply was connected.

After a lot of testing, it turns out to be because the cable connected to the failing sensor was too long (+/- 60cm of ribbon cable).

So, more than an answer or suggestion, I was wondering if someone could shed some light over why this length of cable works when powered from the computer but NOT when powered with an external supply (9V Vin)? I've already checked gammon's very thorough page on I2C but I didn't find a clear answer to this over there.

Thanks! :slightly_smiling_face:

Do you use the Adafruit VL6180X module with level shifters, which is compatible with 3.3V and 5V Arduino boards ?

Crosstalk between SDA and SCL is the worst problem of the I2C bus. That means a flat ribbon cable is a bad choice. Did you put SDA and SCL next to each other in a flat ribbon cable ? That is terrible ! Split the flat ribbon cable into seperate wires and it will work.

The Arduino Nano has no fancy circuit to switch between USB power and VIN power. It is just a diode from the USB 5V to the VCC.
The USB connector on the computer has 5V. The cable might drop the voltage by 0.2V and the diode by 0.5V. Then your board will run at 4.3V (measure the 5V pin). The 3.3V is still 3.3V, because the voltage regulator for 3.3V has no problem with that.
When applying a power supply to the VIN, then the board runs at 5.0V.

When using a module with a onboard voltage regulator or using the 3.3V of the Arduino board then the distance between the 3.3V and the 5V varies when the 5V varies. That has influence on signals and level shifters.

Note: Can you apply 7.5V to VIN instead of 9V ? The Arduino Nano has a small voltage regulator. If you connect a number of leds to it (or other things that need current), then the voltage regulator will get hot with 9V, therefor 7.5V is better.

Thanks for your answer! So other than the bad choice of cable, it all seems to come down to small voltage drops that change the potential between the arduino VCC and the 3.3V on the sensor (not using the adafruit one, but rather the Pololu one, but there's not much of a difference), which in turn affect the signals and level shifters. I'll keep that in mind next time I work with I2C. Thanks!