Page 1 of 1

Sysfs GPIO

Posted: Wednesday 01 October 2025 0:06
by HvdW
I am transferring my setup on RPI4 from bullseye to bookworm
Use a switch to switch 2 relays on GPIO 17 an GPIO 18
This is my setup script

Code: Select all

echo 17 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
#-----------------------------------------------------------------------------
# Set direction = out
#
echo out > /sys/class/gpio/gpio17/direction
echo out > /sys/class/gpio/gpio18/direction
#-----------------------------------------------------------------------------
# Set active_low = 0 (false)
#
echo 1 > /sys/class/gpio/gpio17/active_low
echo 1 > /sys/class/gpio/gpio18/active_low
In /etc/rc.local

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo /home/pi/scripts/sysfs-init.sh
exit 0
Did this, then reboot, then added hardware Generic sysfs GPIO with option autoconfigure devices
Followed the Domoticz GPIO wiki.

Re: Sysfs GPIO

Posted: Wednesday 01 October 2025 12:17
by Rik60
I have put this at the end of the file domoticz.sh in folder etc/init.d to control 8 relays on the GPIO.

Code: Select all

#relay pos1
echo 529 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio529/active_low"
echo high > /sys/class/gpio/gpio529/direction

#relay pos2
echo 530 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio530/active_low"
echo high > /sys/class/gpio/gpio530/direction

#relay pos3
echo 539 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio539/active_low"
echo high > /sys/class/gpio/gpio539/direction

#relay pos4
echo 534 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio534/active_low"
echo high > /sys/class/gpio/gpio534/direction

#relay pos5
echo 535 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio535/active_low"
echo high > /sys/class/gpio/gpio535/direction

#relay pos6
echo 536 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio536/active_low"
echo high > /sys/class/gpio/gpio536/direction

#relay pos7
echo 537 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio537/active_low"
echo high > /sys/class/gpio/gpio537/direction

#relay pos8
echo 524 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio524/active_low"
echo high > /sys/class/gpio/gpio524/direction
I did an upgrade from Bullseye to Bookworm a few weeks ago. Using Sysfs GPIO, running on a Rpi3B+ without problems.

Re: Sysfs GPIO

Posted: Wednesday 01 October 2025 16:33
by HvdW
What are those high numbers like gpio524?

Re: Sysfs GPIO

Posted: Wednesday 01 October 2025 22:57
by Rik60
HvdW wrote: Wednesday 01 October 2025 16:33 What are those high numbers like gpio524?
I found this (thanks to waltervl):

Code: Select all


On newer RPI OS's the GPIO PIN number range has changed. So Sysfs should still work but you need different pin numbers.

See also https://github.com/domoticz/domoticz/issues/6040
I indeed had to change to GPIO pins to the high numbers when i did the upgrade from Bullseye to Bookworm
Didn't you had to change the GPIO numbers with the update?

Re: Sysfs GPIO

Posted: Sunday 25 January 2026 13:03
by xavierm
Hi,
My config : RPi5 with trixie, Domoticz 2025.2
HardWare : Generic Sysfs GPIO

No way to make it work
* Can't echo :
sudo echo "6" > /sys/class/gpio/export
echo: write error: Invalid argument
* Can't gpio
gpio export 6 out
gpio: GPIO Sysfs Interface for Userspace is deprecated (https://www.kernel.org/doc/Documentation/gpio/sysfs.txt).
Function is now useless and empty.
* Can't raspi-gpio
Doesn't exist any more
*Just can
sudo pinctrl set 6 op dl => Not seen by Domoticz

How to export gpio 6 out and seen in Domoticz ?

BR