Jump to content

GPIO access


Andy

Recommended Posts

After reading several threads without success I need to ask again how I can get permission as a "normal" user to use the GPIO pins via my python script:

#!/usr/bin/python
import time

PIN_NUM = 200


print "GPIO %s" % PIN_NUM

try:
   # check to see if the pin is already exported
   open(''.join(['/sys/class/gpio/gpio',str(PIN_NUM),'/direction'])).read()
except:
   # it isn't, so export it   
   open('/sys/class/gpio/export', 'w').write(str(PIN_NUM))

# set gpiochip198 to output
open(''.join(['/sys/class/gpio/gpio',str(PIN_NUM),'/direction']), 'w').write('out')

for i in range(1000):
   open(''.join(['/sys/class/gpio/gpio',str(PIN_NUM),'/value']), 'w').write("1")
   time.sleep(0.5)
   open(''.join(['/sys/class/gpio/gpio',str(PIN_NUM),'/value']), 'w').write("0")
   time.sleep(0.5)

# remove GPIO87 folder from file system
open('/sys/class/gpio/unexport', 'w').write(str(PIN_NUM))

 

 

I get this error:

Traceback (most recent call last):
  File "testGPIO.py", line 17, in <module>
    open(''.join(['/sys/class/gpio/gpio',str(PIN_NUM),'/direction']), 'w').write('out')
IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio200/direction'

 

So I tried to add:

SUBSYSTEM=="gpio", ACTION=="add", RUN="/bin/sh -c '\
        chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
        chown -R root:gpio /sys$DEVPATH && chmod -R 770 /sys$DEVPATH\
'"

into /etc/udev/rules.d/90-gpiomem.rules

 

and yes my username is the GPIO group....

 

Can someone help me further...thx

 

Andy

 

 

 

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines