Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Properly shutting down your Raspberry Pi is crucial to avoid data corruption and ensure the longevity of your device. Unlike traditional computers, simply unplugging the Raspberry Pi can lead to file system corruption, which may render your SD card unusable. This article will guide you through the correct methods to shut down your Raspberry Pi safely using command-line instructions and physical buttons.
Examples:
Shutdown via Command Line: The most straightforward way to shut down your Raspberry Pi is through the command line. Open a terminal window or connect to your Raspberry Pi via SSH and use the following command:
sudo shutdown -h now
This command will halt all processes and power down the Raspberry Pi immediately.
Scheduled Shutdown: You can also schedule a shutdown for a specific time. For instance, to shut down your Raspberry Pi in 10 minutes, use:
sudo shutdown -h +10
This command schedules a shutdown 10 minutes from the current time.
Shutdown via Physical Button: If you prefer a physical method, you can set up a button to safely shut down your Raspberry Pi. Here’s how you can do it:
Software Setup:
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def shutdown(channel): os.system("sudo shutdown -h now")
GPIO.add_event_detect(3, GPIO.FALLING, callback=shutdown, bouncetime=2000)
try: while True: time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()
- Save this script as `shutdown_button.py` and run it at startup by adding it to `/etc/rc.local` before the `exit 0` line:
```bash
sudo nano /etc/rc.local
Add the following line:
python /path/to/shutdown_button.py &
By following these methods, you can ensure that your Raspberry Pi shuts down safely without risking data corruption.