Challenge: The Raspberry Pi always remains powered-on as long as there is power coming in on the micro-USB power line. A shutdown/halt/poweroff command will shutdown the OS and leave the system in a powered on but idle state. The power consumption would be unchanged between idle and active on the Raspberry Pi. Further, to turn the system back on, the USB cable needs to be unplugged or the power supply needs to be unplugged (reset).
Ideally we need....
- something that powers the raspberry pi off when it is shutdown (power consumption becomes negligible / < 0.5 W) [POWER OFF]
- something that can trigger a clean software shutdown [CLEAN SHUTDOWN]
Mediation: All my TVs supply a "service" USB port, and when tested, the port was supplying enough power to power either a model B (3.5 W) or model A (1.5 W). Therefore, I've been plugging in the raspberry pi directly into the TV for the power source. I just remember that whenever I turn off the TV and I need to "shutdown" the raspberry pi (ssh into it to run the shutdown command or from XBMC). If the raspberry pi is idling, it's not as risky to just cut the power, although, like any computer, it is always best to shutdown safely (you stand the risk of corrupting the filesystem). Also, whenever the TV is on, the raspberry pi is on. In XBMC, you can enlist an idle timeout to shutdown after X minutes of idle use. Remember the raspberry pi will continue to consume power from the TV even if it is shutdown.
Solution 1: Panic Button
I purchased a Panic/Stress relief USB button from TheSource for clearance ($4.96 -
http://www.thesource.ca/estore/product.aspx?product=8003038&language=en-CA). I knew it would feature essentially a USB interface to 2 i/o streams that would be either high or low. I could then write a simple shell script that polls the stream and performs a clean poweroff when the button is pressed.
Pros:
- cheap and resourceful
- kind of geeky (re-pursing a device)
- the casing can be taken apart and just the logical board with usb cable can be deployed
Cons:
- a USB device that occupies a USB port
- doesn't provide a full power off state
- doesn't address the POWER OFF requirement
Solution 2: Brew your own circuit
Use a breadboard and construct a logical switch to perform the same function as solution 1.
Pros:
Cons:
- more expensive (the components are fairly cheap, but you need to buy them in qtys of 5-10, and the price starts to add up)
- very susceptible to movement
- size of the breadboard alone becomes impracticable for scenarios where the footprint of the device is a factor
- doesn't address the POWER OFF requirement
Solution 3: Buy a PCB
Since this is a common problem, some smart people have come up with solutions
http://www.pi-supply.com/product/pi-supply-raspberry-pi-power-switch/
Essentially, this circuit board is place inline with the micro-USB power line, with a single connection to the GPIO. It cuts the power to the
Pros:
- extremely geeky
- very small
- easy to integrate with any setup
- doesn't affect your case design
Cons:
- very expensive (15 pounds converts to just under $25 Canadian, the price of a raspberry pi)
- you need to construct the circuit yourself (solder the components onto the PCB)
- would still need to add a separate button circuit or usb device to allow for triggering a shutdown
- doesn't address the CLEAN SHUTDOWN requirement
Solution 4: Direct Shutdown PCB
The best solution I found was a fully assembled direct shutdown PCB from a hobbiest
http://www.mausberrycircuits.com
He offers a wide range of solutions with various style switches (including add-your-own). He will even work with your design requirements and alter the switch.
Essentially, this circuit board is place inline with the micro-USB power line, with two connections to the GPIO (1 input, 1 output). A press of the button or a toggle of the switch takes the unit from off (complete power off for the raspberry pi) to on mode. A shell script starts on bootup that passes a high/1 to the switch to instruct indicate the raspberry pi is on. A low/0 signal passes from the switch to the raspberry pi to indicate the switch is neutral. A toggle of the rocket switch to off or holding a press button switch for two seconds changes the output to high/1 which the polling script triggers a safe poweroff. When the raspberry pi has finally fully shutdown, the GPIO goes from high/1 to low/0, which tells the switch the raspberry pi power can be cut safely. The rocket-style switches also come with a reset button that can trigger a raspberry pi reset if it becomes frozen, etc -- something that normally would require to pull the power line.
The switch also detects software shutdowns invoked by the user (as the GPIO will toggle from high/1 to low/0, which the switch polls for).
Pros:
- very small
- may need some modification to your raspberry pi case
- addresses the CLEAN SHUTDOWN and POWER OFF requirements fully.
- everything fully assembled
Cons:
- expensive but cheaper then any alternatives
I purchased a number of the switches from Mausberry Circuits. The illuminated push button switch easily integrates into my lego design cases -- the added width is 1 lego block.
Here's what my case looked like before adding the switch:
I had to rip down the right-side wall to set it up. But it is lego after all. Time to integrate the switch into the case!
Solution 5:
RemotePi Board by
MSL Digital Solutions (
added December 2013)
At its core, the
RemotePi Board by
MSL Digital Solutions promises the same functionality has the that intercept the micro USB power connector on the Raspberry Pi, which is to control the power on/off state of the Pi through a switch and through software. But instead of intercepting the power flow through the micro USB power connector, it controls the power through the GPIO. Instead of connecting your power to the micro USB power connector on the Raspberry Pi, you connect it to this board. You then either toggle the power state by pressing the black button on the top, or better, you can use a IR remote to toggle the power.
Pros:
- very small
- may need some modification to your raspberry pi case, but otherwise fits within the existing case (doesn't extend out from the board's footprint)
- addresses the CLEAN SHUTDOWN and POWER OFF requirements fully
- no issues with provided switch script (for other switches, I had problems and I had to make customizations to the scripts provided by other offerings)
- fully integrated IR receiver that can be used to allow your IR remote to control XBMC
- everything fully assembled
Cons:
In action:
Integrated into a lego case:
The power button is accessible from the top: