3.5" TFT with RaspberryPi

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", \
ENV{LIBINPUT_CALIBRATION_MATRIX}="1 0 0 0 -1 1 0 0 1"

CALIBRATION
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.

IMPORTANT NOTE
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.

6 Likes