To keep prices down, the Raspberry Pi is missing something that most electronic devices come with: a switch to turn it on and off. That’s OK, you say, we’ll just pull the plug to turn it off. Unfortunately, this can lead to corruption problems with the SD card. All the instructions say you should run the shutdown command before pulling the plug, but this is not always possible, particularly when your Raspberry Pi is running headless without a connected keyboard and monitor, and possibly even without a network connection. So, what can a self-respecting DIYer do? The answer, of course, is ‘add your own switch’!To switch off the Raspberry Pi from the console:
pi@cosmac:~ $ sudo poweroffI would like to use only one button for turn off and on again the Raspi as described in How to add a power button to your Raspberry Pi but for this we need the GPIO3 and this pin is already used by the I2C communication. I instead chose GPIO21 (pin 40) for shutdown, this can be configured with overlays Add following line to the file
/boot/config.txt
dtoverlay=gpio-shutdown,gpio_pin=21If the Raspberry Pi is in HALT mode then you can start it again with switch off (pull the plug) and switch on again or hit the RUN button.
Pin Number | Pin Name Rev2 | Hardware Notes |
---|---|---|
P6-01 | RUN | Short to ground to reset the BCM2835 |
P6-02 | GND |
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
jpg | box-psu.jpg | r1 | manage | 3534.0 K | 2018-06-24 - 14:36 | PeterSchmid | |
jpg | box-running.jpg | r1 | manage | 3432.0 K | 2018-06-24 - 14:36 | PeterSchmid | |
jpg | box-small.jpg | r1 | manage | 56.3 K | 2018-06-24 - 14:44 | PeterSchmid | |
jpg | box-tft.jpg | r1 | manage | 311.7 K | 2018-08-26 - 21:33 | PeterSchmid | |
png | cosmicos.png | r3 r2 r1 | manage | 39.2 K | 2018-09-26 - 20:45 | PeterSchmid | |
svg | cosmicos.svg | r1 | manage | 16.0 K | 2018-09-26 - 20:02 | PeterSchmid | |
jpg | run-shutdown-bottom.jpg | r1 | manage | 225.7 K | 2018-08-26 - 15:35 | PeterSchmid | |
jpg | run-shutdown-switches.jpg | r1 | manage | 121.6 K | 2018-08-26 - 15:35 | PeterSchmid | |
jpg | schmuckkaestli-open.jpg | r1 | manage | 210.9 K | 2018-12-16 - 16:28 | PeterSchmid | |
jpg | schmuckkaestli.jpg | r1 | manage | 139.3 K | 2018-12-16 - 16:28 | PeterSchmid | |
jpg | wooden-box.jpg | r1 | manage | 462.1 K | 2018-06-24 - 14:36 | PeterSchmid |