Categories
Linux Raspberry Pi

Raspberry PI 2 / 3 with 5″ touchscreen LCD

I managed to get a cheap 5″ LCD HDMI touchscreen from Ebay for my 80’s game emulator. This is an 800×480 panel using an XPT2046 to provide the resistive touch screen, a similar one can be bought here: Raspberry Pi 2 HDMI LCD Screen

A lot of the information on the Internet made it look like getting this screen working with the RPi was going to be a bit of a chore, but I found that out of the box Raspbian Jessie seems to work well with only a few configuration changes.

This screen attaches to the RPi2/3 via a clever 180 degree HDMI connector, and also via the GPIO so it is quite a secure fit. Metal standoffs are also included to keep the LCD and Raspberry Pi safe from harm. You can plug the power either into the power socket on the panel, or the RPI. Powering both screen and RPi from a 2a charger, and a battery pack meant for phone recharging rated at 5200 mAh, 3.7v with 2.1a output worked well.

The RPi is probably set to output video at 640×480, so setting the following in /boot/config.txt forces the 800×480 output:
# Force 800×480 for 5″ lcd display
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt=800 480 60 6 0 0 0

The touchscreen didn’t work out of the box either, but adding the following to /boot/config.txt did the trick:
dtparam=spi=on
dtoverlay=ads7846,penirq=25,speed=10000,penirq_pull=2,xohms=150

That got the touchscreen working, but it wasn’t calibrated and there is no right click. The following fixed this:
wget http://github.com/downloads/tias/xinput_calibrator/xinput_calibrator-0.7.5.tar.gz
tar -xvf xinput_calibrator-0.7.5.tar.gz
cd xinput_calibrator-0.7.5.tar.gz
sudo apt-get install libx11-dev libxext-dev libxi-dev x11proto-input-dev
./configure
make
sudo make install

Run the calibration from the Application | System menu, locate all 4 corners and it will output some data, copy the data (starting Section) into the file below. This also includes code to emulate right click with a long press:
su
cat >/usr/share/X11/xorg.conf.d/01-input.conf
Section “InputClass”
Identifier “calibration”
MatchProduct “ADS7846 Touchscreen”
Option “Calibration” “141 4009 196 3966”
Option “EmulateThirdButton” “1”
Option “EmulateThirdButtonTimeout” “750”
Option “EmulateThirdButtonMoveThreshold” “30”
EndSection