Power Switch Part 3
Pi Bits > Power Switch
The Software
As is stated on the github page: Remember to install the code before connecting the switch to the Raspberry Pi.
I'm just going to reiterate the GPIO pins used in the Volumio Player build (as much for my own memory as anything else).
Use | GPIO | Physical Pin | Comment |
NanoSound | GPIO02 | 03 | OLED Display D1 |
NanoSound | GPIO03 | 05 | OLED Display D0 |
NanoSound | GPIO04 | 07 | NanoSound Power Switch Off Trigger - Not Used |
NanoSound | GPIO09 | 21 | NanoSound Input Button 4 - VOL - |
NanoSound | GPIO10 | 19 | NanoSound Input Button 1 - VOL + |
NanoSound | GPIO11 | 23 | NanoSound Input Button 5 - SKIP - |
NanoSound | GPIO12 | 32 | NanoSound Input Button 2 - SKIP + |
NanoSound | GPIO13 | 33 | NanoSound Input Button 6 - Play / Pause |
NanoSound | GPIO14 | 08 | NanoSound Power Switch Detection of power - Not Used |
NanoSound | GPIO16 | 36 | NanoSound Input Button 3 - Not Used |
Speaker Bonnet | GPIO18 | 12 | DAC BCLK |
Speaker Bonnet | GPIO19 | 35 | DAC LRCLK |
Speaker Bonnet | GPIO21 | 40 | DAC DIN |
Power Board | GPIO23 | 16 | Soft Off switch Input to Power Board J4 |
Power Board | GPIO24 | 18 | 3.3V Power out to Power Board J3 |
Go to the following link https://github.com/PiSupply/Pi-Supply-Switch and follow the installation instructions.
Once installed the RasPi will shutdown. Remove power and jumper pin 7 to pin 9, this will trick the script into behaving as though the Power Switch is connected, then power back up.
I then edited the file /opt/piswitch/softshut.py ( sudo nano /opt/piswitch/softshut.py ) and changed the pins from
PinSeven = 7PinEight = 11
to
PinSeven = 16PinEight = 18
GPIO.setup(PinSeven, GPIO.IN) # Set up PinSeven as an input
GPIO.setup(PinEight, GPIO.OUT, initial=1) # Set up PinEight as an output
This means that pin J3 from the Pi Switch goes to pin 18 (GPIO23) on the RasPi and that pin J4 from the Pi Switch goes to pin 16 (GPIO24) on the RasPi.
You can then shutdown the RasPi and connect up the power switch.
Using the switch
- Press the On button to power on the Raspberry Pi.
- Press the Off button to remove power to the Raspberry Pi. This is not a graceful shutdown!
- Press briefly the Soft button to gracefully shutdown the operating system. After 2 minutes the power is also cut off.
- Press the Soft button and keep pressed for a reboot.
- Also selecting shutdown from the desktop or doing a shutdown from a terminal session will act in the same way as the Soft off button and remove power after 2 minutes.
Obviously the same trick of jumpering pin 16 to GND will work if you need to run without the switch and don't want to uninstall the software.