RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Shutdown with keypress

    Scheduled Pinned Locked Moved Help and Support
    8 Posts 4 Posters 9.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.
    • adamspcA
      adamspc
      last edited by

      Is it possible to issue a shutdown command from only a keypress? I have a project very near completion and this is one of the final touches before I post the tutorial. I need to be able to press a keyboard key(any key, doesn't matter which one) and issue either one of the following commands:

      sudo shutdown -h now
      or
      sudo poweroff

      This would need to work both in EmulationStation and within games. I searched through retroarch.cfg and saw nothing related to powering down. I know that it has the ability, because I can hit start and go to shutdown and the system shuts off.

      Any ideas?

      https://www.othermod.com

      1 Reply Last reply Reply Quote 0
      • mediamogulM
        mediamogul Global Moderator
        last edited by

        You should find some helpful info here...
        https://unix.stackexchange.com/questions/107818/how-can-you-run-a-script-triggered-by-a-joystick-input

        RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

        whsiungW adamspcA 2 Replies Last reply Reply Quote 0
        • whsiungW
          whsiung
          last edited by

          If you can work with some simple electronics, google "raspberry power switch". Should give you plenty of ideas.

          Top of my to do list :)

          WH

          1 Reply Last reply Reply Quote 0
          • whsiungW
            whsiung @mediamogul
            last edited by

            @mediamogul said in Shutdown with keypress:

            You should find some helpful info here...
            https://unix.stackexchange.com/questions/107818/how-can-you-run-a-script-triggered-by-a-joystick-input

            I never thought of that, I made an arcade controller a while back... there is an unused button. I was thinking of how I'm going to utilise that extra button, now seem to find a really good candidate :)

            WH

            glennlakeG mediamogulM 2 Replies Last reply Reply Quote 0
            • glennlakeG
              glennlake @whsiung
              last edited by

              @whsiung Check out this link."https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b" It should be all you need.

              1 Reply Last reply Reply Quote 1
              • mediamogulM
                mediamogul Global Moderator @whsiung
                last edited by

                @whsiung said in Shutdown with keypress:

                I'm going to utilise that extra button

                It's a great trick. Since I'm using a controller without a dedicated button for this function, I modified it a bit to have a combination of presses shut down the pi. I've been very pleased with the results. Of course nothing beats a hardwired power switch when it comes to turning it back on.

                RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                1 Reply Last reply Reply Quote 0
                • adamspcA
                  adamspc @mediamogul
                  last edited by

                  @mediamogul

                  That's not exactly what I was hoping for, but it might work for me. My goal was to limit the amount of addons and software running in the background. I'm already running Retrogame to convert GPIO buttons to keyboard keys, and that uses a small amount of CPU power. I'm attempting to make this as lean as possible to limit CPU overhead and the possibility of software glitches. My hope was that this ability was built into the RetroPie suite.

                  Do you know whether the script uses much CPU power to run in the background?

                  I'm about 95% complete with a Pi Zero handheld console project that I'm sure everyone will love, and I am very anxious to complete it and show it off.

                  Also, I'll give a little background on why I need this button. I've made a dual-mosfet power circuit that draws no power from the batteries when the Pi is off, and power is turned on with a momentary pushbutton. When the Pi is shut down (by going to shutdown system in the start options) the power to the Pi/LCD/Audio is completely killed after the OS shutdown completes. It can then be powered on again by pushing the button again. I want to be able to push the button while the OS is running and have the Poweroff command run (the wiring is already done, and it is software I need). I also have a warning light set to come on when the battery is low, and this same circuit can ground out the same GPIO pin that's wired to the power switch and cause Retrogame to issue a keypress, which will shut down the console safely before the battery dies.

                  https://www.othermod.com

                  mediamogulM 1 Reply Last reply Reply Quote 0
                  • mediamogulM
                    mediamogul Global Moderator @adamspc
                    last edited by mediamogul

                    @adamspc said in Shutdown with keypress:

                    Do you know whether the script uses much CPU power to run in the background?

                    Any software solution to something like this is going to take the tiniest amount off the CPU, but it's negligible. I tend to doubt there would be a game that even saw a drop in frame rate here, but I guess there's always that possibility. For your purposes, a hardware solution may be the best answer.

                    RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                    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.