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.