PiTFT product page: https://www.adafruit.com/products/2423
Case product page: https://www.adafruit.com/products/2807
What I'm trying to accomplish is simple, I've been doing quite a bit of reading online though, and everyone seems to do it differently. I simply want to program the buttons as follows:
See here (https://goo.gl/wfypur) for the GPIO numbers referenced below.
#27 - [call this Button 1] - start X session on PiTFT
#23 - [Button 2] - return to terminal session on PiTFT
#22 - [Button 3] - shutdown
#17 - [Button 4] - reboot
I have been reading that you need to be careful in programming the GPIO ports so as not to damage the Pi itself or corrupt your SD card.
After some messing around, I've ended up with the following, but it doesn't seem to work correctly (and it's only for one button...as far as I've made it). I'm only able to push the button and have it start X if I do so within a few seconds of executing the command. It starts X automatically if I run it at startup.
Code: Select all
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(27,GPIO.IN)
if GPIO.input(27):
print('Button not pushed!')
else:
subprocess.call("FRAMEBUFFER=/dev/fb1 startx", shell=True)
while GPIO.input(27) == GPIO.LOW:
time.sleep(0.01) # wait 10 ms to give CPU chance to do other things
GPIO.cleanup()