May be not the right place, but ran again that on the RPi platform.
I want to have - say - an output on the RPi. I'm user pi. I'm in gpio group. I say 'echo 26> /sys/class/gpio/export'. Works. I then say 'echo out> /sys/class/gpio/gpio26/direction'. Works, too. I can now set or clear that pin from bash. Okay.
I do 'echo 26> /sys/class/gpio/unexport', then.
Now, I launch that script:
#!/bin/bash
echo 26 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio26/direction
This throws permission denied in line 3, accessing the direction file.
After unexporting the GPIO 26, I patch my script. It now looks like
#!/bin/bash
echo 26 > /sys/class/gpio/export
sleep 1
echo out > /sys/class/gpio/gpio26/direction
That works.
Any known reason?
1 Answer 1
It takes a fraction of a second for the kernel to export the GPIO. Adding a short delay lets the action complete before the next command is run.