smart switch for Raspberry Pi

IMG_1762

I recently decided to use my second Raspberry Pi which I wasn’t using as an emulator for old video game consoles. I won’t detail the emulator part, but I used PiMame which does basically what I wanted.

But I had a problem :  the shutdown ! Because yes, the only way to turn off my “gaming console” was to unplug the power cable; this is not convenient at all, and it also does not properly shutdown linux.

I did some research to find a switch for the Raspberry Pi which waits for the linux shutdown to cut the power, I found one but it wasn’t exactly what I was looking for; it has several buttons (one for power on, one for power off and one for reset). I didn’t want that, I only want one button which does power on and power off.

So I decided to do it myself ! The specifications were simple :

  • only one button for power on and power off
  • the power off should notify the Raspberry Pi to shutdown, and then wait some time to cut the power

Here is how it works:

  • there is a bi-stable relay, which brings the +5v to the Raspberry Pi
  • the button is a “momentary” button (and there is also a led inside the button, which is nice)
  • when the button is pressed, it applies +5V to the “set” coil of the relay, and the power is applied to the whole system
  • then the Raspberry starts, and there is a small batch script which put ‘1’ to an output gpio
  • this gpio drives the base of a transistor mounted as an inverser
  • when the user press the power button again, it applies +3,3V to an input gpio
  • the script on the Raspberry sees the ‘1’ on the input, it now drives the output to ‘0’ and it ask a shutdown
  • this ‘0’ on the output gpio now drives a +5v on the collector of the inverser transistor
  • on the collector there is a capacitor with a resistor, so the capacitor starts to load until +5V
  • the capacitor is connected to the V+ entry of a op-amp mounted as a comparator
  • on the V- of the op-amp, there is a zener diod at 3,6V. So when the capacitor is loaded at 3,6V (the values are chosen so it takes about 2 minutes, which is too long but I planed to much when I designed it, I will change later) the op-amp output toggled to +5V (it is a rail-to-rail op-amp)
  • this op-amp output is connected to the reset coil of the bistable, which cut the power of the system, et voilà !

Here is a link to the schematic : SmartSwitch.pdf

For sure this is not perfect, but I am not an hardware guy, and this is a first version !

There are some other stuffs on my schematic that do not concern this switch. There is a connector for a fan, because I want to cool down the temperature of the Raspberry Pi, it can be quite hot when the emulator is running. And there is also a switch; I want to select on which emulator the Raspberry starts instead of having to choose it on the pimame menu (which requires a keyboard !).

 

Next step : design a nice PCB, instead of this ugly prototyping board !

This is a quick explanation, if you need more details, do not hesitate to leave a comment !