power off switch / accessing GPIOs - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7) +--- Thread: power off switch / accessing GPIOs (/showthread.php?tid=4692) |
power off switch / accessing GPIOs - KHB49 - 01-26-2022 i am busy boxing the unit and running into issues while trying to add a power off switch due to the fact that my touchscreen seems to be weak in that particular upper right corner where the pulldown is, did turn 180degrees that helps but still want to have that switch. followed the instructions here https://magpi.raspberrypi.com/articles/off-switch-raspberry-pi and used the scrips described here: https://github.com/TonyLHansen/raspberry-pi-safe-off-switch/ learned that i cannot use pin 40/gpio 21 because my hifi berry dac+ uses it: https://www.hifiberry.com/docs/hardware/gpio-usage-of-hifiberry-boards/ adapted the scripts to gpio26 / pin 37 logged in via ssh created the script in pi/shutdown-press-simple.py added the script to /etc/rc.local turned on gpio button handler in moOde still does not work… any suggestions? RE: power off switch / accessing GPIOs - Tim Curtis - 01-26-2022 I don't think you need the GPIO Button handler because the script is launched at startup from rc.local and it does its own monitoring of the specific GPIO pins. Post some info Code: ls -l /home/pi RE: power off switch / accessing GPIOs - KHB49 - 01-26-2022 did some reading on the internet and did some changes… -> chmod -> put the line before exit in rc.local still not working pi@moode:~ $ ls -l /home/pi total 12 drwx------ 2 pi pi 4096 Dec 29 18:57 Downloads -rwxr-xr-x 1 root root 1546 Jun 12 2019 piano.sh -rwxr-xr-x 1 root root 117 Dec 29 19:24 shutdown-press-simple.py pi@moode:~ $ cat /home/pi/shutdown-press-simple.py #!/usr/bin/env python3 from gpiozero import Button import os Button(26).wait_for_press() os.system("sudo poweroff") pi@moode:~ $ cat /etc/rc.local #!/bin/sh -e SQLDB=/var/local/www/db/moode-sqlite3.db # set cpu govenor RESULT=$(sqlite3 $SQLDB "select value from cfg_system where param='cpugov'") echo "$RESULT" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor /usr/bin/udisks-glue > /dev/null 2>&1 /var/www/command/worker.php > /dev/null 2>&1 /home/pi/shutdown-press-simple.py & exit 0 RE: power off switch / accessing GPIOs - KHB49 - 01-26-2022 (01-26-2022, 04:48 PM)KHB49 Wrote: did some reading on the internet and did some changes… RE: power off switch / accessing GPIOs - TheOldPresbyope - 01-26-2022 It looks like the GPIO Zero library isn't there since moOde is built on RaspiOS Lite. Quoting from the GPIO Zero docs Quote:Installation Regards, Kent RE: power off switch / accessing GPIOs - KHB49 - 01-26-2022 (01-26-2022, 06:50 PM)TheOldPresbyope Wrote: It looks like the GPIO Zero library isn't there since moOde is built on RaspiOS Lite. RE: power off switch / accessing GPIOs - Tim Curtis - 01-26-2022 Python 3 is in 7.6.1 Code: pi@rp1:~ $ /usr/bin/env python3 RE: power off switch / accessing GPIOs - KHB49 - 01-26-2022 (01-26-2022, 07:25 PM)Tim Curtis Wrote: Python 3 is in 7.6.1 RE: power off switch / accessing GPIOs - KHB49 - 01-27-2022 did it! new install of moOde sudo apt-get update sudo apt upgrade sudo apt autoremove sudo apt install python3-gpiozero sudo nano shutdown-press-simple.py sudo chmod a+x shutdown-press-simple.py sudo echo '~pi/shutdown-press-simple.py &' sudo nano /etc/rc.local -> control the entry is before exit 0 done did use the shutdown&hold script but did not change the name. pi@moode:~ $ ls -l /home/pi total 8 -rwxr-xr-x 1 root root 1516 Dec 17 10:47 piano.sh -rwxr-xr-x 1 root root 117 Jan 27 08:59 shutdown-press-simple.py pi@moode:~ $ cat /home/pi/shutdown-press-simple.py #!/usr/bin/env python3 from gpiozero import Button from signal import pause import os, sys offGPIO = int(sys.argv[1]) if len(sys.argv) >= 2 else 26 holdTime = int(sys.argv[2]) if len(sys.argv) >= 3 else 6 # the function called to shut down the RPI def shutdown(): os.system("sudo poweroff") btn = Button(offGPIO, hold_time=holdTime) btn.when_held = shutdown pause() # handle the button presses in the background pi@moode:~ $ cat /etc/rc.local #!/bin/sh -e SQLDB=/var/local/www/db/moode-sqlite3.db # Unblock WiFi /usr/sbin/rfkill unblock wifi > /dev/null 2>&1 # Set cpu govenor CPU_GOV=$(sqlite3 $SQLDB "select value from cfg_system where param='cpugov'") echo "$CPU_GOV" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor # USB storage auto-mounter /usr/bin/udisks-glue --config=/etc/udisks-glue.conf > /dev/null 2>&1 #/usr/bin/devmon --exec-on-drive "/var/www/command/util.sh smb_add %d %f" --exec-on-remove "/var/www/command/util.sh smb_remove %f" --always-exec --no-gui > /dev/null 2>&1 & # Work around for Katana driver load failure on Pi-4B AUDIO_DEVICE=$(sqlite3 $SQLDB "select value from cfg_system where param='i2sdevice'") PI_REVNUM_SEGMENT=$(awk '{if ($1=="Revision") print substr($3,3,3)}' /proc/cpuinfo) if [ "$AUDIO_DEVICE" = "Allo Katana DAC" ] && [ $PI_REVNUM_SEGMENT = "311" ]; then rmmod snd_soc_allo_katana_codec rmmod snd_soc_audio_graph_card modprobe snd_soc_audio_graph_card modprobe snd_soc_allo_katana_codec echo `date +'%Y%m%d %H%M%S'` "rc.local ran Katana|Pi-4B driver reload" > /home/pi/katana.log fi # moOde startup and job processor daemon /var/www/command/worker.php > /dev/null 2>&1 /home/pi/shutdown-press-simple.py & exit 0 pi@moode:~ $ /usr/bin/env python3 Python 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> pi@moode:~ $ which python3 /usr/bin/python3 pi@moode:~ $ uname -a Linux moode 5.10.63-v7+ #1496 SMP Wed Dec 1 15:58:11 GMT 2021 armv7l GNU/Linux resources: https://www.hifiberry.com/docs/hardware/gpio-usage-of-hifiberry-boards/ https://webofthings.org/wp-content/uploads/2016/10/pi-gpio.png https://github.com/TonyLHansen/raspberry-pi-safe-off-switch/ https://gpiozero.readthedocs.io/en/stable/installing.html & thanks to the moOde team / forum. |