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

    Safe Shutdown Script

    Scheduled Pinned Locked Moved Help and Support
    pi4shutdown
    2 Posts 1 Posters 1.4k 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.
    • cnotoC
      cnoto
      last edited by cnoto

      I am having an issue with the shutdown script of a newly installed on/off button on my pi 4 on pins 5 and 6. The startup works fine, but the shutdown isn't working. Here are the contents of

      /home/pi/scripts/shutdown.py

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

      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)

      GPIO.setmode(GPIO.BOARD)

      use the same pin that is used for the reset button (one button to rule them a$

      GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)

      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:
        subprocess.call("shutdown -h now", shell=True, 
          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        oldButtonState1 = buttonState1
      
      time.sleep(.1)
      

      Anything look weird?

      1 Reply Last reply Reply Quote 0
      • cnotoC
        cnoto
        last edited by cnoto

        I ended up using @cyperghost 's script from [https://retropie.org.uk/forum/topic/17415/multi-switch-shutdown-script?_=1609290226722](link url)

        and now have things working.

        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.