Advertisement
Androxilogin

RetroPi On/Off Switch

May 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. apt-get with the following command :
  2.  
  3.  
  4. 1. sudo apt-get install update
  5.  
  6. 2. sudo apt-get install python-dev
  7.  
  8. 3. sudo apt-get install python3-dev
  9.  
  10. 4. sudo apt-get install gcc
  11.  
  12. 5. sudo apt-get install python-pip
  13.  
  14. Next you need to get RPi.GPIO:
  15.  
  16. 6. wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz
  17.  
  18.  
  19. Uncompress the packages:
  20.  
  21. 7. sudo tar -zxvf RPi.GPIO-0.5.11.tar.gz
  22.  
  23.  
  24.  
  25. move into the newly created directory:
  26.  
  27. 8. cd RPi.GPIO-0.5.11
  28.  
  29.  
  30. install the module by doing:
  31.  
  32. 9. sudo python setup.py install
  33.  
  34. 10. sudo python3 setup.py install
  35.  
  36.  
  37. creating a directory to hold your scripts:
  38.  
  39. 11. mkdir /home/pi/scripts
  40.  
  41. call our script shutdown.py (it is written in python). Create and edit the script by doing:
  42.  
  43.  
  44. 12. sudo nano /home/pi/scripts/shutdown.py
  45.  
  46.  
  47. The content of the script: Paste it in the blank area
  48.  
  49. #!/usr/bin/python
  50. import RPi.GPIO as GPIO
  51. import time
  52. import subprocess
  53.  
  54. # we will use the pin numbering to match the pins on the Pi, instead of the
  55. # GPIO pin outs (makes it easier to keep track of things)
  56.  
  57. GPIO.setmode(GPIO.BOARD)
  58.  
  59. # use the same pin that is used for the reset button (one button to rule them all!)
  60. GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  61.  
  62. oldButtonState1 = True
  63.  
  64. while True:
  65. #grab the current button state
  66. buttonState1 = GPIO.input(5)
  67.  
  68. # check to see if button has been pushed
  69. if buttonState1 != oldButtonState1 and buttonState1 == False:
  70. subprocess.call("shutdown -h now", shell=True,
  71. stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  72. oldButtonState1 = buttonState1
  73.  
  74. time.sleep(.1)
  75.  
  76.  
  77. Press CRTL X Then Y
  78.  
  79.  
  80.  
  81. Restart the pi
  82.  
  83. 13. sudo reboot
  84.  
  85. configure our script to run at startup,
  86.  
  87. 14. sudo nano /etc/rc.local
  88.  
  89.  
  90. Add the following to the file
  91.  
  92. sudo python /home/pi/scripts/shutdown.py &
  93.  
  94. Press CRTL X Then Y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement