Jancio
Posts: 3
Joined: Thu Jul 24, 2014 8:11 am

[SOLVED] Symptom: False GPIO edge detections

Thu Jul 24, 2014 8:27 am

Hello Raspi forum,

I have been using Raspi for a while and I was more than happy. However, right now, I am working on a project where I need reliable detection of the IO inputs.

Project details:
I am trying to detect a person passing through a door with two pairs of IR transmitter/receiver that have a build in relay switch, that connects the wires (similar to a push button), when someone pass through a door (and interrupt the IR beam). The time when the wires are connected is quite short, so I cant use polling and I need edge detection with callback instead. I am using an external pull-up with 10kohm on both pins, so they are not floating.

Issue:
I have seen that I have quite a lot of "passings through" door during night, when I am sure there is nobody passing so I have made a small logging app. I have seen that there are false edge detections on both IO pins in short span of time (8 ms). I have tried to reperoduce the problem and I have found, that the false detection occurs whenever I plug another device (in particular device with transformer (eg. old solder iron, computer charger)) to the same plug as the pi.

My solution ideas:

I have tried to change the pullup to smaller size to make the effect bigger (5kohm) with no difference. Then I have tried to use another power source for pi. After trying a lot of phone chargers with micro usb with no positive effect, I have tried a switching power supply for a computer to provide 5V for pi as well as 3.3V for GPIO input, but there was still no difference. I was still getting random false edges and I was able to reproduce them by plugging other devices in the same socket.

My pi:

I am using the latest rapsbian image from the website. It is B model. The library used is Rpi.GPIO for python.

The question:

Does anybody now how to solve this issue and prevent the false edges? Is there anything else I can provide you with?

TL;DR:
My pi detects false edges on GPIO pins randomly, in particular at the moment when I connect another device to the same power plug.

Thanks a lot in advance!

Jan
Last edited by Jancio on Mon Jul 28, 2014 12:11 pm, edited 1 time in total.

User avatar
joan
Posts: 14175
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 9:06 am

I suggest you see if you get the same problem with the pigpio Python module. It works in a different fashion.

PiGraham
Posts: 3572
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 10:27 am

Jancio wrote: My pi detects false edges on GPIO pins randomly, in particular at the moment when I connect another device to the same power plug.

Thanks a lot in advance!

Jan
This seems to be an interference issue. Long wires with low voltage signals are prone to picking up interference.

You can debounce the GPIO input. In the change callback you can poll the input for a bit and only action the change if the signal is on solidly for some minimum time. Some GPIO libraries include a debounce parameter that may serve this function (or not).
You could try re-routing the signal wires away from mains, or other, cabling.
You could try screened cable, the screen connected to Pi GND
You could use a higher voltage (e.g. 12v) on the wire-relay and a voltage divider at the GPIO input.
You could try a capacitor to GND at the GPIO input to filter high frequency. Combined with a voltage divider this will form a low-pass filter that will reject fast signals.
You could try putting the signal cables through ferrite rings

Some info here might be helpful
http://www.murata.com/products/emicon_f ... _en28.html

User avatar
croston
Posts: 702
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 10:33 am

I would suggest using a 0.1uF capacitor on the pin in question to try and filter out noise.

Jancio
Posts: 3
Joined: Thu Jul 24, 2014 8:11 am

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 6:15 pm

Hello, thank you for the fast answers.

I have tried pigpio for python and it makes no difference.

I have tried to poll input again in the callback, it seems to help a bit. However, I still get some false edges. After trying to include some short sleep between the edge and polling for verification, the problem disappeared. Unfortunately, the time is now too long, so I sometimes miss the passing through door.

The screened cable does sound good, i will give it a try. The problem is, that the problem occurs also when I use only really short cables (15 cm), that are left unconnected- I have disconnected all the peripherals and I am left only with pi, source, pushup resistor and the cables going nowhere. Is it possible that interference can build in such short cable?

I will try the capacitor next week, because I do not have one at home. I will keep you informed.

Thanks again for the answers, you are amazing!

Jan

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12110
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 7:10 pm

if GPIO inputs have a very high impedance it incredibly easy for them to pick up very high frequency spikes, that trigger the edge dectector of the GPIO logic, that what its made for, to detect very fast and short spikes. Any loose wire works as an antenna, and even a few volts will trigger the spike detector. Using very strong pullups- or pulldown-resistors (like 220 Ohm) might prevent spikes from reaching the required level, but capacitors to GND are even better, I recommend low inductance capacitors, like ceramic plate capacitors, a few dozen nano-farads should be enough, and perhaps a few hundred ohms between the inputs with caps to GND, and the actual wires, or better yet, a small inductor like a ferrite bead.

User avatar
joan
Posts: 14175
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Symptom: False GPIO edge detections

Thu Jul 24, 2014 7:22 pm

mahjongg wrote:if GPIO inputs have a very high impedance it incredibly easy for them to pick up very high frequency spikes, that trigger the edge dectector of the GPIO logic, that what its made for, to detect very fast and short spikes. Any loose wire works as an antenna, and even a few volts will trigger the spike detector. Using very strong pullups- or pulldown-resistors (like 220 Ohm) might prevent spikes from reaching the required level, but capacitors to GND are even better, I recommend low inductance capacitors, like ceramic plate capacitors, a few dozen nano-farads should be enough, and perhaps a few hundred ohms between the inputs with caps to GND, and the actual wires, or better yet, a small inductor like a ferrite bead.
These spikes must be quite long to be sampled by pigpio.

Jancio
Posts: 3
Joined: Thu Jul 24, 2014 8:11 am

Re: Symptom: False GPIO edge detections

Mon Jul 28, 2014 12:11 pm

Hello,

I have bought two 0.1 uF capacitors and added them to the circuit between gnd and each gpio pin. It works like a charm, I am not getting any false edges anymore.

Thank you very much.

Jan

Return to “Troubleshooting”