How to Shutdown or Reboot Raspberry Pi: Step By Step GuideJessica Ward
It’s necessary to shutdown or reboot Raspberry Pi.
Restarting Raspberry Pi can be daunting if you don’t know the correct approach to do it.
People who don’t know how to shutdown Raspberry Pi, they remove the button directly from the plug. The main problem which arises doing it is, it might affect your SD card, and chances that you might lose all your data.
Today in this guide, I will provide easy & quick steps on how to turn off Raspberry Pi.
Let’s get started.
Step 1: Download the Script
First of all, you need to download the Python script to get things rolling. Open the Raspberry Pi terminal screen and type in this command:
Download the file from the above Url and open it in your home directory. Next up, check whether the file is there?
Type the command:
ls (the L is in lowercase)
You will witness a very unusual name for your file.
Step 2: Make it a Hidden file and Change the file Name
This step is optional. If you do this, it will help you remember and manage the file properly without hassle. Also, I suggest hiding the file, so it’s not readily available in your home directory.
Enter the command:
mv yourfilename.py .off_button.py
Note: In place of “yourfilename” replace it with your actual file name.
Next step is to check if the file is hidden or not?
Enter the command: ls -al
You’ll now see a file .off_button.py
Step 3: Customise the script
In this step, you need to check which Raspberry Pi version you have. Note down the version name. Now you need to figure out which pin you need to connect the button.
For that, type in the command:
You’ll find a “Revision” tab in the bottom. Check and compare the number. Know your model and PCB revision.
You can select the GPIO pin from the Hobby Tronics web page. Once done selecting the GPIO pin, open up the .off_button.py script and start editing the file.
Type in the command:
You’ll witness a variable saying “YOUR_CHOOSEN_GPIO_NUMBER_HERE” replace it with your GPIO number.
If everything is in done correctly save and exit from the script.
CTRL+X > Y > Enter
Step 4: Screen Setup
The next thing in the process is to run the script so that it loads automatically at every bootup.
Open “rc.local” file and type in the command:
sudo nano /etc/rc.local
Navigate the file and before the last line, i.e., “exit 0” add this command
Exit the screen after saving everything.
Step 5: Add a Button
It’s one of the most important things in the guide. You can say the core to turn off Raspberry Pi.
This button will help you shutdown Raspberry Pi or restart Raspberry Pi in one click.
There is one catch to this though. You need to use the GPIO pin and connect it to the ground of Raspberry Pi.
Mind you, if you are not careful about this process, chances that you might lose your Raspberry Pi in the blink of an eye.
Before doing anything further, shutdown Raspberry Pi once or if you are using female and female wire, reboot Raspberry Pi to make sure all your scripts are working fine.
Note: The above point is crucial as it will help the Raspberry Pi resistor to start up with the python code. If the scripts are not working properly, then remember, your Pi will be damaged permanently.
To be on a safer side, use the female and female jumper wire to touch pins. It’s just a recommendation.
Step 6- Finishing the setup
Now when you connect the GPIO pin with the Raspberry Pi, you’ll immediately see a green LED light starts flashing. If this happens after a few seconds, it will flash ten times and will safely shutdown Raspberry Pi. Now you can remove the power supply.
You can see how simple it is to shutdown or reboot Raspberry Pi. It’s a piece of cake to set it up from scratch.
Let me know in the comments section was this guide on how to shutdown Raspberry Pi is useful to you or not? Also you can mention other easy and quick methods to do it, if you know any.