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 Button

    Scheduled Pinned Locked Moved Help and Support
    shutdown script
    6 Posts 2 Posters 1.5k 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.
    • M
      matalog
      last edited by

      Hi Guys,

      I installed this a shutdown script on my Pi 3b with latest retropie, and I then tried to amend the script that it uses, to make it require 3 seconds hold on the button to shut the computer down and immediate press, do nothing.

      It seemed that if I changed the script more than 'shutdown -h' to shutdown -r' then the changes would not work.

      I tried adding an IF statement earlier in the script that wouldn't really do anything, and then the whole script stopped working.

      Does anyone know why this script seems to become inactive when edited? Or a way to edit it so that the button is required to be held for 3 seconds before the Pi shuts down.

      Thansk for any help,

      matalog

      1 Reply Last reply Reply Quote 0
      • M
        matalog
        last edited by matalog

        pie. 8bitjunkie. net/ retropie-shutdown-and- startup-switch-the-easy-way (remove spaces to see link)

        This is the script - I want to link to the web page with the install instructions, but it won't let me post a link.

        “#!/usr/bin/python
        import RPi.GPIO as GPIO
        import time
        import subprocess

        GPIO.setmode(GPIO.BOARD)

        we will use the pin numbering to match the pins on the Pi, instead of the

        GPIO pin outs (makes it easier to keep track of things)

        use the same pin that is used for the reset button (one button to rule them all!)

        GPIO.setup(5, GPIO.IN)

        oldButtonState1 = True

        while True:
        #grab the current button state
        buttonState1 = GPIO.input(5)

        # check to see if button has been pushed
        if buttonState1 != oldButtonState1 and buttonState1 == False:
            # shutdown
            subprocess.call("shutdown -h now", shell=True,
              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            oldButtonState1 = buttonState1
        
        time.sleep(.5)”
        
        1 Reply Last reply Reply Quote 0
        • M
          matalog
          last edited by

          Any ideas that may help with this?

          Thanks again,

          matalog

          1 Reply Last reply Reply Quote 0
          • cyperghostC
            cyperghost
            last edited by

            @matalog to avoid future issues take part here and say "Hello" to @meleu
            For you coding issues.... post output of ps -acommand. Is there is a python process listed?

            M 1 Reply Last reply Reply Quote 0
            • M
              matalog @cyperghost
              last edited by

              @cyperghost

              As I was saying I was trying to amend a script to require a 3 second hold of a button instead of shutting down upon immediate press, but every time I changed the script then it seemed to not run at all.

              This works fine, and it even works if i add a comment or if I change shutdown -h to shutdown -r
              This will shut down when I hold pin 5 to GND.

              #!/usr/bin/python
              import RPi.GPIO as GPIO
              import time
              import subprocess
              
              GPIO.setmode(GPIO.BOARD)
              
              # we will use the pin numbering to match the pins on the Pi, instead of the
              # GPIO pin outs (makes it easier to keep track of things)
              # use the same pin that is used for the reset button (one button to rule them all!)
              GPIO.setup(5, GPIO.IN)
              
              oldButtonState1 = True
              
              while True:
                  #grab the current button state
                  buttonState1 = GPIO.input(5)
              
                  # check to see if button has been pushed
                  if buttonState1 != oldButtonState1 and buttonState1 == False:
                      # shutdown
                      subprocess.call("shutdown -h now", shell=True,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                      oldButtonState1 = buttonState1
              
                  time.sleep(.5)
              

              If I change any more than that, it will not work, for example, I made this to test if a changed method would work,
              This does nothing when i hold pin 5 to GND.

              #!/usr/bin/python
              import RPi.GPIO as GPIO
              import time
              import subprocess
              
              GPIO.setmode(GPIO.BOARD)
              
              # we will use the pin numbering to match the pins on the Pi, instead of the
              # GPIO pin outs (makes it easier to keep track of things)
              # use the same pin that is used for the reset button (one button to rule them all!)
              GPIO.setup(5, GPIO.IN)
              
              oldButtonState1 = True
              
              	if oldButtonState1 == 2:
              		oldButtonState1 == 3
              
              		
              while True:
                  #grab the current button state
                  buttonState1 = GPIO.input(5)
              
                  # check to see if button has been pushed
                  if buttonState1 != oldButtonState1 and buttonState1 == False:
                      # shutdown
                      subprocess.call("shutdown -h now", shell=True,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                      oldButtonState1 = buttonState1
              
                  time.sleep(.5)
              

              That does not work.

              Any ideas on why changing the installed script too much, would stop it from running?

              matalog.

              1 Reply Last reply Reply Quote 0
              • cyperghostC
                cyperghost
                last edited by

                @matalog I'm not very firm in python.
                But take a look to this link
                https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetup.sh

                and to this link
                https://lowpowerlab.com/guide/atxraspi/assembly-install/

                shows how to use a timer to differ button event between shutdown and reboot in accordance of button press time. I think that is your demand....

                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.