Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


power off switch / accessing GPIOs
#1
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/o...spberry-pi
and used the scrips described here: https://github.com/TonyLHansen/raspberry...ff-switch/
learned that i cannot use pin 40/gpio 21 because my hifi berry dac+ uses it: https://www.hifiberry.com/docs/hardware/...ry-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?
Reply
#2
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
cat /home/pi/shutdown-press-simple.py
cat /etc/rc.local
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
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
Reply
#4
(01-26-2022, 04:48 PM)KHB49 Wrote: did some reading on the internet and did some changes…
-> chmod
-> put the line before exit in rc.local

on startup it says no module gpiozero… when it reads rc.local

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
Reply
#5
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

GPIO Zero is installed by default in the Raspberry Pi OS desktop image, available from raspberrypi.org. To install on Raspberry Pi OS Lite or other operating systems, including for PCs using remote GPIO, see the Installing chapter.

Regards,
Kent
Reply
#6
(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.

Quoting from the GPIO Zero docs

Quote:Installation

GPIO Zero is installed by default in the Raspberry Pi OS desktop image, available from raspberrypi.org. To install on Raspberry Pi OS Lite or other operating systems, including for PCs using remote GPIO, see the Installing chapter.

Regards,
Kent

thx that´s exactly where i am at right now… unfortunately it´s not possible for me to connect the moOde box to the internet to get the package from there… additionally it requires python3 which seems not to be available aswell cause python -v gives me a lot of information about python 2.7…
Reply
#7
Python 3 is in 7.6.1

Code:
pi@rp1:~ $ /usr/bin/env python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

pi@rp1:~ $ which python3
/usr/bin/python3
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#8
(01-26-2022, 07:25 PM)Tim Curtis Wrote: Python 3 is in 7.6.1

Code:
pi@rp1:~ $ /usr/bin/env python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

pi@rp1:~ $ which python3
/usr/bin/python3

hahahaha, so i am running an ancient box here…

pi@moode:~ $ uname -a

Linux moode 4.19.49-v7+ #1233 SMP Mon Jun 10 15:55:31 BST 2019 armv7l GNU/Linu

guess i should fix that first.
Reply
#9
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 Smile 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/...ry-boards/
https://webofthings.org/wp-content/uploa...i-gpio.png
https://github.com/TonyLHansen/raspberry...ff-switch/
https://gpiozero.readthedocs.io/en/stabl...lling.html
& thanks to the moOde team / forum.
Reply


Forum Jump: