melvin0015
Posts: 2
Joined: Tue Apr 29, 2014 7:54 am

PiTFT + Tactile Buttons

Tue Apr 29, 2014 8:13 am

Hello, i just got my PiTFT from Adafruit working but now i want to know how i can use the buttons.

I would like to have a script that boots up at startup and it shuts down when the pi shuts down.
I got the first button working using this tutorial:

https://learn.adafruit.com/adafruit-pit ... -pi/extras
This tutorial makes a power switch.

The second button which is GPIO #22 i want to act as an script shutdown. (CTRL + C)

Can anyone tell me how i can make a script that does that?

(Sorry if my English is bad, i'm Dutch)

Thankyou


User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: PiTFT + Tactile Buttons

Tue Apr 29, 2014 4:11 pm

The PiTFT buttons are wired to ground, I believe, so your script can simply test GPIO #22 and when it goes low, throw a KeyboardInterrupt exception (or terminate more gracefully).

If you want to simulate a Ctrl-C keypress for ANY running script, that's different, I have no idea if that's even possible.

melvin0015
Posts: 2
Joined: Tue Apr 29, 2014 7:54 am

Re: PiTFT + Tactile Buttons

Tue Apr 29, 2014 4:14 pm

I found out that CTRL + C = pkill -SIGINT -f servicename

But now i only need to find out to run it when i hit the button.

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: PiTFT + Tactile Buttons

Tue Apr 29, 2014 4:35 pm

Yup, that should work for a specific 'servicename'. So you'll want a script continually running that simply loops, checking GPIO #22 and when it's low, executes that command (and sleeps each time around to be nice and not use all the CPU cycles). Look for any tutorial on reading buttons on the Pi. Then you can get fancy and daemonize that script if you like.

Return to “Advanced users”