RpiPowerControl is smart power controller for the RaspberryPi.
Basically, it allows to power up and down the RaspberryPi with a simple push button. The power is removed from the RaspberryPi only when it has been gracefully shutted down. Moreover, RpiPowerControl provides 2 power outputs : one for the RaspberryPi, and the other one for another device (a touscreen, in this case).
- 2 independant outputs : one for the RaspberryPi, and one for any other device
- 2 LEDs to display the state of the system
- Control of the outputs using 2 push buttons
- Smart communication between the RaspberryPi and RpiPowerControl via a serial communication (USART)
I needed such a device in order to finalize a first prototype of Touchradio. Indeed, I wanted to be able to power up/down the system like I do with my TV or my computer : by pressing a single button. Without it, the only way to start and stop the Rpi is to plug and unplug the power cord. Not very convenient…
Some similar projects already exist, but the ones I found only allow to control 1 power output. For Touchradio, I needed 2 of them : one for the Rpi, and the other one for a touchscreen. So, I decided to design my own power controller, and I did it with my own possibilities and knowledge (and the help of a very cool colleague).
Of course, the way I did it is not the most direct one, or the most reasonnable one, mainly if I wanted to build it in series and to sell it. But I did these choices so that I can do it by myself, and that I’m able to implement all I need, at low cost.
RpiPowerControl is based on the evealuation board STM32F0Discovery (easy choice : I had one on hand, I know it, I’ve already worked with it). It’s an evaluation board for the processor STM32F051 (ARM Cortex M0). This µP is running at 48Mhz and has 64Kb of FLASH memory, and 8Kb of RAM memory.
Of course, this processor is overkill for this project, but, as I said, I had to board on hands, I wanted to use it.
I added a very simple electronic board so that I have 2 LEDs, 2 relays, 2 buttons, and a serial port.
The embedded software in the STM32F0 is written in C in the IDE Keil µVision4. A little daemon is running of the Rpi. It has been written in Python.
How does it work?
A 5V power supply supplies the RpiPowerControl. It’s this power supply that will supply the Rpi and the touchscreen when the relays will be closed.
RpiPowerControl has 2 push buttons. One of them allows to power on/off the touchscreen. When you push it a first time, the relay of the touchscreen is closed, and it is powered up. A second push on this button opens the relay and power the screen down.
The second button allows a smart control of the Rpi power supply. When you first push on this button, the relay of the Rpi is closed, and the Rpi is booting normally. A the end of the boot up sequence, the little Python darmon is started. This one starts by sending a little message to RpiPowerControl on its serial port indicating that it has successfuly booted. Then, the daemon waits for a command from RpiPowerControl.
When you push a second time of the button, RpiPowerControl sends a command on the serial port in order to ask the Rpi to shutdown properly. At that time, the Python daemon runs the command ‘shutdown’. At the end of the shutdown command, another Python scipt will be run in order to send a last message to RpiPowerControl, saying that the Rpi is shutting down. At this moment, RpiPowerControl will wait a certain amount of time (20 seconds) before opening the relay and powering down the Rpi.
In the case of the Rpi would shut down by itselfs, the notification command will also be sent, allowing RpiPowerControl to open the relay when the Rpi is shut down.
State of the project
Like Touchradio, this project is still under heavy development. The workflow described just above is implemented, but it needs some fixes and fine tunings.
The embedded C code and the Python software are not ready yet to be released, but I’ll publish them on my GitHub account as soon as I have finish with them.