This article describes the PowerBlock itself, as well as how to connect a power switch and how to install the driver.
The PowerBlock provides a power switch functionality. Why might this be of interest for you? The Raspberry Pi comes without a power switch. As soon as you plug the micro USB cable into the RPi, it turns on. If you want to shutdown the Raspberry Pi, you need to call a shutdown command to to bring the system into a state in which you can safely remove the USB cable again. If you just pull out the micro USB cable your file system might become corrupted and you might possibly loose data.
Here, the PowerBlock comes into play. It is stacked onto the GPIO header of the Raspberry Pi and provides a micro USB connector itself, a connector for a toggle switch to control the power supply of the Raspberry Pi, and a connector for an LED to indicate whether the Raspberry Pi is off, booting, running, or shutting down. The power supply is controlled by a tiny microcontroller on the PowerBlock PCB that monitors the button state as well as the state of the Raspberry Pi and switches a MOSFET accordingly. This means that there is no need anymore to plug and unplug the USB cable from the Raspberry if you want to completely and safely turn it off.
Dimensions and Interfaces
The dimensions of the PowerBlock PCB are chosen such that it exactly matches the two mounting holes on the opposite of the USB sockets of the Raspberry Pi models A+ and B+. The PowerBlock PCB comes with the same round corners as the Raspberry itself and give it a neat look. Regarding the GPIO usage the PowerBlock is attached to the first 2×6 pins of the Raspberry Pi GPIO header.
Here are a top and bottom view of the PowerBlock PCB:
The hardware interfaces of the PowerBlock are described in the following:
- 2×6 pin female header as connector to the Raspberry Pi
The PowerBlock PCB is attached to the Raspberry with a 2×6 pin female header. This header makes use of pins 1 to 12 of the J8 header. This header is used for connecting the voltage and ground pins as well as the I2C pins between the RPi and the PowerBlock. The PCB is kept as small as possible so that you can easily access all other pins that are not used by the PowerBlock.
Micro USB Connector for the power supply
The PowerBlock has the same USB Micro connector as the Raspberry Pi. That means you can simply use your existing USB Micro cable for powering the RPi.
Pin Outs for 5V Supply Voltage and Ground
If you do not want to use the USB connector, GND and the 5V supply voltage can also be accessed via two pins so that you could use batteries or whatever you like to power the RPi.
Optional DC Barrel Jack Adapter
The PowerBlock is also prepared for connecting a DC barrel jack adapter. The hole dimensions for the barrel jack adapter are chosen such that most of DC barrel jack adapters should fit. Here is a picture that shows the PowerBlock with the optional DC barrel jack:
Pin Out for a Toggle Switch
To control the power state of the Raspberry Pi the PowerBlock provides an interface for attaching a toggle switch. The on-board microcontroller monitors the state of that switch as well as the one of the Raspberry.
Pin Out for Status LED
The current power state of the Raspberry Pi can be indicated with a 5V status LED that can be attached to the two pins that are provided by the PowerBlock. These states can be “off”, “booting”, “on”, and “shutdown”. The different state are indicated with easy-to-distinguish static and pulsing patterns.
Optional USB A Connector as power out
If you want to provide a switched 5V voltage to another device, you can solder a USB A connector to the PowerBlock – it is prepared for that as well. Here is a picture that shows the PowerBlock with both the optional DC barrel jack as well as the USB A connector:
In-Service Programmer (ISP) pin-out for ATtiny
The Power Switch logic is realized with the help of an Atmel ATtiny85 microcontroller. If you want to you have the possibility to access the microcontroller with the ISP header. In this way you could reprogram the microcontroller with whatever functionality you like.
Assembly of the PowerBlock
Assembly of the PowerBlock? Not needed – it comes fully assembled. You only need to connect a power switch and, optionally, an LED. This is described in more detail in the following.
Attaching a Power Switch
To turn the Raspberry Pi on and off with the PowerBlock you need to attach a toggle switch to the two button pins on the PowerBlock. Technically speaking, the microcontroller on the PowerBlock looks, if the two pins of the switch are connected or not. If they are connected, a GPIO pin of the microcontroller on the PowerBlock is pulled to GND and interpreted accordingly.
- It is important that you use a toggle switch and not a momentary button with the PowerBlock. Otherwise the Raspberry Pi will be turned off again right after booting.
- If you do not want to use the power switch functionality you can disable this in the configuration file /etc/PowerBlockconfig.cfg by setting “powerswitch”: false.
- The power switch circuitry of the PowerBlock leads to a tiny voltage drop and we made the experience that a good quality power supply and a good quality USB cable are mandatory for a working setup. If unsure, we can recommend the official Raspberry Pi Power Supply.
Attaching a Status LED
The PowerBlock has pin outs for an optional status LED that indicates the power state of the Raspberry Pi. You can directly attach an LED to the pins that are marked with “LED”. You need to pay attention to the polarity of the LED: The LED pins are marked with “+” and “-” for that.
The LED will blink in four different patterns that depend on the power state of the Raspberry Pi:
- Off: The LED is simply off.
- Booting: The LED slowly fades in and out.
- On: The LED constantly stays on.
- Shutting down: The LED fades in and out twice as fast as during boot up.
Software Setup and Configuration
The power switch functionality of the PowerBlock is controlled with the GPIO pins 17 and 18 of the Raspberry Pi:
- Pin 17 can be used to indicate the power state of the Raspberry Pi. This pin is read by the PowerBlock”s microcontroller to control the on-board power switch.
- Pin 18 can be read by the Raspberry Pi to get status of the button that is attached to the PowerBlock.
The PowerBlockService is an open-source driver for the PowerBlock. It provides a service for interacting with the power button signals as well as for mapping attached game controllers to corresponding game pad devices on the Raspberry Pi. The installation only takes a few steps and is done from command line. In the following, this is described in more detail.
The command-line installation consists of these steps:
- Installing required packages
- Fetching the latest version of the PowerBlock driver and service from the public repository.
- Compiling the driver binary.
- Installing the driver binary.
- Installing the service.
To be able to successfully build the driver you need to have certain APT packages installed:
sudo apt-get update sudo apt-get upgrade -y sudo apt-get install -y git cmake g++-4.9 doxygen
The following commmands for the command line do the above steps:
git clone git://github.com/petrockblog/PowerBlock.git cd PowerBlock mkdir build && cd build cmake .. make sudo make install sudo make installservice
You might need to reboot your Raspberry in order to have all needed services running.
The above installation procedure is also shown in this video. Please note that, other than in the video, you need to install g++-4.9 as described above:
This content is blocked. Accept cookies to view the content.
The following video shows the PowerBlock in action:
This content is blocked. Accept cookies to view the content.
What if you want to put your Raspberry Pi together with the PowerBlock into a case? If the RPi together with the PowerBlock fit into your case depends on the lind of power jack and the case you use. Overall, the PowertBlock adds about 6 mm in height to the Raspberry Pi 2 Model B. If you are interested, a user has published his design files for a 3D printable case that fits a PowerBlock at Thingiverse.
The PowerBlock is an extension board for the Raspberry Pi (TM). The key feature of the PowerBlock is a power switch functionality to safely turn on and off the power to the Raspberry Pi with a toggle switch. A connector for a status LED that indicates the power status of the Raspberry Pi can optionally be connected to the PowerBlock.
If you are interested in getting the PowerBlock, you can find it in our shop.