As you might have guessed, there is always at least one Raspberry Pi doing something at my place. Two are already in datacenters providing services. One over at edis.at in Austria and one at raspberrycolocation.com (PCextreme B.V. in the Netherlands). I did a post on that a while back: All you need to know about Raspberry Pi colocation offers.
The one at home currently has a hifiberry digi+ on its gpio and is connected to the stereo. It functions as my standalone music player. It runs musicbox ( or volumio ) which is capable of connecting to various music sources, including my spotify account. It also has to capability of being an airplay and dnla receiver, in case I want to stream audio from my pc or android devices.
As this Pi has only one purpose, it doesn’t need to be powered on when nobody is at home. Powering up via usb connection or power plug and shutting it down via ssh is a bit tedious. Additionally, the pi draws some power when shut down while still being connected to the the power supply.
This is where Pi Supply Switch comes to your rescue. It provides an easy method of switching the pi on and off via buttons. Once it is switched off, the power supply will cut the power after a short time. This will also work when powering down via ssh. The power supply is connected to the 3v of the Pi, if the Pi is shut down, the 3v are not provided any more and the circuit cuts the power to the Pi.
For the shutdown via button to work, you need to listen on the interrupt for the push of the button:
# Import the modules to send commands to the system and access GPIO pins from subprocess import call import RPi.GPIO as gpio # Define a function to keep script running def loop(): raw_input() # Define a function to run when an interrupt is called def shutdown(pin): call('halt', shell=False) gpio.setmode(gpio.BOARD) # Set pin numbering to board numbering gpio.setup(7, gpio.IN) # Set up pin 7 as an input gpio.add_event_detect(7, gpio.RISING, callback=shutdown, bouncetime=200) # Set up an interrupt to look for button presses loop() # Run the loop function to keep script running
A more in depth article, schematics and code can be found on raspberry-pi-geek.com
Now if you’re like me, you probably forget to shut down the machine when you go to bed, as it just idles away near the stereo. So add an additional line in the crontab to shut it down at night, when no other machine is on, when nobody played music in a while or the stereo is off ( your stereo has ip networking right?).
Latest posts by Nico Heid (see all)
- Raspberry Pi Supply Switch, start and shut down your Pi like your PC - August 24, 2015
- Infinite House of Pancakes – code jam 2015 - July 13, 2015
- google code jam 2014 – magic trick - April 18, 2014