talcat
Posts: 5
Joined: Thu Nov 12, 2015 8:22 pm

RPi.GPIO sudo versus sudo-less performance differences

Thu Nov 12, 2015 11:43 pm

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()


-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

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

Mon Nov 16, 2015 2:08 pm

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
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

BigNeilM
Posts: 25
Joined: Sun Jul 15, 2012 12:45 pm
Location: Cambridge

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

Sun Nov 29, 2015 12:48 am

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.
Neil Matthews
Lost count how many of As, Bs, APluses, BPluses, Pi2s and now a couple of Zer0s. :-)
Get your E-paper HAT at www.percheron-electronics.uk/shop

tjaap
Posts: 10
Joined: Sun Jul 21, 2013 10:14 am

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

Fri Dec 04, 2015 3:44 pm

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.

talcat
Posts: 5
Joined: Thu Nov 12, 2015 8:22 pm

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

Tue Dec 08, 2015 8:49 pm

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....

BigNeilM
Posts: 25
Joined: Sun Jul 15, 2012 12:45 pm
Location: Cambridge

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

Wed Dec 09, 2015 9:39 am

-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.
Neil Matthews
Lost count how many of As, Bs, APluses, BPluses, Pi2s and now a couple of Zer0s. :-)
Get your E-paper HAT at www.percheron-electronics.uk/shop

User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 231
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

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

Sat Jan 02, 2016 4:46 pm

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.
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

Return to “Python”