3.5" TFT with RaspberryPi


I have a 3.5-inch TFT connected to a RaspberryPi and running the WPE browser project. The web pages comes up fine, but I cannot get the touchscreen input to be rotated / reflected correctly. The model of the display is a XPT2046 and it connected directly to the 40-pin header, much like others I have seen and also the one shown in the WPE ReadMe.

I have the following parameter set:

RESIN_HOST_CONFIG_dtoverlay = "piscreen,speed=24000000,rotate=270"

This rotates the screen, but the touchscreen is upside down and reflected in terms of input.

There are a number of suggestions on this forum and also Google about how to do this, but the ‘piscreen’ dt_overlay does not have anything to do with the touchscreen reflection. I do not want to have to make changes to the hostOS, which should be possible with the latest images.

Does anyone have any suggestions on how to fix this (such as the Udev in the WPE project or somehow changing the reported co-ordinates within WPE itself)?

Even if I have no rotation, the touchscreen and the display are not aligned in terms of orientation.


Cannot get pi-hole running on balena cloud - not being able to access public url

After a bit of digging about and running dmesg on the hostOS, it appears the resistive touchscreen driver is of a type “ADS7846 Touchscreen”.

So, I created a new udev rule called 99-touch.rules and have the following (on one line):

ACTION=="add|change", KERNEL=="event[0-9]*", \
ATTRS{name}=="ADS7846 Touchscreen", \

The matrix shown above will rotate the touchscreen and it works pretty well. However, if you have a UI that requires some accuracy, then you may wish to change the settings for your specific hardware / screen. Working out what you need is not simple and even through there are utilities (such as ts_calibrate) these are not used by WPE.
My settings turned out to be 1.15 0 -0.075 0 -1.16 1.08 0 0 1 and I worked this out using a fab tool here.

This rotates the touchscreen to align with the rotation of the LCD and it all works perfectly.

In short, there is very little you need to do to get WPE working on a RaspberryPi with one of these sub $20 screens. OK, it’s resistive, but it is also a full WebKit browser for small user interfaces which can make a lot of difference.

The following configuration is required for the fleet or device:

RESIN_HOST_CONFIG_dtoverlay = "piscreen,speed=24000000,rotate=270"
RESIN_HOST_CONFIG_gpu_mem_256 = 128
RESIN_HOST_CONFIG_hdmi_cvt = 480 320 60 1 0 0 0
RESIN_HOST_CONFIG_hdmi_force_hotplug = 1
RESIN_HOST_CONFIG_hdmi_group = 2
RESIN_HOST_CONFIG_hdmi_mode = 87

The beauty is that no changes are required on the hostOS at all, which is great. The driver is already installed on the latest hostOS images, so the dt_overlay simply enables it. The new udev rule then rotates the screen.

Why 270 degrees? Well this places the USB power at the top of the device, which means it’s easier to have on the desk! I think the touchscreen rules are required for whatever orientation you have the display to get them all aligned.

Find out more on the rotation options on this thread and also here.

For those interested, the TFT can be found on Amazon, with or without a rather useless case!

I hope this helps someone.

It appears that if you restart the WPE container (such as a balena push), then the touchscreen might rotate again and be out of sync. A hostOS reboot fixes this, but I might look into how the re-applying the transformation can be prevented.



@branchespark thanks for sharing your findings!



I have added a note about calibration, as the touchscreen can be a tiny bit off on the edges and some tweaking can help … a lot!