I am using Ruby to drive output GPIO pins using the old SYSFS pseudo-filesystem interface, and am regularly encountering intermittent Errno::EACCES: Permission denied @ rb_sysopen errors.
My user is a member of the gpio group. The pseudofiles involved are writeable by the gpio gpoup.
The following is the simplest failure I've been able to boil it down to (a pry session), using a gem called gpio_sysfs, which is an extremely simple wrapper around reads and writes to files within /sys/class/gpio/:
[18] pry(main)> p0 = GpioSysfs::Pin.new(0)
#<GpioSysfs::Pin:0x0000005574264408 @pin=0>
[19] pry(main)> p0.value = true
Errno::EACCES: Permission denied @ rb_sysopen - /sys/class/gpio/gpio0/direction
from /home/slack/.gem/ruby/3.0.3/gems/gpio_sysfs-0.1.0/lib/gpio_sysfs/pin.rb:30:in `write'
[20] pry(main)> p0.direction = "out"
"out"
[21] pry(main)> p0.value = true
true # The output switches high at this point
When p0.value=() is called, the library first writes to gpio0/direction using the same call that I have used on line [20].
Does anybody know why this call fails the first time and succeeds the second?
Hardware is a model 3B and system is a recently installed Raspberry Pi OS Bullseye (64 bit, lite install).