I have a Raspberry Pi 3B+ that I'm using with two I2C devices on the same bus. The first device is a DAC from Adafruit (product here). The second device is an accelerometer, also from Adafruit (produce here). The DAC is used to control a DC motor driver for a very large 24V motor. The accelerometer will measure vibrations caused by the motor.
When I use either device with the other disconnected, it works great. (I'm using the python libraries provided by Adafruit for both devices.) But when I try to use both devices at the same time (that is, both are powered on), I get interference. The accelerometer reports frequent spikes in acceleration (despite being perfectly still), and the DAC will occasionally change its output voltage. Also, the RPi frequently fails to read the accelerometer, throwing me an IOError. I don't understand what's going on.
The DAC is powered by 5V. The accelerometer is powered by 3.3V. Both devices have built-in 10kOhm pullup resistors on their I2C lines going to their respective voltage sources. The RPi has built-in 1.8kOhm pullups.
Even though the DAC is on 5V, I measure 3.3V on the I2C lines as the resting high state. Also, the accelerometer is designed to work with 3.3V or 5V I2C voltage.
The DAC is connected to the Raspberry Pi by mere 4-inch wires, which are held apart from each other to minimize parasitic capacitance and EMI. The accelerometer is connected by 3 ft wires, which may seem long, but my o-scope shows clean I2C waveforms at the device end. At the RPi end, the waveforms are not quite as clean, but they seem good enough.
At the accelerometer, the I2C waveform is slightly rounded when the DAC is turned off (which is what you'd expect from high parasitic capacitance). When I turn the DAC on, those waveforms get crip and square. I would've expected the opposite to happen when I add a second device to the bus.
I took the RPi, DAC, accelerometer, and motor driver out of the machine for further testing. I disconnected the 24V power supply and 24V motor and left them in the machine. When I test the I2C devices now, I am unable to replicate any of the errors. It works flawlessly.
I considered that the problem might be EMI from the motor being picked up on my long accelerometer wires, but the motor did not have to be moving for my problems to appear. My 24V power supply is switch-mode, so perhaps it is what was producing EMI.
I considered faulty/damaged/shorted-while-troubleshooting components. I tried a new accelerometer and a new RPi and got the same results. I have not tried a new DAC. However, if any of these components are faulty, I would not expect them to work at all; and yet they work fine most of the time.
I tried changing the I2C frequency on the RPi between 100Hz to 100kHZ (the default) but I saw no effect.
I have verified all the wire connections.
As it is, I cannot put my electronics back in the machine without them behaving erratically.
Just for kicks, I put two knots in the accelerometer wire. The errors and spikes coming from the accelerometer were much reduced. However, I lost all communication with the DAC.