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.
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.
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.
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.
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
(snafu@raspi)-$ sudo vim config.txt