RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Finished: Retropie case with on/off switch and power LED

    Scheduled Pinned Locked Moved General Discussion and Gaming
    caseswitchpower ledmomentaryheatsink
    24 Posts 6 Posters 6.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • coldnpaleC
      coldnpale
      last edited by coldnpale

      8bitjunkie button script

      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.

      1 Reply Last reply Reply Quote 0
      • caver01C
        caver01
        last edited by caver01

        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.

        My 4-player cocktail style cabinet built as a custom "roadcase"

        ? coldnpaleC 2 Replies Last reply Reply Quote 1
        • ?
          A Former User @caver01
          last edited by

          @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.

          caver01C coldnpaleC 2 Replies Last reply Reply Quote 0
          • coldnpaleC
            coldnpale @caver01
            last edited by

            @caver01
            Thanks for the information! I believe this answers many questions!!

            1 Reply Last reply Reply Quote 0
            • caver01C
              caver01 @A Former User
              last edited by

              @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.

              My 4-player cocktail style cabinet built as a custom "roadcase"

              1 Reply Last reply Reply Quote 0
              • coldnpaleC
                coldnpale @A Former User
                last edited by coldnpale

                @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.

                1 Reply Last reply Reply Quote 1
                • caver01C
                  caver01
                  last edited by caver01

                  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.

                  My 4-player cocktail style cabinet built as a custom "roadcase"

                  coldnpaleC ? 2 Replies Last reply Reply Quote 2
                  • coldnpaleC
                    coldnpale @caver01
                    last edited by coldnpale

                    @caver01
                    I believe I know the answer but since you probably know better i thought i'd ask.

                    1. After performing a shutdown from switch or emulationstation, is it safe to unplug the power adaptor?

                    2. 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. :)

                    jebbettJ 1 Reply Last reply Reply Quote 0
                    • jebbettJ
                      jebbett
                      last edited by

                      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 :)

                      1 Reply Last reply Reply Quote 0
                      • jebbettJ
                        jebbett @coldnpale
                        last edited by

                        @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.

                        1. After performing a shutdown from switch or emulationstation, is it safe to unplug the power adaptor?

                        2. 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..

                        coldnpaleC 1 Reply Last reply Reply Quote 2
                        • coldnpaleC
                          coldnpale @jebbett
                          last edited by

                          @jebbett
                          Thanks!

                          1 Reply Last reply Reply Quote 0
                          • ?
                            A Former User @caver01
                            last edited by

                            @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.

                            caver01C 1 Reply Last reply Reply Quote 0
                            • caver01C
                              caver01 @A Former User
                              last edited by

                              @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.

                              My 4-player cocktail style cabinet built as a custom "roadcase"

                              ? 1 Reply Last reply Reply Quote 1
                              • ?
                                A Former User @caver01
                                last edited by A Former User

                                @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?

                                jebbettJ 1 Reply Last reply Reply Quote 0
                                • jebbettJ
                                  jebbett @A Former User
                                  last edited by

                                  @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..

                                  coldnpaleC 1 Reply Last reply Reply Quote 0
                                  • coldnpaleC
                                    coldnpale @jebbett
                                    last edited by coldnpale

                                    @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.

                                    1 Reply Last reply Reply Quote 1
                                    • B
                                      BigBadHodad
                                      last edited by

                                      I installed the script and the button will start the pi up but not shut it down, does anyone know what could cause that? When I first tested it it would shut down but not anymore.

                                      Also sorry about grave digging, just trying to keep the posts in one thread.

                                      mituM 1 Reply Last reply Reply Quote 0
                                      • mituM
                                        mitu Global Moderator @BigBadHodad
                                        last edited by

                                        @BigBadHodad Please open a new topic and add more details about your setup.

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post

                                        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.