I’ve had a lot of issues regarding the sysfs interface recently, and unfortunately, I’ve got another unrelated one. I’m trying to integrate the sysfs gpio interface into my python3 code. This is because I find sysfs to be a more all rounded module rather than other libraries like gpiod. My code sets up the gpio pin as an output, then drives the line high which in turn causes an led to light up. Here is how I access my code:
sudo python3 ledsysfs
And here is the main code:
import os
os.system('sudo echo 581 > /sys/class/gpio/export')
os.system('sudo echo out > /sys/class/gpio/gpio581/direction')
os.system('sudo echo 1 > /sys/class/gpio/gpio581/value')
os.system('sudo echo 581 > /sys/class/gpio/unexport')
The issue with my code is that when I run it, I get an error message that occurs on line 2 and 3:
sh: 1: cannot create /sys/class/gpio/gpio581/direction: Permission denied
sh: 1: cannot create /sys/class/gpio/gpio581/value: Permission denied
I will add that when I run these commands when I'm not in the python script, but rather directly via the command line, it works just fine. Here is what I do through the command line:
sudo echo 581 > /sys/class/gpio/export
sudo echo out > /sys/class/gpio/gpio581/direction
sudo echo 1 > /sys/class/gpio/gpio581/value
sudo echo 581 > /sys/class/gpio/unexport
Do you know how I can fix this issue?