Unable to write to a GPIO pin despite file permissions on /sys/class/gpio/gpio18/value
I solved the problem by adding cameron to the gpio group:
sudo usermod -aG gpio cameron
gpio export 18 out
echo 1 > /sys/class/gpio/gpio18/value
Now everything works.
I have not played with the GPIO pins this way but based on lgeorgets second comment and 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
.