Soft-Power-Off via push button

17 views
Skip to first unread message

Joerg Hoppe

unread,
Jul 23, 2022, 6:10:34 AMJul 23
to UniBone
Hi all,
I got a question wether its possible to shut-down the BBB safely via the push button
(in contrast to a brute "Reset" or "Power-Off)

> In the FAQ it mentions it's not been a problem just cutting power to the BBB without a
> safe shutdown. That is probably true, but would it be possible to trigger a
> safe shutdown by monitoring the pushbutton switch that's wired to an IO
> (not the RESET one) to do a safe shutdown? I don't normally have a console
> connected to the BBB so this would be a nice way to trigger it before
> turning off the power if the switch is not used for anything else.

This bash-script should help.
Its be run in background, started in .profile.

kind regards,
Joerg

#!/bin/bash
# soft-power-off.sh
# This script monitors the push button on a UniBone/QBone
# and issues a shutdown when pressed.

# 1.The pushbutton is connected to P8.12, GPIO1_12
# It can be queried via the filesystem:
# Its Linux GPIO nr is 32+12 = 44
GPIO_ROOT=/sys/class/gpio

# Setup GPIO as input
echo 44  >$GPIO_ROOT/export 2>/dev/null
echo in >$GPIO_ROOT/gpio44/direction

echo "Press UniBone/QBone push button 1-2 seconds to shutdown."

state=0
while [ $state -eq 0 ]
do
    sleep 1s
    # 1st sample
    state=`cat $GPIO_ROOT/gpio44/value`
    if [ $state -eq 1 ]
    then
        # press detected: 2nd sample
        sleep 1s
        state=`cat $GPIO_ROOT/gpio44/value`
    fi
done

# only reached when button pressed: bye!
echo "UniBone/QBone push button press detected ... shutting down!"
shutdown --poweroff --no-wall +0



Reply all
Reply to author
Forward
0 new messages