Soft-Power-Off via push button

Skip to first unread message

Joerg Hoppe

Jul 23, 2022, 6:10:34 AM7/23/22
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,

# 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

# 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."

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

# 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
0 new messages