Displaying buttons on the TFT

Having successfully hooked my small TFT up to the Raspberry Pi, I now wanted to use it! As it was a touch screen version what I wanted was buttons.

This is the end result;

TFT initial state

TFT display updated after a button press

The code is to be found in this gist:

A few comments on the false starts and things I learned (code is well commented I think):

  • I tried to install pygameUI but this failed because of the way I had implemented the TFT itself.
  • pygame is structured in a way I was unfamiliar with (fairly new to python). Key concepts are:
    • The screen (the area you update)
    • Rect – an object that defines a rectangular area of the screen.  I created an array of Rect objects then gave each a centre.  Once defined they will always display at that location unless you change it.
    • You output various layers then update the display.
    • Updating the display is best done on the rects that have changed although in this case, frame rate is not an issue.
    • I used centres as I found that trying to create a border using a top left reference did not result in a constant thickness of the border all round.

I now need to find a way to mount the TFT permanently.  I also really would like an enclosure – I’m going to hunt down a 3D one or pay a visit to my local hacklab.

I also need to expand my code to pull instructions off and send instructions to the main IOT server I have to control the heating.



Facebooktwitterby feather
This entry was posted in Coding and Programming, Python and tagged , , . Bookmark the permalink.

Leave a Reply