Raspberry pi on/ off button - clean shutdown

This is related to the Airport departure board project you can check out here.

The need for umbilical cords connecting to the mouse on my live airport departure board was bothering me so extremely that I had to do something about it or I wouldn't feel whole.

As hinted on the original article, I knew I had to add an on/ off button to the sccreen. I went back a few years when I originally had to do the same for another project (SIMPLE SOUND BOX - A RASPBERRY PI AS A SIMPLE MUSIC PLAYER).

I proceeded to do exactly as I wrote on that music box article:

  • I dug up a momentary switch from the garbage pile, soldered two wires to it and protected the connections with heat shrink.
  • I made a hole on the enclosure and put the button through (see picture at the top of the post to confirm I ain't lying).
  • I connected the wires to pins 5 and 6 of the pi.
  • For power on there is nothing more you need to do because connecting pin 5 to 6 will conveniently power on the pi.
  • There's a tiny little more we need to do for the powering off feature. Thankfully someone smart has had this problem before and I made use of this code that I have now cloned on to my own repository so I can keep it forever and ever as I seem to get back to it once in a while.
  • Ensure git is installed on your pi and clone my repository: git clone https://github.com/commacmms/pi-power-button.git
  • Run the installation script (will ensure the listener gets loaded on each system startup): ./pi-power-button/script/install
And that's about it, really. Press to start, press to stop.


Comments