Pi2RMini – a proper power switch for the RaspberryPi

This text specifically refers to the v1.0 boards. The files are all available on GitHub.

In order to make my RasPi MPD server more “living room” (read as you will…) and user friendly, it really needs to have a proper controlled power on/off switch. Additionally, it’s not good for the integrity of the SD card to have a slow switch off, which you get from turning off a normal supply or from trying to pull the lead out. Ideally, the system should be shutdown in software first, and then have the power removed. There are a two other projects which appear to do the same thing (by no means exhaustive!), but they also end up with more cables. Everyone using a RasPi surely already has too many cables..!

In order to do both for a small system, the Pi2RMini fits onto the GPIO header directly. There’s a switch and bicolour status LED onboard to control, so there’s no need for any wires if you don’t want them. Power connections are the usual micro USB B, or provision for a direct input potentially from a higher power supply. The power input can by fused with a resettable/non-resettable fuse depending on preference. Power to the RasPi is through a P-channel MOSFET acting as a switch, so only dissipating P = IRPi2Rds from a small SOT-23. The N-channel MOSFET is there to ensure the gate of the P-channel is switched fully off at 5V, rather than the 3.3V the microcontroller is at. As the board powers the GPIO header directly, it’s prudent to fit a polyfuse in F1 so there is some protection for the RasPi.

The board could be smaller, however it I wanted to keep it reasonably sized so people could build it themselves, and also it provides some mechanical support with the screw, useful if the power flex is heavy. The standard 6-pin AVR programming header is in the centre. If you are mounted in a case, the switch and bicolour LED are broken out on a separate header. The board is very easy to build up (trickiest is the USB header), and would actually be a good first SMD project. It’s also single layer, so you can etch it easily at home. I’ve included a correctly scaled PDF of the copper.

On the RasPi side, there’s a small script that runs in the background and checks for signals on the GPIO 7 pin and communicates (very simply) back to the Pi2RMini. On power up, the Pi2RMini will wait 20 seconds for a response from the RasPi; if this is not met, it will go into error mode (LED flashing red) awaiting a hard reset. When a signal to shutdown is received from the Pi2RMini, the script issues

sudo shutdown -h now

to shut the system down cleanly. The Pi2RMini will pause for 20 seconds after receiving acknowledgement of the shutdown signal and then switch off power to the RasPi. If no confirmation is received from the RasPi, the Pi2RMini will go into error mode (LED flashing red), and will require a complete reset. Pushing the button when the system is on for longer than 4 s (the LED will flash green then red continuously) will lead to a reset, and cut off power completely and instantly. It’s important to note, that this is less likely to corrupt your SD card than simply pulling the cord out, as the MOSFET switch-off is very quick. All the timings are easily altered in the firmware and flashed to the board. The code (I think!) is well commented, so it should be fairly obvious. There is approximately 47% of the flash space left on the ATTiny13, so there’s plenty of room for modifications – it would be great to see some!

To get the board up and running, you will need to run the following commands from your home directory:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install github
git clone git://git.drogon.net/wiringPi
cd wiringPi
cd ~
wget https://raw.github.com/awjlogan/Pi2RMini/master/pi2rmonitor
sudo chmod 755 pi2rmonitor

In order, this updates your RasPi and installs GitHub (steps 1-3), then installs wiringPi (steps 4-6), then gets the RasPi script for the Pi2RMini and changes it to executable. Finally, you need to add the following line to /etc/rc.local just before the final line (exit 0). This will start up the script when you first start your RasPi, so you don’t have to start the script up manually each time.

(cd /home/pi && exec ./pi2rmonitor) &

GitHub contents:

  • Changes.txt contains a summary of completed and future changes
  • Pi2RMini v1.0.brd Layout in Eagle format, v6.1.0
  • Pi2RMini v1.0.sch Schematic in Eagle format, v6.1.0
  • Pi2RMini v1.0.pdf Processed and properly scaled PDF for those wanting to etch their own boards. Not mirrored.
  • bom.xlsx full BOM, including Farnell part codes. These are for 100 quantities, approximately multiply by 2.5 to get the unit price. Total price is quoted for the Farnell parts, inclusive and exclusive of VAT. Not up to date with latest prices, only up to last modified date.
  • Pi2RMini.c Written in AVR GCC using AVR Studio v5. The compiled release binary is pi2rmini.elf and pi2rmini.hex

Released as free, open-source hardware. All the files are available to download from GitHub. Free to use, modify, and distribute. I will be offering these as the v1.1 board with some modifications as both kits and fully constructed in the near future. This will, of course, also be free, open-source hardware. Please subscribe to be kept up to date!


Eagle library – new parts.

Another very long delay, a few new parts to add to the Eagle library, which has now been downloaded over 1000 times! Thanks for using it, and as ever if it’s useful I’d love to hear about your projects.

New parts are:

742G34 dual non-inverting 74-series buffer, KCSA02 7-segment display, LT3032 dual positive/negative LDO regulator, and MAX1693 USB current monitor.

The DropBox link is no longer being updated, so please use the Git download link at:


Eagle library updated

Components added: 2N7002 N-MOSFET, 78LXX regulator, AP1117 LDO linear regulator, ATTiny24 microcontroller, DS1337 RTC, LM2576 switching regulator, MIC2026 high side MOSFET driver, PMDT290UNE dual N-channel MOSFET, PMEG4050 Schottky diode, TSM2323 N-MOSFET, USB2512 USB hub controller, USB2513 USB hub controller.

No prizes for guessing what I’m working on at the moment..! Made in Eagle 6.4.1. Any problems just let me know. Available now from the Git repo:


Eagle library moved to Git

Despite the lack of recent updates (things are happening slowly..!), I’ve decided to move everything over to a Git repository. I don’t have much (any) experience using it yet, so let me know if you have any problems with it! The repository can be found at:


The old .zip file is still available for the time being, but if all goes well it won’t be updated in the future. As ever, look forward to hearing from you!

USB Headphone Amplifier for the ObjectiveDAC


The Objective O2 amplifier and Objective DAC have generated a lot of interest recently, due to their excellent objective performance, and low cost. I built up a combined ODAC/O2, and was very happy with it. Unfortunately, the O2 requires an AC power supply at all time and bringing laptop, laptop power adaptor, the O2/ODAC, and it’s adapter leads to not a lot of space for anything else.

One of the main draws of the ODAC is its native 24-bit interface, which means that digital volume control doesn’t lead to reduced audio performance, as is the case with 16-bit audio. With this in mind, it should be possible to design a small board that is powered by USB without any need for a volume control onboard. Audio potentiometers are often quite large, expensive, and their tracking between channels isn’t particularly good. Also, the DAC used on the ODAC doesn’t have the output current capacity or voltage swing to drive headphones, and so a buffer (or buffer with gain) is required afterwards. I happened to have some of the excellent EL2002 buffers (sadly now no longer made) left over, although I will release a second board based on the O2’s driver chip, the NJM4556A. Continue reading

Eagle library updated

Rather a long time between updates, but I’ve uploaded a newer version of the library. Added in this one are:

  • LT3467 switching power supply control IC
  • EL2002 buffer
  • ELL6SH low profile inductor

There are a couple of redundant items in there, which are completely untested so please refer to the spreadsheet for more information!

As per request, this was created with Eagle v6.1.0. Download the library.

Stellaris RainbowLED (qs-rgb) Colour Fix

I have just received my two TI Stellaris Launchpads, and have been having a quick look at the software and usage. So far, it seems very impressive (especially given the promotional price) and the power and complexity of the ARM chip used is clear just looking at the default program installed. There is, however, a slight error in the software. On my two boards, if in a terminal you enter:

> rgb 00FF00

instead of the expected full green, it’s blue. Likewise, 0000FF gives green, not blue. This is obviously not a massive issue, but if you want to fix it simply replace lines 156 and 157 in the rgb_commands.c file with:

g_sAppState.ulColors[BLUE] = (ulHTMLColor & 0x0000FF) << 8;
g_sAppState.ulColors[GREEN] = (ulHTMLColor & 0x00FF00);

Recompile, and you’re done!