Skip to content

**** ****

Shutdown button for my Pi


It has been around a year now since my first Pi arrived and that first Pi has always been used as a media centre for my trailer and at home.

The problem being…

I use the remote app on my phone and iPad as the primary control there is no keyboard attached to the Pi for input. On the rare occasion there is a problem where either XBMC hangs up or the Pi drops from wifi I have no way to power it off other than unplugging it.

At home when it is just the wifi problem no biggie, the physical remote over HDMI works but at my trailer I have an older TV and this doesn’t work.

Anyone who has used a Pi knows you do an unclean shutdown enough times and you have to re image the OS because the file system damage is not always repairable. With lower quality cards this even sometimes leads to the SD card becoming unbootable permanently but I have only had that happen with one particular brand.

The solution

So I have some buttons left over from my original Arcade project and I decided to solve the problem by adding a shutdown button to my Pi. This way even if XBMC locks the physical button can execute a shutdown. It would take a full hardware lock of the Pi to cause a forced power off again and the only time I have seen that occur is when over clocking to 1Ghz so this should in almost all cases solve the problem!

Hardware

In this particular case I am using a red sanwa style arcade button for the shutdown, red seemed appropriate I also had blue and white available. I got this button from Adafruit last year along with the easy connector cable that will be used to connect to the GPIO on the Pi.

I connected the cable to the last pair of pins on the GPIO board as it was the easiest place to place the jumper and manipulate the cable in a manner to fit through the GPIO slot on my Pibow case.

I tried to keep as much of the cable within the case as possible, this is meant to be functional not pretty. Maybe I’ll get a smaller button in the future but this is what I had on hand.

Software

I’m using retrogame to handle the GPIO input detection and also the shutdown activation. Recent versions of retrogame seem to have taken this out but I forked an earlier version that has what I want for my projects.

For the Vulcan nerve pinch code to work with just a single button I just modified the bitmask to look for the same button instead of 2: (1L << 5) | (1L << 5)

Results

It works! hold the button for about 2 seconds and the Pi shuts down. This hopefully will extend the life of my OS and the SD cards.

Facebook Comments


Categorized as: What's up


12 Comments

  1. Justin says:

    Does retrogame start up automatically in the background?

  2. Hmm it seems like your site ate my first comment (it was extremely long)
    so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog writer but I’m still new to
    everything. Do you have any tips and hints for novice blog writers?
    I’d certainly appreciate it.

  3. matt says:

    it would be great to have a few more details here for newbies. how this the switch wired to the GPIO? how is game software installed and modified. thanks in advance.

  4. KingPhil says:

    Sure, I’ll write up a follow up details post

  5. Josh says:

    would this work for an in car mounted airplay server?
    I want the pi to shutdown when the power is switched off.

  6. […] time ago I made a post about adding a shut down button to my Raspberry Pi which I then followed up with how to set it up to also be the power on […]

Leave a Reply