4

I'm developing a project where I have a button connected to the Raspberry Pi GPIO where it sends shutdown command when pressed for 3 seconds. I also have a 16x2 LCD that outputs status messages. When I press the button the Raspberry shutsdown, but the LCD is still on because the 5V GPIO is on while the power supply is connected.

How can I switch off the 5V pin? Is there a way?

Thanks in advance!

3
  • Yes - turn the power supply off. The Pi 5V is connected to the input 5V by a diode and fuse, so it does whatever the power supply does. PS why do you want to turn the power off, the Pi uses less than most appliances on standby?
    – Milliways
    Commented Jan 10, 2017 at 11:43
  • The LCD screen back light may be on and can be quite annoying at night when its just a black, illuminated LCD screen :D - You would have to create some kind of switch (maybe using a transistor) to turn of the 5V to the LCD after you triggered a shutdown by using the button. Or a relay.. when the Pi shuts down the pins go LOW and the relay turns off.
    – Piotr Kula
    Commented Jan 10, 2017 at 13:47
  • embeddedpi.com/documentation/gpio/… This gives a bit more info shame you can not toggle it the other way Commented Jan 26, 2020 at 15:04

1 Answer 1

1

How can i switch off the 5V pin? Is there a way?

As Milliways implies, a switch. However, if it's not being used to actually kill the power to the Pi but just the LCD, then you could use the same switch to trigger shutdown (for which you'll need more than just the 5V line connected, which is a bit of a complication, because you can't wire that and a GPIO together on a switch, although a simple voltage divider with two resistors would solve that problem).

Alternately, the "switch" could be an NPN transistor used to control the 5V power to the LCD -- or more precisely, the return to ground (because of the relationship between the collector, emitter, and base voltages).

If you use a GPIO that is by default pulled low, I'm pretty sure (but not 100% positive) that very late in the shutdown process it will go back to that default state, and thereby turn off the power to the LCD.

If not, it is just a matter of setting the GPIO programmatically at shutdown. There's no equivalent of /etc/rc.local for this although I believe cron has a feature that could be used, or you could write a systemd service file with an ExecStart and ExecStop. The former is it seems necessary to the latter, you can't have something stopped that isn't "started successfully" (man systemd.service), but there's probably some way to have something that just runs during shutdown if you dig around. Of course, since you do presumably want to turn the power on at some point, you could use the service for that -- and note "started successfully" could mean at any point, it doesn't have to be at boot.

Anyway, first you need an NPN transistor. These are super cheap (as in pennies) and super easy to use. Unfortunately, you cannot buy just one and they likely don't have any at the nearest grocery store, but what you are looking for is a bag of something like the very commonplace 2N2222.

4
  • 2
    There is a gpio-poweroff which drives a GPIO high or low on poweroff (including halt). dtoverlay=gpio-poweroff,<param>=<val>. I have found it difficult to use, maybe a latch is required.
    – Milliways
    Commented Jan 10, 2017 at 23:34
  • I just tested dtoverlay=gpio-poweroff. This goes GPIO26 to go low on boot, high after poweroff.
    – Milliways
    Commented Jan 11, 2017 at 5:54
  • @Milliways I'm not too sure the device_tree stuff can affect the state of things after the kernel halts; it could be to do that you have to carve stuff into firmware (or maybe you can't at all, i.e., you have to use an external circuit). That the README says using dtoverlay=gpio-poweroff "will ... cause the pin to go low" during a reboot doesn't mean it will stay there post shutdown. But you should be able to find a pin that defaults to either pulled-down or floating (and in the latter case use an external pull down).
    – goldilocks
    Commented Jan 11, 2017 at 14:51
  • 1
    Who knows, given the lack of documentation from Broadcom. AFAIK CPU GPU GPIO are independent subsystems, and it is not unreasonable to expect GPIO to retain state; indeed setting a pin to output then poweroff seems to retain the value, so it is to be expected that the gpio-poweroff would set the GPIO and work similarly, and my testing seems to confirm this. Previously I was trying to use the active_low, which, as far as I remember, did cause some problem, but this may be the circuitry I had connected.
    – Milliways
    Commented Jan 12, 2017 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.