Is it possible to disable backlight when shutdown?
When the Raspberry Pi is shutdown, but still connected to power, the backlight remains on. Is this behaviour configurable? Or should it be possible to toggle the backlight off by pulling the backlight GPIO high/low during the shutdown process?
Any documentation that we can refer to?
It's possible you could pull this pin using a technique similar to the one here: https://github.com/pimoroni/clean-shutdown/blob/master/daemon/lib/systemd/system-shutdown/gpio-poweroff
This drops a script into systemd that runs upon shutdown and asserts a GPIO pin.
New, easier, method, add the following to /boot/config.txt:
dtoverlay=gpio-poweroff,gpiopin=19,active_low=1
Can I turn the screen off using software when the pi is still turned on? i.e. on timeout turn the screen off then turn it back on when someone walks in front of the screen? I want my pi to be a control panel on the wall but not lit up all the time.
I have similar project going on. I have the touch version, and would like tap the screen to wake it up and turn of with a timer.
It seems that there is a supporting device tree function built in in the pi4 branch, but the overlay is not loaded.
Running sudo dtoverlay hyperpixel4 drops error messages to dmesg as follows
OF: overlay: find target, node: /fragment@4, phandle 0xcd not found
OF: overlay: init_overlay_changeset() failed, ret = -22
I stand corrected, the above error happens possibly, because loading of overlays is a new thing. The debug log sudo vcdbg log msg shows no errors. The .dts indicates compatibility with gpio-backlight overlay. It also has references of gpio pin 19 being the control for this feature.
After installing the python module for the official 7" display, I quickly verified that the control works:
>>> from rpi_backlight import Backlight
>>> backlight = Backlight()
>>> backlight.power = False
>>> backlight.power = True
I don't know why this device is not responding to xset dkms commands, and what should be done to make it work, but this resolves to control issue for now. Next step is to hook it up to the screensaver functionality.
This was working for a long time:
dtoverlay=gpio-poweroff,gpiopin=19,active_low=1
But now I've installed the newest Raspbian Lite (aka Raspberry Pi OS, August 2020) on the same RPi4 and the screen will stay black on boot :-(. When I remove the line it will start as usual but the backlight won't turn off at shutdown (obviously).
I've tried to put different things in a shutdown script located at /etc/rc0.d but the screen won't stay off. Following commands are working as long as the system is active:
-
raspi-gpio set 19 op dl -
DISPLAY=:0.0 xset dpms force off -
echo '1' > /sys/class/backlight/rpi_backlight/bl_power
But at the very last stage the backlight turns on again.
Any known issues with the latest RPi OS? Any solutions?
The latest RPi OS - or rather the latest Linux kernel - seems rather more forceful about pins being mutually exclusive so I'm not surprised it's hit the backlight too.
The previous and rather contrived method of using a script in /lib/systemd/system-shutdown/gpio-poweroff should still work but it's far from optimal.
Hacking on the script I linked above, something like this will work:
#! /bin/sh
# file: /lib/systemd/system-shutdown/gpio-poweroff
# $1 will be either "halt", "poweroff", "reboot" or "kexec"
poweroff_pin="19"
case "$1" in
poweroff)
/bin/echo "Using power off pin $poweroff_pin"
/bin/echo $poweroff_pin > /sys/class/gpio/export
/bin/echo out > /sys/class/gpio/gpio$poweroff_pin/direction
/bin/echo 0 > /sys/class/gpio/gpio$poweroff_pin/value
/bin/sleep 0.5
;;
esac
:
In the meantime I'll see if there's a way to get the dtoverlays playing nice together.
The latest RPi OS - or rather the latest Linux kernel - seems rather more forceful about pins being mutually exclusive so I'm not surprised it's hit the backlight too.
The previous and rather contrived method of using a script in
/lib/systemd/system-shutdown/gpio-poweroffshould still work but it's far from optimal.Hacking on the script I linked above, something like this will work: [...]
Thanks for the info.
I've created the script and put it into /lib/systemd/system-shutdown/gpio-poweroff (and made it executable if that's relevant), but ultimately the screen stays on. The usual behavior is:
sudo shutdown -h now -> screen turns black for ~3s -> screen turns back on and you see a bit of RPi console log -> RPi turns off and backlight stays on
Did I miss something? Do I have to install anything to make this script work?
Okay upon further investigation the backlight should be turning off with no additional changes since there's a service in /etc/systemd/system/poweroff.target.wants/rpi-display-backlight.service that effectively runs echo 1 | sudo tee -a /sys/class/backlight/rpi_backlight/bl_power on shutdown.
It appears to shut down the backlight... but then it comes right back on again at the last stage. I'm guessing this is the point at which the gpio-backlight module is unloaded, releasing the GPIO back to its original state- which would be a high impedance input- and letting the pull-up on the Hyperpixel do its work so the backlight returns to "on." This would explain the weird backlight turning off and then on again on shutdown.
The only solution I can find is to hot-swap the module that owns the GPIO pin-
sudo rmmod gpio-backlight
sudo dtoverlay /boot/overlays/gpio-poweroff.dtbo gpiopin=19 active_low=1
This seems to allow the backlight to turn off and stay off. I'll try and throw together a systemd unit for this.
This is pretty clunky, but create the following as /etc/systemd/system/hyperpixel4-backlight.service:
[Unit]
Description=Sets up gpio-poweroff to handle Hyperpixel backlight upon shutdown/reboot
ConditionPathExists=/usr/bin/hyperpixel4-init
ConditionPathExists=/boot/overlays/gpio-poweroff.dtbo
ConditionPathExists=/usr/bin/dtoverlay
DefaultDependencies=no
Before=umount.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c '/sbin/rmmod gpio-backlight;/usr/bin/dtoverlay /boot/overlays/gpio-poweroff.dtbo gpiopin=19 active_low=1'
[Install]
WantedBy=reboot.target halt.target poweroff.target
And then run sudo systemctl enable hyperpixel4-backlight.service
It appears to shut down the backlight... but then it comes right back on again at the last stage. I'm guessing this is the point at which the gpio-backlight module is unloaded, releasing the GPIO back to its original state- which would be a high impedance input- and letting the pull-up on the Hyperpixel do its work so the backlight returns to "on." This would explain the weird backlight turning off and then on again on shutdown.
This pretty much sums what I had puzzled together I guess in a technically more precise way :sweat_smile:
Its working with the hyperpixel4-backlight.service described above! Thanks a lot! :star_struck:
I wrote a holiday project hyperpixel4-blu and embedded @Gadgetoid 's systemd service to be part of if. The package monitors XScreenSaver events and toggles the backlight on and off accordingly. You can find the .deb from the releases.
This is pretty clunky, but create the following as
/etc/systemd/system/hyperpixel4-backlight.service:[Unit] Description=Sets up gpio-poweroff to handle Hyperpixel backlight upon shutdown/reboot ConditionPathExists=/usr/bin/hyperpixel4-init ConditionPathExists=/boot/overlays/gpio-poweroff.dtbo ConditionPathExists=/usr/bin/dtoverlay DefaultDependencies=no Before=umount.target [Service] Type=oneshot ExecStart=/bin/sh -c '/sbin/rmmod gpio-backlight;/usr/bin/dtoverlay /boot/overlays/gpio-poweroff.dtbo gpiopin=19 active_low=1' [Install] WantedBy=reboot.target halt.target poweroff.targetAnd then run
sudo systemctl enable hyperpixel4-backlight.service
This disables my backlight control in /etc/rc.local: /usr/bin/gpio -g mode 19 pwm /usr/bin/gpio -g pwm 19 40
Any way to dim the light with this service? Edit: Might also just be this issue https://github.com/pimoroni/hyperpixel4/issues/131
@fhb – using those commands worked great for me as part of a bash script too, thanks so much!
Edit: nope, both the service and the gpio commands still have the screen coming back on about three seconds after shutdown
@fhb – using those commands worked great for me as part of a bash script too, thanks so much!
Edit: nope, both the service and the gpio commands still have the screen coming back on about three seconds after shutdown
Same here, still comes back on after 3 seconds.
@fhb – using those commands worked great for me as part of a bash script too, thanks so much! Edit: nope, both the service and the gpio commands still have the screen coming back on about three seconds after shutdown
Same here, still comes back on after 3 seconds.
Same here. I encountered this issue today. Have you been able to solve it?