Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to disable backlight when shutdown? #3

Open
stuartm opened this issue Jul 27, 2018 · 17 comments
Open

Is it possible to disable backlight when shutdown? #3

stuartm opened this issue Jul 27, 2018 · 17 comments
Labels
notice Important notice or information

Comments

@stuartm
Copy link

stuartm commented Jul 27, 2018

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?

@Gadgetoid
Copy link
Member

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.

@Gadgetoid
Copy link
Member

New, easier, method, add the following to /boot/config.txt:

dtoverlay=gpio-poweroff,gpiopin=19,active_low=1

@Gadgetoid Gadgetoid added the notice Important notice or information label Oct 15, 2019
@Roaders
Copy link

Roaders commented May 11, 2020

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.

@sjtoik
Copy link

sjtoik commented May 23, 2020

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.

@sjtoik
Copy link

sjtoik commented May 24, 2020

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

@sjtoik
Copy link

sjtoik commented May 24, 2020

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.

@fquirin
Copy link

fquirin commented Oct 3, 2020

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?

@Gadgetoid
Copy link
Member

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.

@fquirin
Copy link

fquirin commented Oct 5, 2020

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: [...]

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?

@Gadgetoid
Copy link
Member

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.

@Gadgetoid
Copy link
Member

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

@fquirin
Copy link

fquirin commented Oct 6, 2020

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 😅

Its working with the hyperpixel4-backlight.service described above! Thanks a lot! 🤩

@sjtoik
Copy link

sjtoik commented Jan 13, 2021

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.

@fhb
Copy link

fhb commented May 16, 2021

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

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 #131

@jeffThompson
Copy link

jeffThompson commented May 5, 2022

@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

@briwil
Copy link

briwil commented Jul 21, 2022

@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.

@coollx
Copy link

coollx commented Apr 15, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notice Important notice or information
Projects
None yet
Development

No branches or pull requests

9 participants