Once upon a time...

Once upon a time...
Christmas 2016

Friday, 24 April 2020

Adding a power button & LED to my Raspberry PI


  • There are many posts and articles out there about this topic, this post is record the approach I took and which of the posts I followed.


As previously mentioned, I bought a couple of Rev 1 Raspberry PI Model B's when they first came out and I touched on the fact that I was using one to run my Mendel 90 using OctoPrint in this post.

What I haven't blogged about it is the fact that I since built a 2nd Mendel 90 and sent the first one to my brother in South Africa along with the RasPi.

Well, mine has stood up to the test of time and the good old Rev 1 RasPi is still running my Mendel 90 with OctoPrint (leveraging OctoPi).

I decided I wanted to be able to safely power down as I run the RasPi in headless mode, so Googled about adding a power button, this led me to this article on howchoo, which links to another article about adding a power LED.

Anyway, I experimented using the RasPi 3 that I bought for my daughter's (failed) media centre project which worked great, so I created a switch and LED assembly pictured below (the astute/curious amongst you will note that the RasPi in the picture is actually yet another one that I have, a Rev 2).


When I then tried this on my Rev 1 board I discovered it didn't work, so some Googling later and I found an excellent resource in the form of this page by Matthijs Kooijman. It turns out that he devised a devicetree overlay (yes, I didn't know about this stuff before myself) which has been merged into the official Raspbian kernel repository from 2017.08.16 onwards. This means that you can achieve a powerbutton (same pins as the howchoo article) without the Python daemon, simply a boot config change, so I implemented this. (As per his page I had to tweak the setup for the Rev 1 as the GPIO on pin 5 is GPIO1 as opposed to it being GPIO2 on later RasPi's).

 So in summary, I used:

  • Matthijs Kooijman's instructions to add the powerbutton on pins 5 & 6
    • Coded added to /boot/config.txt
      • For Rev 1 RasPi: dtoverlay=gpio-shutdown,gpio_pin=1
      • For later RasPi's: dtoverlay=gpio-shutdown,gpio_pin=3
  • howchoo's instructions to add the LED on pins 6 & 8
    • Coded added (if LED doesn't light up) to /boot/config.txt: enable_uart=1

No comments:

Post a comment