How to turn off Raspberry Pi properly
Probably
every RPi user once wonders how to turn off Raspberry Pi?
You
can't just turn off the power. If you do so, it is very likely one
day SD card will be corrupted, and your RPi will not start up. You
must first shut down OS, and only then you can turn it off by pulling
the cord out of the socket, or if you are more advanced user, by
switch installed by yourself.
It is more or less ok, if you are using your RPi as desktop PC.
It is more or less ok, if you are using your RPi as desktop PC.
But
what to do if in your project neither the keyboard nor the mouse or
the monitor are used?
board.
Let's
get into details.
First
you need to edit config.txt file on your RPI, by adding a line:
dtoverlay=gpio-poweroff,active_low,gpiopin=14
Put
this line at the end, before
start_x=0 .
start_x=0 .
With
this line you set GPIO14 (here I'am using BCM GPIO numbering) high
at start up. When it will go low after shutdown, it will turn power
off via pin “ctrl” on Pololu board.
Connect
Pololu board to your RPi as it is shown on the picture below.
You need to add some code to your Python script, also.
**************************************************************************** gpio.setup(31, gpio.IN, pull_up_down = gpio.PUD_UP) # set GPIO 31 as input def Shutdown(channel): os.system("sudo shutdown -h now") # shuts down RPi on low GPIO31 gpio.add_event_detect(31, gpio.FALLING, callback = Shutdown, bouncetime = 2000) # waiting for GPIO low to shut down RPi
****************************************************************************
Now
how it works.
SW1
switch serves as „ON“ button. Nothing special, everything is
clear :)
When you press SW2, shutdown process initializes.
Once the process is completed, GPIO8 goes low. This low level on pin "ctrl" turnes off the power.
That's it :)
Love it! Thank you!
ReplyDelete