Is there a way to configure the Raspberry Pi 5 power button to do something else, like toggle the touch display on and off? I know how to toggle the display in the command line and Python:
Command line:Python:I saw a couple of suggestions online:(But not exactly what to do with it)
AndChangeTo(But this doesn't do work)
In my case, I changed it to:And my toggle_screen.sh is:And toggel_screen.py is:Also, I made toggle_screen executable by running:The toggle_screen.sh script works fine, toggling the screen on and off. Please note that if you try the above code and it doesn't work, look in the /sys/class/backlight/ folder and see if the folder has a different name - mine is 4-0045, but is 10-0045 on my Raspberry Pi 4 with original touch display.
Having had Raspberry Pis for many years (since the Raspberry Pi 1 B+ came out), I've become used to not having a power button so would like to give it a use. My RPi4 has the Pimoroni fan shim on it, which has a button and I have it configured to toggle the display on and off.
Command line:
Code:
# Turn offecho 1 | sudo tee /sys/class/backlight/4-0045/bl_power# Turn onecho 0 | sudo tee /sys/class/backlight/4-0045/bl_power
Code:
# Turn offos.system("""sudo sh -c 'echo "1" > /sys/class/backlight/4-0045/bl_power'""")# Turn onos.system("""sudo sh -c 'echo "0" > /sys/class/backlight/4-0045/bl_power'""")
Code:
sudo nano /etc/systemd/logind.conf
And
Code:
nano ~/.config/wayfire.ini
Code:
command_power = pwrkey
Code:
command_power = exec /home/pi/myscript.sh
In my case, I changed it to:
Code:
command_power = exec /home/pi/ToggleScreen/toggle_screen.sh
Code:
/usr/bin/python /home/pi/ToggleScreen/toggle_screen.py
Code:
import osdisp = os.popen("cat /sys/class/backlight/4-0045/bl_power").read().strip()if disp == "0": os.system("""sudo sh -c 'echo "1" > /sys/class/backlight/4-0045/bl_power'""")else: os.system("""sudo sh -c 'echo "0" > /sys/class/backlight/4-0045/bl_power'""")
Code:
sudo chmod +x /home/pi/ToggleScreen/toggle_screen.sh
Having had Raspberry Pis for many years (since the Raspberry Pi 1 B+ came out), I've become used to not having a power button so would like to give it a use. My RPi4 has the Pimoroni fan shim on it, which has a button and I have it configured to toggle the display on and off.
Statistics: Posted by fosautoparts — Mon Nov 18, 2024 10:13 am