Removing noise from I2C inputs.

I have 32 input switches to monitor so I’m using multiple MCP IC‘s communicating over I2C.

I’m getting noise when nearby solenoids are activated. There is no impact on the GPIO pins but just when using I2C. By noise I mean the I2C inputs get an error and my code stops.

I have seen other posts about reducing the length of wire or moving the solenoid’s but that is not an option. Why is the I2C sensitivity different than the GPIO pins and is there a way to change this so they have the same sensitivity? I am a newbie and self-taught so I don’t understand pull ups or downs yet. I found a simple push button (input) and LED (output) circuits and I’m using resistors.

Anyway, works with GPIO but I2C is too sensitive if that’s the correct word. Any help would be much appreciated. I also tried setting a timer (debouncing I think), but that doesn’t work. I’m going to try a ferrite core next but not sure if that should go near the I2C or solenoid. But would really like the pins to react the same. Thanks for any help.

Sent from my iPhone

2 Answers 2


This is to be expected. I²C is an open drain bus i.e. NO active pull-ups, intended for short range low speed on board interconnection between devices.

"As I mentioned I’m a newbie so I don’t know what pull ups are."

I did answer "Why is the I2C sensitivity different than the GPIO pins", but unless you have the requisite background you will have to do some more learning.

In simpler terms CMOS outputs (what you call GPIO pins) have active pullup & pulldown, so are capable of driving loads at higher speed and over longer distances.

I²C only have passive pullup, so are limited in speed due to capacitative loading on longer wires and are subject to interference.

In simple terms I²C is not designed to do what you want and you are attempting to use it outside its capacity. An engineer would NOT use I²C, and would NOT put on the same board as solenoids.

Your Question is not specific to the Pi, it is a general EE question.
An engineer would NOT use I²C - there are better interfaces, and techniques to isolate control circuitry from power circuitry, which is probably the underlying cause of your problems.

It is possible to extend the range of I²C (with additional circuitry) but it is far better to use a more appropriate interface.

The solutions are to

  1. reduce the length of wire
  2. move the solenoid and isolate from control circuitry.
  • AFAIK, the default i2c bus (ch 1) on RPi does have pullups on the board.
    – Seamus
    Commented Nov 9, 2021 at 23:07
  • @Seamus I said nothing about pullups but there is no active pull-ups like TTL & CMOS. Those of us who worked with RTL in the 1960s are only too familiar with the limitations of passive pull-ups.
    – Milliways
    Commented Nov 9, 2021 at 23:57
  • Fortunately, RTL was before my time :) I'm familiar with the circuitry, but not the nomenclature. I wouldn't say this is to be "expected" necessarily as the OP didn't tell us what the range/distance was. But maybe something like the LTC4311 could be added to address your concern?
    – Seamus
    Commented Nov 10, 2021 at 7:12
  • Thanks for the response. As I mentioned I’m a newbie so I don’t know what pull ups are. My question still is why is the behavior different on a raspberry pi’s GPIO pins versus using I2C. Commented Nov 10, 2021 at 18:12
  • 1
    Hi @RobertSalamon and Milliways. Please try to calm down and adhere to the be nice policy. I take it that you have widely differing opinions on the topic, still I'd like to not have this discussion heat up any further.
    – Ghanima
    Commented Nov 11, 2021 at 7:17

The initial answer:

It sounds like your solenoids are emitting electromagnetic interference (EMI); i.e. the solenoids are the source of the interference, the i2c circuitry is the victim. Your first step should be to remediate the source, rather than the victim.

I can't give you much in the way of specific advice because you didn't provide a schematic, nor a photograph of the wiring and physical layout. However, here are a couple of things that should help:

  1. Solenoids employ an inductive coil which generates back emf when the current flow is interrupted. This back emf can be a strong source of EMI, and should be suppressed. I would say - not knowing anything else about your environment - that the solenoids are a likely suspect as the source of the interference on your i2c circuit. The schematic below shows a simple suppressor to add (externally) to the solenoid coil.
    D1 and R1 form a "snubber" or suppression circuit which will act to limit the back emf voltage spike generated when the switch (or transistor) is opened to release the solenoid (current flow ceases). The 1N5819 is a Schottky diode - often used for suppression as they offer better performance than a p-n junction diode.


simulate this circuit – Schematic created using CircuitLab

  1. Wiring runs may enable the interference generated by the source to propagate. Try to keep all wiring runs as short as possible. Physical proximity of the i2c wiring to the solenoid wiring will have an effect - more separation will likely reduce the level of interference. Wrt your i2c wiring, twisting the wire leads between your RPi's i2c GPIO pins and the device(s) on the bus may make the i2c circuit less susceptible to interference generated by the source.


A couple of conflicting viewpoints have emerged here. Debate can be useful to see a problem in a different light, so I hope this edit will provide a more useful and interesting answer.

I want to say first that I feel some relevant details (e.g. wiring length, victim-to-source separation distance) are missing from the question - details that could inform better answers. But in all honesty, even if these details were included, they may not be sufficient for a concise & definitive answer: "Why does this not work, and what must be done to make it work?"

That said, I'll try to get to the point: Despite the somewhat limited scope of applications for i2c when it was developed in the 1980s, it's still in widespread use today. This due to the fact that i2c has evolved over 40 years, and has been adapted to work in applications that might have been impractical in the past. I don't mean to come across as an "i2c evangelist"; I'm only trying to point out that i2c's shortcomings are well-known, and have been mitigated to some degree over its 40 year life. I see no reason why i2c cannot work in the OP's application here - within reasonable limits.

The two issues likely responsible for the OP's question are:

  1. The open-drain transistors connected to the bus through pullups may not be able to switch the current necessary to overcome the signal distortion caused by the bus capacitance, and

  2. The back-emf generated from the solenoids may be coupling into the bus through radiation and/or conduction to corrupt the signal.

The approach to a solution here is exactly the same as in most other development projects: follow the cause & effect relationships to mitigate the issue(s). Some instrumentation (e.g. a good oscilloscope) would definitely be useful, but probably not essential. IMHO, this is the attraction of what we do here: experimentation and learning. Challenges that inspire creative solutions make for a fun hobby... jigsaw puzzles are available for more mundane interests.

Based on my understanding of the issues, three remedies come to mind:

  1. Reduce errors by reducing the clock speed - per the Shannon-Hartley theorem

  2. Suppress the back-emf generated by the solenoids (see schematic & discussion above)

  3. Incorporate "bus buffering" to overcome i2c's open-drain drivers. There's a very good series of articles on Hackaday focused on overcoming i2c's limitations. This will be of interest to anyone interested in pushing the limits of their i2c projects. In addition, the LTC4311 is another potential hardware solution to build a more robust i2c.

  • Hi Seamus, Thanks for the response. Yes I have isolated it to the solenoid. When I fire the solenoid it does not affect my GPIO pins however it does affect my I2C. The wires are the same length so something about I2C being more sensitive. Commented Nov 10, 2021 at 18:15
  • And just thinking more about it do remember a discussion I had about the backflow when I bought the solenoids. I will definitely investigate this more.So if I understand what’s happening, after the solenoid fires the backflow goes back down the wire which is being picked up by my other I2C wires. Commented Nov 10, 2021 at 18:25
  • Had to break up my comment as it was too long. But to continue… Apologies if my terminology is basic. I jumped in headfirst on this project and it’s coming along quite well even though I don’t understand all of the concepts. I had a ton of circuits working individually and the solenoids firing in a separate space and when I put them together that’s when this issue arose. Basically my SIT test didn’t work after all my assembly testing did work. I’m a software guy and this project has kept my sanity during the past year and a half. Quite fun and interesting. Thank you Commented Nov 10, 2021 at 18:27
  • @RobertSalamon Milliways tried to tell you why I2C was more likely to be affected. You should read their answer again, carefully. Commented Nov 11, 2021 at 2:47
  • 1
    Yes, I saw that but obviously the RPi wouldn’t have them if they were not supposed to be used in a simple scenario. So the point is how to make them less sensitive or reduce the back flow. Commented Nov 11, 2021 at 4:07

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.