In the meanwhile I have played a little bit with pinctrl. But it's now your part to test if it works.
#!/bin/bash
# Created on: 2024-04-15 20:00
# Changed on: 2024-04-17 13:30
# Version: 1.2.0
#
# Changelog:
# 1.2.0 2024-04-17
# - version information added
# - migrated from deprecated usleep to sleep command
# 1.1.0 2024-04-16
# - restricted the pinctrl usage to the 40-pin header
# - use a more specific pin naming to prevent usage of the wrong pin
# 1.0.1 2024-04-15
# - pull-up/down setting added
# 1.0.0 2024-04-15
# - migrated to pinctrl
# - code comments added
PINCTRL_BIN="/usr/bin/pinctrl -p"
# this is the GPIO pin receiving the shut-down signal
GPIOpin1=GPIO14
# set GPIO14 to input
$PINCTRL_BIN set $GPIOpin1 ip pd
while true; do
sleep 1
# check if GPIO14 is going to high
power=$($PINCTRL_BIN get $GPIOpin1 | awk '{ print $5 }')
if [ "$power" = "hi" ]; then
# change GPIO14 to output and set it to high level
$PINCTRL_BIN set $GPIOpin1 op dh pn
sleep 3
poweroff
fi
done
Display More
#!/bin/bash
# Created on: 2024-04-15 20:00
# Changed on: 2024-04-17 13:30
# Version: 1.2.0
#
# Changelog:
# 1.2.0 2024-04-17
# - version information added
# - migrated from deprecated usleep to sleep command
# 1.1.0 2024-04-16
# - restricted the pinctrl usage to the 40-pin header
# - use a more specific pin naming to prevent usage of the wrong pin
# 1.0.1 2024-04-15
# - pull-up/down setting added
# 1.0.0 2024-04-15
# - migrated to pinctrl
# - code comments added
PINCTRL_BIN="/usr/bin/pinctrl -p"
if [ "$1" != "reboot" ]; then
GPIOpin=GPIO15
GPIOpin1=GPIO14
# execute shutdown sequence on pin
# set GPIO15 to output and high level for 125ms
$PINCTRL_BIN set $GPIOpin op dh pn
sleep 0.125
# change the output to low level for 200ms
$PINCTRL_BIN set $GPIOpin dl
sleep 0.2
# change the output to high level for 400ms
$PINCTRL_BIN set $GPIOpin dh
sleep 0.4
# change the output to low level
$PINCTRL_BIN set $GPIOpin dl
# set GPIO 14 high to feedback shutdown to RemotePi Board
# because the irswitch.sh has already been terminated
$PINCTRL_BIN set $GPIOpin1 op dh pn
sleep 4
fi
Display More
I think it's the same as Rpi4 on libreelec 12 but it doesn't work if i use GPIOpin=527 and GPIOpin1=526
LibreELEC:~ # ls -la /sys/class/gpio/
total 0
drwxr-xr-x 2 root root 0 Feb 27 18:26 .
drwxr-xr-x 58 root root 0 Jan 1 1970 ..
--w------- 1 root root 16384 Apr 15 20:42 export
lrwxrwxrwx 1 root root 0 Feb 27 18:26 gpiochip512 -> ../../devices/platform/soc/107d508500.gpio/gpio/gpiochip512
lrwxrwxrwx 1 root root 0 Feb 27 18:26 gpiochip544 -> ../../devices/platform/soc/107d508500.gpio/gpio/gpiochip544
lrwxrwxrwx 1 root root 0 Feb 27 18:26 gpiochip548 -> ../../devices/platform/soc/107d517c00.gpio/gpio/gpiochip548
lrwxrwxrwx 1 root root 0 Feb 27 18:26 gpiochip565 -> ../../devices/platform/soc/107d517c00.gpio/gpio/gpiochip565
lrwxrwxrwx 1 root root 0 Feb 27 18:26 gpiochip571 -> ../../devices/platform/axi/1000120000.pcie/1f000d0000.gpio/gpio/gpiochip571
--w------- 1 root root 16384 Apr 15 20:42 unexport
Display More
To make it complete, please check every listed chip:
cat /sys/class/gpio/gpiochip512/ngpio
cat /sys/class/gpio/gpiochip512/label
The correct one has 58 on the RPi4 (but the pin count could be split/vary on RPi5) as the return value for ngpio and I'm assuming the label is "pinctrl-bcm2712" or something similar.
EDIT:
Benoitone I have added pull-down for the input pin, to be ensure the pin isn't floating.