Advertisement
LongSteve

Pi Supply Soft Shutdown Script

Aug 20th, 2013
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Pi Supply Soft Shutdown Script
  2. # Version 1.2
  3. # Nathan Bookham 2013
  4. # Stephen Longhurst 2013
  5.  
  6. # Import the modules to send commands to the system and access GPIO pins
  7. from subprocess import call
  8. import RPi.GPIO as gpio
  9.  
  10. # Define variables to store the pin numbers
  11. soft_shutdown_pin = 16 # Default pin for Pi Supply is 7
  12. keep_powered_pin = 18 # Default pin for Pi Supply is 8
  13.  
  14. # Define a function to run when an interrupt is called
  15. def shutdown():
  16.     # Cleanup GPIO
  17.     gpio.cleanup()
  18.  
  19.     # Shutdown with halt and power off in 1 minute
  20.     call(['shutdown', '-hP','+1'], shell=False)
  21.  
  22. # Set pin numbering to board numbering
  23. gpio.setmode(gpio.BOARD)
  24.  
  25. # Setup the input Pin to wait on
  26. gpio.setup(soft_shutdown_pin, gpio.IN)
  27.  
  28. # Pin to pull high to keep the Pi Supply giving us power
  29. gpio.setup(keep_powered_pin, gpio.OUT, initial=gpio.HIGH)
  30.  
  31. # Run the shutdown function
  32. shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement