I have a Raspberry Pi 2, and recently received an XPT2046 3.5" touchscreen for it. The instructions included were spotty at best, but basically boiled down to replacing my kernel and some other random files, crossing my fingers, and hoping for the best. This is not how I wanted to install it so I took to Google searching for answers.
I have mine installed on Raspbian Strech, 2017-11-29. This is a lot newer than what I was originally running on my Pi 2, and is in fact newer than the instructions I originally found. The good news is it works just fine.
Here's how I was able to get mine to work:
First things first, I installed vim, because really, if your text editor isn't complicated you're not doing it right. I also ran raspi-config
and enabled SSH and VNC access and rebooted.
We need to add some stuff to the end of /boot/config.txt
dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=piscreen,speed=16000000,rotate=90
Next we add the touchscreen calibration to our xorg.conf by creating 99-calibration.conf
:
$ sudo mkdir /etc/X11/xorg.conf.d
$ sudo vim /etc/X11/xorg.conf.d/99-calibration.conf
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "3853 170 288 3796"
Option "SwapAxes" "1"
EndSection
Now we need some software to make it all go, and to help us out later:
$ sudo apt update
$ sudo apt install libts-bin evtest xinput python-dev python-pip
$ sudo pip install evdev
$ sudo apt install xinput-calibrator
And if you want to prevent the screen from blanking automatically (assuming you've not installed any screensavers):
$ sudo vim vim /etc/lightdm/lightdm.conf
Find the heading
[Seat:*]
followed shortly by the line
#xserver-command=X
Change that line to
xserver-command=X -s 0 dpms
Ok, it's time to test it all out!
$ sudo reboot
You wont see anything on the screen until the GUI logs on, but once it does you should see a really cramped desktop. One issue I'm still having is that the X-axis is inverted on the touchscreen. Left is Right and Right is Left. I attempted to fix it in 99-calibration.conf
with the following:
Option "InvertX" "1"
But it doesn't seem to be taking effect. I've wasted hours troubleshooting, it's something I'll just have to come back to later. My project needs a display, not so much a touchscreen.
One last note, if you want to launch the calibration tool from SSH instead of the tiny touch screen, you'll need to specify the X display like so:
DISPLAY=:0 xinput_calibrator
Sources: