I have a Python script that runs at startup and looks for GPIO inputs (the buttons on my PiTFT screen). I can make the buttons do things like shut down the Pi (sudo shutdown now
), but I'm stumped as to how to make the buttons launch applications like lxterminal
or pithos
. Here's what I have for the script - can anyone suggest why the button for shutdown works but the buttons for launching apps doesn't? I have added a line in my /etc/rc.local
that starts the script at startup via sudo, if that helps....
#!/bin/python
# a simple script for using the tactile buttons on the TFT
import RPi.GPIO as GPIO
import time
import os
# Use Broadcom SOC Pin Numbers
# setup with internal pullups and pin in READ mode
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Main Loop
while 1:
if ( GPIO.input(22) == False ):
os.system("sudo pithos")
time.sleep(1)
elif ( GPIO.input(27) == False ):
os.system("sudo lxterminal --geometry=40x10")
time.sleep(1)
elif ( GPIO.input(18) == False ):
os.system("sudo shutdown -h now")
time.sleep(1)
sleep
before the python launch command. All my scripts in python use it. I think it should help – Shan-Desai Nov 19 '16 at 20:09