Page 1 of 1

RPi.GPIO sudo versus sudo-less performance differences

Posted: Thu Nov 12, 2015 11:43 pm
by talcat
Hey guys!

I've recently just updated RPi.GPIO to 0.6.0a3 in order to be able to access the GPIO pins from not root. However, I've noticed a very annoying behaviour (that I think has also been documented viewtopic.php?t=124738.

Basically, 70%-90% of the time when trying to either GPIO.wait_for_edge or GPIO.add_event_detect I get the following Runtime Error:
RuntimeError: Failed to add edge detection or RuntimeError: Error waiting for edge

However running the code under sudo never has any runtime errors.

Does anyone have any ideas what could be causing this problem?

(Here is some example code):

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def call(channel):
        print "callback"

GPIO.add_event_detect(25, GPIO.RISING, callback=call)

try:
        GPIO.wait_for_edge(24, GPIO.RISING)
except KeyboardInterrupt:
        print "Exit"
        GPIO.cleanup()


Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Mon Nov 16, 2015 2:08 pm
by -rst-
Might want to log a ticket in sourceforge http://sourceforge.net/p/raspberry-gpio ... rce=navbar or try to contact the author memberlist.php?mode=viewprofile&u=4165

Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Sun Nov 29, 2015 12:48 am
by BigNeilM
I'm seeing it on APlus and BPlus but not on a Pi2. Seems to occur in python 2 and in python3. Latest Raspbian Jessie. Ticket raised with Ben Croston.

Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Fri Dec 04, 2015 3:44 pm
by tjaap
I had the same problem, but after spending a few hours (of course) on trying different workarounds, I discovered that it was not actually the GPIO module but entirely different problems in my code that prevented the script to execute correctly from rc.local. In my case the permissions on my scripts were wrong and a subprocess was called incorrectly. Maybe something like this is going on in your case as well? HTH.

Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Tue Dec 08, 2015 8:49 pm
by talcat
I doubt it? Again, this happens (on both an RPI B and RPi 2) on very simple code - a script that literally just sets edge detection on a pin....

Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Wed Dec 09, 2015 9:39 am
by BigNeilM
-rst- wrote:Might want to log a ticket in sourceforge http://sourceforge.net/p/raspberry-gpio ... rce=navbar or try to contact the author memberlist.php?mode=viewprofile&u=4165
Does anyone know if Ben Croston is still actively supporting this code?
Or is it something someone else (RPi Foundation?) has taken over?

The reason I ask is that the sourceforge repository has an old version and a description file which is way out of date. I just want to be sure we're asking the right person to fix a problem.

Re: RPi.GPIO sudo versus sudo-less performance differences

Posted: Sat Jan 02, 2016 4:46 pm
by ben_nuttall
This is a bug with RPi.GPIO that Ben Croston is aware of. We found the issue when developing GPIO Zero, and Dave Jones has been helping to find a fix or it in RPi.GPIO.

See my solution to a similar issue from a GPIO Zero user here: viewtopic.php?f=32&t=129015&p=874227#p874227

I've noticed that the problem occurs on the first attempt but not the second.

Interesting that you've noticed the error doesn't occur when the program is run by the root user. Noted.