Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5273

Official Display • Reconfigure Raspberry PI 5 Power Button to Switch on and off Touch Display 2

$
0
0
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:

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
Python:

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'""")
I saw a couple of suggestions online:

Code:

sudo nano /etc/systemd/logind.conf
(But not exactly what to do with it)
And

Code:

nano ~/.config/wayfire.ini
Change

Code:

command_power = pwrkey
To

Code:

command_power = exec /home/pi/myscript.sh
(But this doesn't do work)
In my case, I changed it to:

Code:

command_power = exec /home/pi/ToggleScreen/toggle_screen.sh
And my toggle_screen.sh is:

Code:

/usr/bin/python /home/pi/ToggleScreen/toggle_screen.py
And toggel_screen.py is:

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'""")
Also, I made toggle_screen executable by running:

Code:

sudo chmod +x /home/pi/ToggleScreen/toggle_screen.sh
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.

Statistics: Posted by fosautoparts — Mon Nov 18, 2024 10:13 am



Viewing all articles
Browse latest Browse all 5273

Trending Articles