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.

More details

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.

  • \$\begingroup\$ Those long leads do seem suspicious. But can you absolutely confirm that the problem occurs when both are connected, even if you only run the software for one? \$\endgroup\$ Commented Jun 12, 2019 at 20:19
  • \$\begingroup\$ 3-ft is a long wire for I2C. It might work alone, but the added capacitance of the other device might be screwing things up. What happens if you shorten by 50% \$\endgroup\$ Commented Jun 12, 2019 at 20:20
  • \$\begingroup\$ @ChrisStratton When both devices are connected, but the DAC is powered off, the accelerometer works perfectly every time. \$\endgroup\$
    – Eli-1.772
    Commented Jun 12, 2019 at 20:22
  • \$\begingroup\$ I realize that 3-ft is very long, but when I move the electronics out of my machine and onto my desk, everything works fine. Also, I o-scoped the I2C at the accelerometer and found pretty good waveforms. \$\endgroup\$
    – Eli-1.772
    Commented Jun 12, 2019 at 20:24
  • 2
    \$\begingroup\$ "when I move the electronics out of my machine and onto my desk, everything works fine" that sound like pickup from the motor circuitry. Try it with the DAC powered but the motor amp off. Incidentally, having an unpowered I2C device on a bus is a horrible spec violation; you're lucky that worked at all. \$\endgroup\$ Commented Jun 12, 2019 at 20:48

1 Answer 1


I solved the problem. The interference on the I2C lines was probably caused by EMI from the switching power supply and PWM motor controller.

The I2C frequency is 100kHz and the noise frequency was ~3MHz, so I made a low-pass filter. I put 500pF capacitors on both clock and data, and I put 39Ohm resistors in series directly off of the RPi. (Interestingly, the "official" maximum bus capacitance of I2C is 400pF.) This significantly attenuated the noise.

I also twisted the 3-ft I2C wires of the accelerometer: clock with GND, and data with 3.3V.

The errors and spikes in the acceleration readout are totally gone now and it works great.

  • \$\begingroup\$ There are only two things that could be better: First, the I2C signal is very clean, but still has a little noise and occasional spikes; this doesn't seem to affect the performance, but ideally they would be eliminated. Second, when I turn on the motor controller, I get a little blip in the acceleration readout, which is minor, but still unexplained. \$\endgroup\$
    – Eli-1.772
    Commented Jun 19, 2019 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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