5 inch XPT2046 touch LCD

hdmi_cvt 800 480 60 6 0 0 0

Getting the touch screen working on Raspbian 7 is pretty easy, as well. Windows 10 IoT doesn’t currently have a driver (stay tuned here, I may be writing one if time allows).
Just add the below additional lines to the configuration file (in /boot/config.txt when Raspbian is running):


This tells the Linux kernel (at least as of version 4.1 and later), to use the ads7846 driver over the SPI bus to read touch screen coordinates. The penirq=25 line tells the driver to use GPIO pin 25 as the interrupt for a touch screen event. The penirq_pull=2 tells the driver to turn the pullup resistor on for the SPI bus, and xohms=150 tells the driver to use a baseline of 150 ohms (not the default 400) as the resistance for the resistive touch screen input. It’s also important to note that the default speed is way too fast for the XPT2046 chip (around 2 MHz, it can handle 1MHz on a good day), so we set it to 10000 (1 MHz).

The next part will require a small amount of ingenuity on your part. You’ll need to get the file “5inch_HDMI_LCD.tar.gz” from somewhere. If you search with Google, you should be able to find it easily enough. With this file, you can extract the archive file “xinput-calibrator_0.7.5-1_armhf.deb”. Install it with “dpkg -i xinput-calibrator_0.7.5-1_armhf.deb“.
This installs the graphical touch screen calibration tool for the 5″ LCD. Since we want to provide at least a baseline calibration, we add a directory at /etc/X11/xorg.conf.d and create a file named 99-calibration in that directory.

The contents (as an example) would be:

Section “InputClass”
    Identifier    “calibration”
    MatchProduct    “ADS7846 Touchscreen”
    Option    “Calibration”    “129 3955 191 3946”

If you want to calibrate your display manually, you can simply log into the Raspberry Pi 2 on the console and issue the normal startx command. Then SSH into the Raspberry Pi 2, and run the command “DISPLAY=:0 xinput_calibrator”. You should get a screen that tells you to press the stylus to the crosshair. Once you’ve hit all four crosshairs, you are presented with a chunk of text that looks strikingly like the above 99-calibration file contents. Replace the /etc/X11/xorg.conf.d/99-calibration file’s

contents with the output of the xinput_calibrator command and you should be in good shape.