Pirate Audio Headphone Amp - why does the backlight stay on when the Raspberry Pi is powered down?

I have a Pirate Audio Headphone Amp. When the Raspberry Pi Zero is on, you can turn the backlight off (pirate-audio/README.md at master · bjohas/pirate-audio · GitHub).

However, when the Pi is powered down, the backlight comes back on. Is there any way of avoiding that? (Other than unplugging the Raspberry Pi.)

The backlight is turned off by a low signal on the backlight pin. When the Pi shuts down that pin is likely going to a floating state (not a low), thus the backlight goes back on.

Thank you. That is to say that there isn’t really a solution for this… unless one constructed a ‘standby saver’ unit, that cuts power completely if the draw is very small.

There is no easy solution. I have a switch wired up on a couple of my builds that have proto boards in the mix. In my case those Pi’s run 24/7 but I sometimes like to turn the displays off.
There is also a dtoverlay that can set a pin low on shutdown, and keep it low. I tinkered with it in the past but it had other side effects that I didn’t like. The main one being the Pi would no longer boot up when GPIO 3 was grounded. I had to unplug the power supply, and plug it back in to get that Pi to boot up.

This is really helpful @alphanumeric, thank you so much.

While the Pi is on (with this particular display), turning the display off while the Pi is on is not a problem:, as noted above - dimming is harder though.

When you say ‘no longer boot’, what do you mean? No longer boot by pulling up a pin? I will only have the Pi on for part of the day, and am thinking of having one of those micro-usb cables with a switch. So fully disconnecting power / reconnecting power would not be an issue for me.

Were there other unintended side effects?

Also, do you have the code for this? I had a quick look, but I couldn’t see any standard overlays that would pull a gpio low or high. Any hints greatly appreciated!

I have some headless setups that I shut down with a button press.
I use the following with my Fan Shim for example.
dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up
If you shutdown and leave the power on, grounding GPIO 3 will boot the Pi back up.
On a stock fan shim the fan will just keep running on shutdown until you remove power. The fan control pin needs to be grounded. Thats where I had tried the overlay to keep the pin low on shutdown. It worked, the fan shut off, but I couldn’t boot back up with a button press. I had to unplug the power supply and plug it back in to get the Pi to boot up again.

Name:   gpio-poweroff
Info:   Drives a GPIO high or low on poweroff (including halt). Enabling this
        overlay will prevent the ability to boot by driving GPIO3 low.
Load:   dtoverlay=gpio-poweroff,<param>=<val>
Params: gpiopin                 GPIO for signalling (default 26)

        active_low              Set if the power control device requires a
                                high->low transition to trigger a power-down.
                                Note that this will require the support of a
                                custom dt-blob.bin to prevent a power-down
                                during the boot process, and that a reboot
                                will also cause the pin to go low.
        input                   Set if the gpio pin should be configured as
                                an input.
        export                  Set to export the configured pin to sysfs

That’s amazing, thank you! (I’ll try this and will post back.)

Hi @alphanumeric - thank you again. All works! Written up here pirate-audio/README.md at master · bjohas/pirate-audio · GitHub.

1 Like

I solved it with inspiration above as follows:

 cat displayoff.py 
from st7789 import ST7789

# Set your parameters
rotation = 0  # Change as needed
spi_port = 0
spi_chip_select_pin = 0
spi_data_command_pin = 23
backlight_pin = 13
spi_speed_mhz = 80  # Example speed, adjust as necessary

# Initialize the display
disp = ST7789(
    rotation=rotation,
    port=spi_port,
    cs=spi_chip_select_pin,
    dc=spi_data_command_pin,
    backlight=backlight_pin,
    spi_speed_hz=spi_speed_mhz * 1000000  # Convert MHz to Hz
)

# Begin communication with the display
disp.begin()


# Turn off the backlight
disp.set_backlight(0)
print("Backlight turned off.")