2

This is driving me crazy.

I do this:

cameron@raspberrypi ~ $ gpio export 18 out

Then here's the output of sudo ls -lL /sys/class/gpio/gpio18:

-rwxrwx--- 1 root     gpio     4096 Mar  8 10:50 active_low
-rwxrwx--- 1 root     gpio     4096 Mar  8 10:52 direction
-rwxrwx--- 1 cameron  cameron  4096 Mar  8 10:50 edge
drwxrwx--- 2 root     gpio        0 Mar  8 10:50 power
drwxrwx--- 2 root     gpio        0 Mar  8 10:50 subsystem
-rwxrwx--- 1 root     gpio     4096 Mar  8 10:50 uevent
-rwxrwx--- 1 cameron  cameron  4096 Mar  8 10:50 value

So looks like I should now have access to value, great. However:

cameron@raspberrypi~ $ echo 1 > /sys/class/gpio/gpio18/value
-bash: /sys/class/gpio/gpio18/value: Permission denied

What gives? I thought this was the correct way to set up a GPIO pin for a non-root user to access it.

  • Cross-posted: unix.stackexchange.com/questions/118716/… -> Please indicate when you do this by placing a link in every question to everywhere else you have asked the question. This way people will not waste their time writing an answer in one place when you have already received one in another. Note that some places forbid cross-posting, but on Stack Exchange it is a grey area ;) – goldilocks Mar 8 '14 at 13:30
  • Works here. Despite what @goldilocks said you SHOULD NOT use sudo, as gpio sets ownership to the user that runs it. What does gpio readall show? – Milliways Mar 8 '14 at 22:24
2

The problem seemed to be that the user was not in the gpio group. This is exactly what I did:

sudo usermod -aG gpio cameron
gpio export 18 out
echo 1 > /sys/class/gpio/gpio18/value

Now everything works as expected.

  • Glad you have got it working. – Milliways Mar 9 '14 at 7:24
  • I now realise I my /usr/local/bin/gpio has suid permission. I really can't remember whether this was by default or whether I changed it. I don't actually have a gpio group. You should accept your own answer to mark as solved. – Milliways Mar 9 '14 at 7:35
0

I have not played with the GPIO pins this way but based on this article, you must first set the direction of the pin to "out". The direction node is owned by root, so:

sudo sh -c 'echo out > /sys/class/gpio/gpio18/direction'

sh -c is needed here to execute that command in a root subshell. This is because sudo echo out > direction would execute echo as root, but the redirection (> direction) would be done by your current (non-root) shell. You could also just do this su root.

After that you should, hopefully, be able to set value as cameron.

  • 1
    The gpio command sets the direction. – Cameron Ball Mar 9 '14 at 4:27
-4

use this command:-

echo 1 > /sys/class/gpio/gpio18/active_low

cat value

1

your value is changed.

  • 1
    Did you read the accepted offer? the problem was group membership. – Steve Robillard Aug 11 '15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.