HOW TO TURN OFF RASPBERRY PI PROPERLY

by BorisV2 in Circuits > Raspberry Pi

2886 Views, 8 Favorites, 0 Comments

HOW TO TURN OFF RASPBERRY PI PROPERLY

Raspberry-Pi-3-Ports-1-1833x1080.jpg

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. But what to do if in your project neither the keyboard nor the mouse or the monitor are used?

My solution is based on the use of Mini Pushbutton Power Switch with Reverse Voltage Protection board. Let's get into details.

Configure Your Raspberry Pi

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

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

shutdowndrawing.jpg

Connect Pololu board to your RPi as it is shown on the picture.

Python Script

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

****************************************************************************

How It Works

SW1 switch serves as „ON“ button. Nothing special, everything is clear :)

When you press SW2, shutdown process initializes by executing Python script.

Once the process is completed, GPIO8 goes low.

This low level on pin "ctrl" of Pololu board, turnes off the power.

That's it :)

Thanks!

Visit my Blog for more interesting projects :

https://verysecretlab09.blogspot.com/

Youtube channel:

https://www.youtube.com/channel/UCl8RTfbWUWxgglcJM...