One of the early design goals that I had for the bartop arcade cabinet was that it needed to be as user-friendly as possible. To a person using the cabinet, the actual inner workings should be both hidden and non-intrusive. With a Raspberry Pi, the largest obstacle in the way of that is that in order to power off the device safely, the standard practice is to either shut down from a menu in a front end, such as EmulationStation, or to issue a Shutdown command from the command line. Neither of those options are particularly attractive to me and this is a common problem faced when creating a project that is not intended to run as a headless setup. After a bit of evaluation, the solution that I have chosen to use comes in the form of petRockBlog’s PowerBlock.
Looking at Available Options
There are surprisingly few options that are readily available, in terms of being able to provide both power off and power on functionality. I immediately dismissed the idea of cutting power directly, through either a Switch or through a power supply which has an inline switch. Considering that I will be working with line voltage, I do want to have a definitive kill switch. However, a non-clean shutdown can lead to data corruption. While people say that they have cut power to their devices countless times without issue, there are also those who have done so and corrupted an image. I would simply rather not risk a non-clean shutdown, unless I have absolutely no options remaining.
This led me to the two most common and readily-available solutions that are created just for this purpose. Both Mausberry Circuits and petRockBlog have available products to provide safe shutdown to a Raspberry Pi, through discrete hardware solutions. Both offerings are outstanding, and each have features that the other does not, and both operate on the same general premise. Essentially, a switch is used to trigger a safe shutdown and once the Raspberry Pi has completely shut down, it will cut power to the device. Powering up is then a process of closing the circuit, which will provide power back to the Raspberry Pi. Considering this article is about the petRockBlock Powerblock, it is obvious that I have made a choice. That choice, however, comes down to my specific needs and how I value the features for this project, as opposed to either one having an obvious advantage over the other. To illustrate, it would help to understand the features of the two.
Mausberry Circuits Shutdown Circuit
Initially, I tried the Shutdown Circuit from Mausberry Circuits. It is the smaller of the two boards, with the Shutdown Circuit designed to be used inline with the power supply for the Raspberry Pi. Between the two, it is the smaller solution, by far. The entire circuit easily sits on a U.S. quarter dollar, and the density of the circuit board is high, with the pin outs sitting on the edge. This does tend to make any sort of mounting difficult, as there is neither room for edge mounting, nor any pre-drilled holes for a standoff. As intended, the model that I am using sits inline between the power supply and the Raspberry Pi through the use of male and a female micro USB connections. The male end would be inserted into the female micro USB connector on the Raspberry Pi, and the power supply connected to the female end of the circuit. There are two pins that are connected to user-configurable GPIO pins, which are pulled to initiate the shutdown. There are also other configurations available, as it relates to how the circuit is connected to the Raspberry Pi, but they are operationally all similar, otherwise.
One unique feature of the Shutdown Circuit, is that it is capable of auto-detecting the type of switch being used. This flexibility means that either a momentary switch or a latching switch can be used, with no additional configuration changes to make. Aside from the pin out to connect a switch, there is an additional pair of pin outs that can be used to issue a reset, instead of just a shutdown. Finally, there is also a pair of pin outs that supply 3V DC, in order to power an external LED. That is in addition to the chip LED that is already onboard.
Verdict: Overall, the Shutdown Circuit packs a lot of functionality into a small space and at a reasonable price. If using any sort of HAT, the Shutdown Circuit is a great solution. In general, wherever space is at a premium, the Shutdown Circuit provides a compact and purpose-driven solution.
Source: Mausberry Circuits · Shutdown Circuit (Price: $17.99 USD)
For completeness, I only discovered the PowerBlock from petRockBlog after I had tried the Shutdown Circuit from Mausberry Circuits. The PowerBlock is a partial HAT, occupying the first six sets of pins on the GPIO header. It is the same depth as the Raspberry Pi, while only being around one inch wide. While it does not come with any, I will be adding a pair of 2.5Mx15mm standoffs, using the holes on the PowerBlock. Without, the entire stress of the card is at the point of the header and while handling of the device is usually minimized, I found myself awkwardly supporting the HAT while I was testing it, just so I would not apply downward pressure to the non-supported edge. Out of the box, the PowerBlock has a female micro USB input, which is for the power supply. This means that the micro USB input on the Raspberry Pi will not be used to supply power. While this is the only configuration available for purchase, this solution offers several great additional features, such as a 5V DC input that can be used to attach a barrel plug or terminal block, along with a 5V DC output that can be used as a passthrough for other 5V DC power requirements, such as operating a fan.
The PowerBlock requires a latching switch and strictly offers on and off functionality, meaning that there is no autodetection of switch types, nor the ability to wire in a reset button directly. The latter is not as much a negative as the inclusion of it being a bonus for the Shutdown Circuit. Wiring a reset to use a GPIO pin is trivial, if it is a feature that I want to add in, as documented in makeUseOf’s “How To Add A Reset Switch To Your Raspberry Pi“. LED pin outs are also provided, operating a 5V DC. Most 12V latching buttons with an LED will light on 5V DC, albeit dimmer than at 12V. This means that there are more button options available, which feature integrated lighting, without needing to step-up the voltage to make them operational. One additional feature that is present on the PowerBlock is the built-in LED sequences that it uses for startup and shutdown. On startup, the LED will slowly pulse, yielding to a solid light once the inital boot process has completed. On shutdown, the LED will pulse at twice the speed, until the power is cut to the Raspberry Pi. This provides immediate feedback as to what the device is doing, which is a nice touch when it comes to the user experience.
Verdict: Overall, the PowerBlock is a well-concieved circuit that comes at the expense of not being able to stack an additional HAT. The price is only slightly higher than the Shutdown Circuit, but provides a bit more flexibility.
Source: petRockBlock · PowerBlock (Price: $21.90 USD)
Installation and Configuration of the PowerBlock is very straightforward. The first step is to shutdown and remove power from the Raspberry Pi. Upon doing so, the PowerBlock is attached to the GPIO header and the switch attached to the pin outs on the PowerBlock. Then, the Raspberry Pi power supply is connected to the PowerBlock’s micro USB input. My switch is currently on-order, so I am using a single cable with female to female DuPont connectors to bridge the pins, in the interim, as well as a plain blue LED hooked up to the LED pin outs. Until my switch is properly installed, I simply remove one end of the cable from the pin outs, and it initiates shutdown. Connecting the pin closes the circuit and begins the boot routine.
In order to have the switch operate, there is a simple set of commands required to download required components, then build and install the service that is monitoring for the changes in state to the power switch. From a command line, ensure that all updates are installed, along with the build dependencies:
sudo apt-get update sudo apt-get upgrade -y sudo apt-get install -y git cmake g++4.9 doxygen
Next, the PowerBlock service needs to be downloaded and compiled:
cd ~ git clone git://github.com/petrockblog/PowerBlock.git cd PowerBlock mkdir build cd build cmake .. make sudo make install sudo make installservice sudo reboot
At this point, nothing else should be required, and the switch should operate as expected. From a powered on state, with the switch latched, unlatching the switch will initiate the shutdown process. If an LED is connected, it will begin pulsing quickly while the shutdown is in process and will go dark at the same time power is cut from the Raspberry Pi. Latching the switch from a powered off state, the LED will begin pulsing slowly until the main boot processes have completed. When running RetroPie, that means that it will enter a solid state around the same time that the RetroPie splash screen is displayed.
In action, this is the demonstration video directly from petRockBlog:
Once I receive my switch and reassemble, I will include a video of my own setup, along with information related to the switch.
The post Using a PowerBlock with a Raspberry Pi appeared first on Back to the Arcade.