Finished: Retropie case with on/off switch and power LED
-
@jebbett Thanks for the feedback! Box costed me 10e, so i'd say it's on the cheap side.
For the switch:
I wired a momentary button on pins 5 and 6. With this I was able to only turn on the pi. Then I used the script from a tutorial I found on 8bitjunkie to make it also perform a safe shut down. For the shutdown it feels like you have to hold the button for about half a second, maybe a bit less. I believe it was programmed to worked like that to avoid accidental shudowns from unwanted electrical behaviour. For example, I read that some people had some sudden shutdowns when inserting a usb device, but with this script I am not experiencing any issues. -
And in order to keep the wiring clean and not block the airflow from the mesh alu on the sides I organised my wires like that:
-
Didn't know you could use pins 5 & 6 like this.
Could you share the script? Might order a button and try this this weekend.
-
@livefastcyyoung
I didn’t think so either, but see the link below..
https://www.raspberrypi.org/forums/viewtopic.php?t=191145
Everyday is a school day!
-
Scroll down to keyboard method (uk). That's what I did.
Just make sure it is a momentary push button and not an on/off switch.
Can't imagine using a pi without a button now. I can't stand unpluging and repluging the adaptor.
-
This technique has been around for a while. It relies on the fact that a Pi can be "awakened" from deep sleep by shorting pin 5 to ground. That is what the momentary switch does.
Then, once booted, you have the python script loaded that basically sets up the same pin as GPIO input, sets it to HIGH and watches the pin to go low (the script sleeps and loops until it sees this happen). When this happens, it issues a safe shutdown command.
There are a bunch of ways to write the script. You could do it in BASH too if you wanted. The looping aspect is not the best method. With python you could just as easily setup edge detection so that it is not wasting CPU cycles looping every half second. The .5 delay is also probably why you need to hold the button for a moment. Depending on when in the sleep loop you press the button, it would take, on average, a quarter second (but as much as a half second) for the script to loop and check the status of the pin.
Before using a Mausberry circuit, I used this method for safe shutdown. It is definitely the easiest/cheapest way to go. However, after the shutdown, the Pi is not actually turned off. It is still consuming power which may be a problem for portables. Also, if power cycles, it will boot right up. LEDs may also still stay lit, etc. However, for the cost of a simple momentary switch, a few wires and a script, you get a power switch that works well enough for most purposes, and certainly better than pulling the micro USB every time.
The more complex circuits out there like the Mausberry have the added ability to monitor the Pi, and when the circuit detects a shutdown, it really cuts the power. These circuits also don't turn power back on until the user presses the button/switch (a power outage/cycle won't inadvertently turn on the Pi). This behavior is more aligned with expectations people have with modern electronics. The question is whether this final step is worth the investment for you.
The 8bitjunkie link above is nice because it sets up everything. If I made one improvement, however, it would be to adjust the logic in the python script in favor of GPIO edge detection to get out of the looping.
-
@caver01 Thanks for all of this! With all of that said, I think I'll pass on using this method. The only reason I really want to be able to shut down the Pi is because of the fan installed in the case. I don't want it running when I'm not using it. Since this method wouldn't truly cut power, that fan would continue to run.
Back to the drawing board for me.
-
@caver01
Thanks for the information! I believe this answers many questions!! -
@livefastcyyoung
You might do some tests. Depending on how you power the fan it might still work. If you are pulling power from the GPIO header, it might cut power on that while in deep sleep. I don’t recall. -
@livefastcyyoung
I also have a feeling the fan will stop.
My LED turns off when I power the system down from the switch. I am not seeing any difference when I am performing the shutdown from emulation station or the switch. Both ways leave some small board leds on, but the power from the pins should be cut off. You could install the script and short the 2 pins with a screwdrver or a jumper to test it. -
The nice thing is that this is such a simple way to setup a basic power switch that you can test it by just doing the software script alone, then carefully shorting pins 5 and 6 with anything conductive to test. In other words, you don’t really need to wire up a switch to do a test.
Actually, forget that, you just need to issue a shutdown command at the command prompt and see if your fan powers down. Simple.
-
@caver01
I believe I know the answer but since you probably know better i thought i'd ask.-
After performing a shutdown from switch or emulationstation, is it safe to unplug the power adaptor?
-
Is the shutdown enough to remove the microsd card? Or should I also unplug the adaptor before removing it?
Thanks again for all the information, it really is schoolday today. :)
-
-
I suspect it drops the power too, but if not you could just hook up a transistor for a few pence and connect to another gpio..
Example here providing automatic fan control also :)
Just google "use a transistor to control a fan on the raspberry pi", I would post a link but the forum thinks it's spam :)
-
@coldnpale said in Finished: Retropie case with on/off switch and power LED:
@caver01
I believe I know the answer but since you probably know better i thought i'd ask.-
After performing a shutdown from switch or emulationstation, is it safe to unplug the power adaptor?
-
Is the shutdown enough to remove the microsd card? Or should I also unplug the adaptor before removing it?
Thanks again for all the information, it really is schoolday today. :)
The answer is yes to both, removal of the SD card is fine as long as it's not writing to the card at the time, in this case it wont be running at a software level, it's basically like standby on your computer..
-
-
@jebbett
Thanks! -
@caver01 said in Finished: Retropie case with on/off switch and power LED:
Actually, forget that, you just need to issue a shutdown command at the command prompt and see if your fan powers down. Simple.
When I run sudo shutdown now from the command prompt and my Pi still shuts down but the fan still goes.
The fan runs off pins 2 & 4 if that changes the equation at all.
-
@livefastcyyoung strange. Pins 2 and 4 are both 5v as far as I can tell. Are you sure you are not using 4 and 6 (5v and ground)? Another thought is that since you might be using 5v, you could see if the USB ports power down during a shutdown. If so, you could pull 5v from a USB port by hacking a cable and borrowing the red and black wires.
-
@caver01 I’m sorry, it’s definitely 4 and 6.
Unfortunately, I don’t have a free USB port. :(
Edit: is it possible in a shutdown script, to tell the Pi to kill all power for certain pins in the GPIO?
-
@livefastcyyoung said in Finished: Retropie case with on/off switch and power LED:
Edit: is it possible in a shutdown script, to tell the Pi to kill all power for certain pins in the GPIO
Yes, see my previous post.. but the 5v port is not a GPIO port, hence you will need to use a transistor to a GPIO for switching and link to the 5v for power..
Thinking more on this, the 5v rail can be used to power the Pi, so makes sense that it does not lose power.. 3v however may still have a chance..
-
@jebbett
Indeed, my 3v pin is powering off.
I wired a LED's anode + resistor on pin 8 (3v) and cathode on pin 6 (bridged with the button's ground wire).Then I activated the voltage on pin 8 from EmulationStation>raspi-config>interfacing options>Serial.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.