On/Off Shim not working as expected

Hello everybody. First post here!

I need help with a Pimoroni ON/OFF shim that is not working as expected since a while.

when i opened the config file in /etc/cleanshutd.config , this was completely blank.
So, as I think that it should be, i re-wrote the following:

# Config for cleanshutd
# Commented out values will be reverted to defaults,
# and may not work on any given board.
# OnOff SHIM uses trigger 17 and poweroff 4
# Zero Lipo uses trigger 4 and poweroff off
# pHAT BEAT uses trigger 12 and powerof off
# Default values are trigger 4 and poweroff off

daemon_active=1
trigger_pin=17
led_pin=17
poweroff_pin=4
hold_time=1
shutdown_delay=0
polling_rate=1

the SHIM still doesn’t work, even though now the led is lighting when i press the on/off button. Looks like the RPi doesn’t detect the BCM17 held down.

I tried rebooting many times but no luck.

I also tried to fresh install a version of the RPi OS and run the one-line installer:
curl https://get.pimoroni.com/onoffshim | bash

but after rebooting, the /etc/cleanshutd.config file was again completely blank… therefore i wrote again the same:

# Config for cleanshutd
# Commented out values will be reverted to defaults,
# and may not work on any given board.
# OnOff SHIM uses trigger 17 and poweroff 4
# Zero Lipo uses trigger 4 and poweroff off
# pHAT BEAT uses trigger 12 and powerof off
# Default values are trigger 4 and poweroff off

daemon_active=1
trigger_pin=17
led_pin=17
poweroff_pin=4
hold_time=1
shutdown_delay=0
polling_rate=1

but the SHIM is yet not working. only the led on the board is lighting up.

Both now and before the fresh install, the file gpio-poweroff, located in /lib/systemd/system-shutdown, contains:

#! /bin/sh

# file: /lib/systemd/system-shutdown/gpio-poweroff
# $1 will be either "halt", "poweroff", "reboot" or "kexec"

poweroff_pin=""
led_pin=""
config_file=/etc/cleanshutd.conf

if [ -f "$config_file" ]; then
    /bin/echo "Reading config file $config_file"
    poweroff_pin=`grep -r '^poweroff_pin=[0-9]*$' "$config_file" | cut -f2- -d=`
    led_pin=`grep -r '^led_pin=[0-9]*$' "$config_file" | cut -f2- -d=`
fi

case "$1" in
  poweroff)
        if [ "$poweroff_pin" = "" ]; then
            /bin/echo "Skipping GPIO power-off" && exit 0
        else
            /bin/echo "Using power off pin $poweroff_pin"
        fi
        if [ ! "$led_pin" = "" ]; then
            /bin/echo "Using LED pin $led_pin"
            /bin/echo $led_pin > /sys/class/gpio/export
            /bin/echo out > /sys/class/gpio/gpio$led_pin/direction
            for iteration in 1 2 3; do
                /bin/echo 0 > /sys/class/gpio/gpio$led_pin/value
                /bin/sleep 0.2
                /bin/echo 1 > /sys/class/gpio/gpio$led_pin/value
                /bin/sleep 0.2
            done
        fi
        /bin/echo $poweroff_pin > /sys/class/gpio/export
        /bin/echo out > /sys/class/gpio/gpio$poweroff_pin/direction
        /bin/echo 0 > /sys/class/gpio/gpio$poweroff_pin/value
        /bin/sleep 0.5
        ;;
esac
:

Can you help me figure out what’s wrong?

Thanks a lot

Answering to myself but helped from the Pimoroni customer support, here i report how the issue has been mitigated:

Seems like the the board wasn’t working with the new RPiOS (bullseye).
After i fresh installed a version of the previos OS (buster),
I run the one-line installer and the cleanshutd.txt was there and the board was functioning as expected.

Still need to understand how to make it work with newer OS.

I have the same symptoms, using the latest (2024-03-15) version of Raspberry Pi OS Lite on my Zero W board.

From https://www.raspberrypi.com/documentation/computers/raspberry-pi.html, I read:

“A 40-pin GPIO header is found on all current Raspberry Pi boards, although it is unpopulated on Raspberry Pi Zero, Raspberry Pi Zero W, and Raspberry Pi Zero 2 W.”

This makes me think this SHIM cannot possibly work on my Zero W. Am I missing something here?

No, that’s just saying that if you buy a Zero(*) without a pre-soldered header on it, it won’t have a header on it into which you can plug the shim.

You can fix that by (a) buying a version with a header on it, or (b) soldering a header on yourself (which is fiddly AF and life is too short :-) )

Thanks for the explanation. Mine obviously has the header, so that’s not the problem.

The Raspberry Pi 5 has a built in On / Off button. And Pi OS Bookworm has the new code built into it to make use of it. Best guess is that is messing up the On Off Shim. One would think that if a Pi 5 wasn’t detected, the built in code would be disabled, but who knows?

I figured out the problem. In /usr/bin/cleanshutd I had to remove the “fsel=0” bit from trigger_pin_low().

There’s another issue I reported with /etc/init.d/cleanshutd. /boot/config.txt has to be replaced with /boot/firmware/config.txt

Additionally, according to the software, the red LED on the board should be controlled by the software. However, it seems to be hardwired to the pushbutton, meaning no software control.

I’ve reported all of these things, and have gotten only automatic acknowledgements of receipt.

1 Like

I’m sure somebody will get back to you once they get a chance to sit down with the same hardware to investigate.
Thanks for the detailed response though, it will help others that hit the same glitch.

@nhazadian Very sorry for the slow response - we’ve been a bit short handed over the last few days. I’ve just dropped you a reply to your support ticket.

For anyone else who comes across the thread and is trying to use On/Off SHIM with Bookworm there’s a Github issue here with some updated config settings that might help get things going: