GPIO Power button and LED indicator - AddOn (v0.2)

rasplex

#1

0.2 tested on build 1.8.0.148
0.1 tested on build 1.6.2.123

I hate I don’t have a physical power button to turn on and off my rasplex without dealing with physical addons or having to unplug and plug again to restart my rasplex. Things that I thought that could be easily be solved with a push button.

I also added a power button to power a LED so I can know If rasplex is up and running as the default green and red led indicates other things like SD access and if it has power.

For all this Im adding the python GPIO support to rasplex which isn´t available on normal setups

To install

Extract the content inside “/.plexht/addons/packages/” so you get a gpio folder

if you dont know how to uncompress in linux its
tar xf gpio.0.1.tar.gz

Edit or create autostart.sh (default location at “/.config”) with

#!/bin/sh
(PYTHONPATH="${PYTHONPATH}:/storage/.plexht/addons/packages/gpio/lib";
export PYTHONPATH;
sleep 10s;
python ~/.plexht/addons/packages/gpio/bin/shutdown.py;) &

and reboot

Features

  • Press the power button to turn Rasplex on
  • Press the power button for 3 seconds to securely turn off Rasplex
  • Lights a LED connected to PIN 10 to indicate if the unit is running

#Wiring

For this I’m connecting ping 5 to ground ping 6 with a pushbutton
Pin 10 goes to the LED circuit back to ground pin 9
So your setup should look something like this.

I wont explain LEDs and resistors here but you cant connect a LED directly to your Rpi, you need to use a resistor and anything over 15 Ohms should do the trick with LEDs of 20 mA. Just add a bigger resistor if you want it dimmer.

If you notice my script it only takes care of shutting down the system, as Pin 5 its the default Pin for powering on any Raspberry from standby. So its nice to use the same pin for shutting it off.

I also like to use pin 6 and 9 as my ground pins as they are next to the others.

Hope you find it useful for your setups, its specially useful if you are building your own case

Changes on the new 0.2 version

I made some upgrades to the script for better integration.

  • Now it has some fault tolerance when dealing with interrupted connections on the 3 second press time that should fix most user problems
  • A pop up message is displayed when the button is pressed and the max time is reached so you can have some GUI information of what its happening
  • If a LED is also present, it will blink a couple of times to signal the shutdown command

#2

Thanks for this. Going to give it a try later this coming week.


#3

"Press the power button for 3 seconds to securely turn off Rasplex"

and by 'securely' you mean gracefully shutdown ? or.. ?


#4

@wavrunrx said:
"Press the power button for 3 seconds to securely turn off Rasplex"

and by 'securely' you mean gracefully shutdown ? or.. ?

Yes, it will send a shutdown command and preserve the SD from any corruption.

Its exactly the same state as if you shut it down from the menu and leave the power cord connected, but pin 5 works as a wake up to power it up with the touch of a button.

Think of it as a stand by state on any other device


#5

Thanks!

I've been looking for a pre-built RPi.GPIO version for almost 6 hours, none of them worked, or links were dead or led to shady places... Should have checked here first ;)

Now I can finally finish my dualboot Rasplex/RetroPie machine by adding my momentary latching button to it, so the gf can easily shut it down after using it.


#6

And yesterday I have soldered cable to the "Run" pins of the RP3 to connect a start button. I could have really easier :D


#7

@compoti said:
And yesterday I have soldered cable to the "Run" pins of the RP3 to connect a start button. I could have really easier :D

Well to be fair, those pins are for something different as it will do a hard reset so you don´t really want to accidentally press it and corrupt your SD so it might be a dangerous option for powering on a Pi.

Make sure your button doesn´t pop out of your case to avoid any accident.


#8

My Raspberry will shutdown after 60 minutes in idle and the Button is only for a cold start. But I think I want to change to your GPIO start button. It just looks much more meaningful. Apart from that, I would also like a working light.


#9

Yesterday I have upgraded my Raspberry in the child room with your GPIO start button. It's work great, thanks for the addon :-bd


#10

@compoti said:
Yesterday I have upgraded my Raspberry in the child room with your GPIO start button. It's work great, thanks for the addon :-bd

Good to know its of some use

on the next update, once I have some free time, I think I will make the countdown half long and place a GUI notice to let you know you are shutting down the system


#11

Hello, thank you for this feature.

I have unzipped all the files installed in the correct location as well as creating the autostart.sh in the /.config directory. However, it is not working and I don't know how to troubleshoot.

When I press and hold the button it shuts the pi down after about 10 seconds and I need to power cycle to get it running again. I get the feeling that the autostart file is not doing what it should.

I am not new to electronics but I don't do any programming and python is new to me. It took me forever to figure out how to ssh into the pi and navigate around. Very willing to learn, though.

Thanks


#12

@"One Bit Wonder" said:
Hello, thank you for this feature.

I have unzipped all the files installed in the correct location as well as creating the autostart.sh in the /.config directory. However, it is not working and I don't know how to troubleshoot.

When I press and hold the button it shuts the pi down after about 10 seconds and I need to power cycle to get it running again. I get the feeling that the autostart file is not doing what it should.

I am not new to electronics but I don't do any programming and python is new to me. It took me forever to figure out how to ssh into the pi and navigate around. Very willing to learn, though.

Thanks

Hi @"One Bit Wonder"
The script itself just takes care of the safe shutdown process, to power it up you need to close the circuit of ping 5 and ground. Its just a feature that its just build on the Pi itself. And thats the main reason why Im using the ping 5 for the power.

Also make sure that you are using a push button


#13

I am using a momentary button to short the gpio3 to ground. The Pi does not sleep after 3 seconds, nothing happens after 3 seconds. If I hold for close to 10 it shuts the pi down and I have to reboot.

I have wired a led and current limiting resistor from gpio 15 to gnd and that works.

You say the script takes care of the shutdown, so it seems the script is not being executed. Suggestions on how to troubleshoot this?


#14

@"One Bit Wonder" said:
I am using a momentary button to short the gpio3 to ground. The Pi does not sleep after 3 seconds, nothing happens after 3 seconds. If I hold for close to 10 it shuts the pi down and I have to reboot.

I have wired a led and current limiting resistor from gpio 15 to gnd and that works.

You say the script takes care of the shutdown, so it seems the script is not being executed. Suggestions on how to troubleshoot this?

If the Pi shutsdown after X number of seconds, then the script its working correctly

The reason it takes more time its that the circuit you are building with the push button circuit isnt good enough for the script to read a stable signal without interruptions for 3 continuos seconds. This might have to do with some radio interferences, a bad button or things like that. Im shure that the circuit could be made better but I havent bothered as it just works for me.

If you find it hard to shut down just make the time value smaller


#15

Hi people, I made some changes to my shutdown script that I hope it will help you

  • Now it has some fault tolerance when dealing with interrupted connections on the 3 second press time that should fix most user problems
    Sometimes its hard to get some solid 3 seconds of closed circuit without interruptions if the press button or electronic skills arent good enough. This will try to compensate some current interruptions so it doesnt feel like you have to press the button for +10 secs to get a shutdown

  • A pop up message is displayed when the button is pressed and the max time is reached so you can have some GUI information of what its happening
    You can edit these messages to anything you want in line 9 and 10 of shutdown.py

  • If a LED is also present, it will blink a couple of times to signal the shutdown command
    Useful if you are using Rasplex headless or you dont want to turn the TV to shut it down