Snafu Code Logo
HOME LEARN PROJECTS ABOUT

Using the Adafruit PiTFT 2.8 Touch Screen

Adding a touch screen hat(Hardware Attached on Top) to your Raspberry Pi is a great way to expand your Pi's capability, making it more mobile and allows you to easily see data output, such as a command line interface or even a full blown desktop GUI without the need for a computer monitor or external screen. However, one common problem with these screens seems to be the touch feature gets inverted or flipped. For example, when you touch the left side of the screen, it registers as a touch on the right side, or dragging left makes it go up. Very annoying! The reason for this is usually caused by different hardware and software configurations being used. For example, the Raspberry Pi OS is regularly being updated, updates are necessary but they can also cause problems for supporting older hardware. Also, depending on which model Raspberry Pi you have, such as a 2, 3 or 4 will make a difference.
For this project I am using the latest version (at time of writing) of the Raspberry Pi OS, and the Adafruit PiTFT Plus 320x240 2.8" TFT + Capacitive Touchscreen.

Getting Started

Adafruit has a very good tutorial for installing and setting up their screens, including instructions of how to rotate it. But even after following their tutorial and calibrating my screen I still had issues with the touch. In my case, the display was correct, but when I touched the right side of the screen, it would register as a click on the left. So how do we fix this?
First follow the Adafruit instructions and make sure you have to correct rotation. In my case it was 90 degrees. To change your rotation just run the adafruit-pitft.py script. It will give 4 different options for rotation, 90, 180, 270, and 0. If you have the correct the rotation(or at least the one you want) and the touch is still not right, move onto the options below.

Option 1

You could try and install the latest tested version of Raspberry Pi OS that Adafruit has tested, which currently is the May 28, 2021 release from here.

Raspberry Pi Os Release
This may be fine for some projects, but keep in mind that you will need to re-flash your sd card, and will loose anything that you have downloaded or installed previously. I decided to skip this and go to option 2.

Option 2

Edit the /boot/config file. This was the easiest fix for me, although I can't guarantee it will work I think it's worth trying.
First open a terminal and cd to the /boot directory.

(snafu@raspi)-$ cd /boot

Here you'll notice a file called config.txt. We are going to edit that file.

cd to /boot
(snafu@raspi)-$ sudo vim config.txt

sudo vim config.txt
You'll need to use sudo to edit this file if you aren't logged in as root. I am using Vim to edit this file but you can of course use nano or gedit. Once you open up the file scroll to the bottom and you should see a block of code from Adafruit. What we are looking for here is the "touch-swapxy=", and "touch-invx=". You can change these values to either equal true or false. In my case they were both set to true, so I set them both to false. To start, you can try just changing one value to either true or false and see what happens.

Edit adafruit code
Once you make your changes save the file. If you are using Vim hit the Esc key, than type a colon(:) and then type wq and hit enter. This will save and close the file. To see these changes take effect you'll need to reboot. Hopefully once it restarts it will be fixed! If it's still not right you can try to change the values in the config.txt file again. Also note that there is an option to change the rotation in the file, if you need to adjust that.

Hopefully this will fix your problem! Good luck.