I've been working on a simple project involving a Raspberry pi and some switches. I would never thought I would have any problem for something as simple as a switch, but here I am.
The 2 wires from my switch are connected to the raspberry pi. One is connected to ground, the other is connected to a GPIO. The internal pull-up resistor of the raspberry pi is used.
The length of the cable is around 7m.
The program is just a matter of reading the GPIO and sending commands according to state changes.
My problem is simple: everything works fine for some time, but eventually the switch ends up not "working" anymore (reading low state whether or not the switch is pushed).
I checked the switch, and of course it still opens and closes as expected, so the problem comes from somewhere else. What I did is I disconnected the switch, and measured the voltage between the two wires: I get 0V.
This is my first clue for thinking something bad happened to the raspberry pi. Because the internal pullup is used, I should have measured around 3.3V. And this is indeed what I measure if I replace the raspberry pi with a new one.
I thought this might be caused by EMI, causing voltage spikes? I really have no experience dealing with this. So what I did is I replaced the raspberry pi, and I added an external pull-up resistor with a lower value (the internal resistor is 30k, I used 1k as external resistor), guessing that this would reduce the noise. But the same thing happened after one day.
This time, when I measure the voltage at the GPIO, I have around 1.2V. According to the reading, using a simple voltage divider, this is equivalent to a resistor value of 600Ohms pulling down the signal inside the raspberry. Definitely not normal.
Then I tried to replace the wires with shielded audio cable, connecting the the shielding to ground. And half a day later, yet another raspberry pi was good for retirement.
I have now placed a ceramic capacitor between gnd and the GPIO (100nF), and for now it seems to be OK (it's only been 12h) but I have to say I have no confidence because I'm not sure what is the reason for this problem.
On the same system, I have another switch with a much shorter wire (1m) and I never had any issue with this one. This is why I guess my wires are acting as antennas, but I don't know for sure (especially since shielded wires did not help).
Any idea about what could happen would be appreciated.