Sysfs GPIO

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!

Moderators: leecollings, remb0

Post Reply
Tukker
Posts: 673
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Sysfs GPIO

Post by Tukker »

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.
Bugs bug me.
Rik60
Posts: 228
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Sysfs GPIO

Post 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.
Tukker
Posts: 673
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Sysfs GPIO

Post by Tukker »

What are those high numbers like gpio524?
Bugs bug me.
Rik60
Posts: 228
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Sysfs GPIO

Post 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?
xavierm
Posts: 4
Joined: Sunday 25 January 2026 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post 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
jacquesbrunet
Posts: 5
Joined: Sunday 08 March 2026 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post by jacquesbrunet »

Hi All, same problem for me. Can't export GPIOS with regular pin numbering, but works when adding an offset of 512. Exported pins as output are visible in "Devices" with "Hardware Generic SysFS". I can create "Switches" which send commands On and Off, BUT header pins voltage never change. In the opposite way, when I toggle pins voltage from SSH terminal (which works fine) the "Switches icons" keep their status.
Raspberry3B V1.2 fresh Trixie 64b OS with Docker. Latest Domoticz version. Used to work fine with old Buster.

Any help welcome!

End part of the log
2026-03-08 21:59:55.093 Status: [web:8080] Incoming connection from: 192.168.xxx.xxx
2026-03-08 22:34:39.822 Status: [web:8080] Incoming connection from: 192.168.xxx.xxx
2026-03-08 22:34:59.055 Status: User: admin (IP: 192.168.xxx.xxx) initiated a switch command (3/Test36/Off)
2026-03-08 22:35:04.955 Status: User: admin (IP: 192.168.xxx.xxx) initiated a switch command (3/Test36/On)
Rik60
Posts: 228
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Sysfs GPIO

Post by Rik60 »

What does the file /sys/kernel/debug/gpio tells you (cat /etc/kernel/debug/gpio)?
jacquesbrunet
Posts: 5
Joined: Sunday 08 March 2026 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post by jacquesbrunet »

hello Rik60, thank you for your time.
(cat /etc/kernel/debug/gpio)? or (cat /sys/kernel/debug/gpio)? ...
it says belong to sysfs minus 512 for exported ports
gpio-512 (ID_SDA )
gpio-513 (ID_SCL )
gpio-514 (GPIO2 )
gpio-515 (GPIO3 )
gpio-516 (GPIO4 )
gpio-517 (GPIO5 )
gpio-518 (GPIO6 )
gpio-519 (GPIO7 )
gpio-520 (GPIO8 )
gpio-521 (GPIO9 )
gpio-522 (GPIO10 )
gpio-523 (GPIO11 )
gpio-524 (GPIO12 )
gpio-525 (GPIO13 )
gpio-526 (GPIO14 )
gpio-527 (GPIO15 )
gpio-528 (GPIO16 )
gpio-529 (GPIO17 |sysfs ) in lo
gpio-530 (GPIO18 )
gpio-531 (GPIO19 )
gpio-532 (GPIO20 )
gpio-533 (GPIO21 )
gpio-534 (GPIO22 )
gpio-535 (GPIO23 )
gpio-536 (GPIO24 )
gpio-537 (GPIO25 )
gpio-538 (GPIO26 |sysfs ) in lo
gpio-539 (GPIO27 )
gpio-540 (NC )

Today I started to learn libgpiod.... It is even more complicated with tons of docs to read and nothing working at the end.
jacquesbrunet
Posts: 5
Joined: Sunday 08 March 2026 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post by jacquesbrunet »

I forgot to set the ports direction, sorry for that

gpiochip0: GPIOs 512-565, parent: platform/3f200000.gpio, pinctrl-bcm2835:
gpio-512 (ID_SDA )
gpio-513 (ID_SCL )
gpio-514 (GPIO2 )
gpio-515 (GPIO3 )
gpio-516 (GPIO4 )
gpio-517 (GPIO5 )
gpio-518 (GPIO6 )
gpio-519 (GPIO7 )
gpio-520 (GPIO8 )
gpio-521 (GPIO9 )
gpio-522 (GPIO10 )
gpio-523 (GPIO11 )
gpio-524 (GPIO12 )
gpio-525 (GPIO13 )
gpio-526 (GPIO14 )
gpio-527 (GPIO15 )
gpio-528 (GPIO16 )
gpio-529 (GPIO17 |sysfs ) out lo
gpio-530 (GPIO18 )
gpio-531 (GPIO19 )
gpio-532 (GPIO20 )
gpio-533 (GPIO21 )
gpio-534 (GPIO22 )
gpio-535 (GPIO23 )
gpio-536 (GPIO24 )
gpio-537 (GPIO25 )
gpio-538 (GPIO26 |sysfs ) out lo
gpio-539 (GPIO27 )
Rik60
Posts: 228
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Sysfs GPIO

Post by Rik60 »

Ok.
A few weeks ago i started to use a plugin insteat of sysfs, now i am on libgpiod, the plugin i use, and it's working for me is:
https://github.com/Mibeus/Domoticz-GPIO-Debian-13
It can control 8 or less outputs.
jacquesbrunet
Posts: 5
Joined: Sunday 08 March 2026 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post by jacquesbrunet »

Hi,
I have couple of problems with that plugin :
1- There is no plugins subdirectory in domoticz (fresh OS 64b from Imager), so I mkdir one and follow other instructions. At the end there was no Domoticz RPI GPIO Hardware.
2- By chance, I found the plugins dir in /domoticz/config/ So I reinstalled the plugins there. I got the Domoticz RPI GPIO Hardware, WONDERFUL!!! But unfortunately no device at all were created despite the 4 relays in the gpio_config.json file. log file says :
2026-03-09 18:32:34.301 Error: MesIO: gpiod module not found! Install it with:
2026-03-09 18:32:34.301 Error: MesIO: sudo apt install python3-libgpiod
2026-03-09 18:32:34.301 Error: MesIO: or: sudo pip3 install gpiod --break-system-packages
2026-03-09 18:32:34.307 Status: MesSorties: Initialized version 2.0.1, author 'Mibeus'
2026-03-09 18:32:34.310 MesSorties: Domoticz RPI GPIO plugin starting
2026-03-09 18:32:34.311 MesSorties: Plugin path: /opt/domoticz/userdata/plugins/DomoticzRPIGPIO
2026-03-09 18:32:34.311 MesSorties: Loading configuration from: /opt/domoticz/userdata/plugins/DomoticzRPIGPIO/gpio_config.json
2026-03-09 18:32:34.311 MesSorties: Configuration loaded successfully
2026-03-09 18:32:34.313 Error: MesSorties: gpiod module not found! Install it with:
2026-03-09 18:32:34.313 Error: MesSorties: sudo apt install python3-libgpiod
2026-03-09 18:32:34.313 Error: MesSorties: or: sudo pip3 install gpiod --break-system-packages
2026-03-09 18:32:34.377 Status: PluginSystem: 2 plugins started.

However, libgpiod is well installed, I can gpioinfo, gpioset... I guess there is a path conflict !
hours and hours lost for nothing.
What to do now ? Any help welcome
jacquesbrunet
Posts: 5
Joined: Sunday 08 March 2026 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sysfs GPIO

Post by jacquesbrunet »

from the log file :
Plugin path: /opt/domoticz/userdata/plugins/DomoticzRPIGPIO
This path doesn't exist. In opt, I do have containerd and WidevineCdm directories. So I created the full path and placed gpio_config.json here. No improvment at all . I wish you a good night.
Rik60
Posts: 228
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Sysfs GPIO

Post by Rik60 »

You are on Docker. I am not. I am sorry, i can not help you with this. Hopefully someone with Docker can help you.
User avatar
TiXav
Posts: 67
Joined: Saturday 28 November 2015 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Sysfs GPIO

Post by TiXav »

Hello,
I moved to docker on November (I did not have any time to move to bookworm and reinstall everything), since I use https://github.com/flyte/mqtt-io andI run it as service to expose gpio throught MQTT and use MQTTmapper plugin to update domoticz, It's working well since november even for input (pulse of flowmeter or gate push button) and for output (heating control via "fil pilote" sorry it is french, gate control)
I hope help...
Post Reply