I'm running tv.giphy.com on my RPi, which shows random (or not) GIFs in full screen mode. I run the website in Cromium's kiosk mode. I have a PiTFT with 4 incorporated buttons and I would like to use one of these buttons to automatically save the image/GIF that I'm looking at on RPI's memory (SD card).

Could you help me/direct me to some documentation as to how to set up PiTFT's buttons? I can't seem to find anything relevant.

I just bought my first RPI less than 2 weeks ago and I'm a complete noob, but I'm getting really excited about all the possibilities :)

Thank you in advance.

  • What does the seller of the PiTFT say? – joan Mar 13 '19 at 20:54
  • And can you add a link to your screen? If it's a 'real' PiTFT (from Adafruit) then you can find the documentation in the device description and on the Adafruit learn pages. – Dirk Mar 13 '19 at 21:03
  • Of course, it's the Adafruit 2.2" LCD screen: learn.adafruit.com/… – Liviu.B Mar 14 '19 at 20:53

Assuming the buttons are connected to GPIO pins directly, just try creating Button objects on every pin and seeing which one's state changes when you press a button:

from gpiozero import ButtonBoard
from signal import pause

buttons = ButtonBoard(*range(2, 28))

for btn in buttons:
    btn.when_pressed = lambda b: print(b.pin)


(note this is Python 3 code)

Now press one of the buttons and you should see its pin number printed out e.g. GPIO2.

When you know which pin numbers to use, create Button objects on those pins, e.g:

from gpiozero import Button

btn_a = Button(2)
btn_b = Button(3)
btn_c = Button(4)
btn_d = Button(5)

There's a chance they're wired pull-down, and the pressed/released logic would be reversed, so you'd use Button(4, pull_up=False).

See the gpiozero Button documentation and recipes for more info.

  • Thanks for the very quick response. Being a complete novice, I assume from your message that I need to install the Python 3 GPIO package. I will have some spare time this weekend so I will let you know how it works. Thanks so much again. Btw, the buttons are indeed connected directly to the GPIO, this being the Adafruit 2.2" LCD display, with 4 buttons. I found a link explaining which GPIO's are connected to the buttons, but I couldn't figure out which button goes to which GPIO specifically, so will try to find out this weekend. – Liviu.B Mar 14 '19 at 20:48
  • This GPIO library is pre-installed in Raspbian desktop. If you don't have it, the installation instructions are here: gpiozero.readthedocs.io/en/stable/installing.html – ben_nuttall Mar 14 '19 at 23:41
  • Every time I try to run the following Python command: 'buttons = ButtonBoard(*range(2, 28))', it gives me the following error: Failed to add edge detection. What does that mean? I tried troubleshooting this using this script: github.com/RPi-Distro/python-gpiozero/issues/… , but get the same error. Could someone direct me to the right answer? Thanks again. – Liviu.B Mar 17 '19 at 11:48
  • BTW, I'm not using the GPIO pins for anything else but the PiTFT display – Liviu.B Mar 17 '19 at 11:54
  • Those comments were outdated, the RPi.GPIO update has been released. Just make sure you're full updated: sudo apt update; sudo apt dist-upgrade – ben_nuttall Mar 17 '19 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.