Blog Home Dudermang

pi touch screen

by Corey Faulkerson

Posted on 2016-12-29 23:59:11



Hi,

Following instructions will save tons of time for Raspberry Pi3 users who had purchased
display like 5 Inch Touch Display from Waveshare which uses XPT2046 driver chip.

0) In OS Jessie NO DRIVER REQUIRED! for XPT2046 or ADS7846 Touchscreen. Do not install original driver from Waveshare or any other driver announced as compatible. You will kill your Jessie for sure. At least Waveshare driver totally disables WiFi module functionality!!!

1 ) sudo nano /boot/config.txt
add
Code: Select all
dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=ads7846,penirq=25,speed=10000,penirq_pull=2,xohms=150


2) sudo nano /etc/modules
add
Code: Select all
ads7846_device model=7846 cs=1 gpio_pendown=25 speed=1000000 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=150 x_min=184 x_max=3869 y_min=141 y_max=3959

NOTE: This will start the internal touch driver with calibration parameters same as xinput calibrate utility gives. However, X axis will be inverted.
Values In config string x_min=184 x_max=3869 y_min=141 y_max=3959
are the same that xinput config string
Code: Select all
Option  "Calibration"   "3869 184 141 3959"
creates

3) Now fixing inverted X axis. Get evtest for screen touch axis management
sudo apt-get install -y libts-bin evtest xinput python-dev python-pip
sudo pip install evdev

4) Create axis inversion script in your /home and add this script into autostart
Edit Autostart for Wheesy sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Edit Autostart for Jessie sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
Add string
Code: Select all
@sh /home/pi/rotate.sh

Run command
sudo nano /home/pi/rotate.sh
Add following into to newly created file
Code: Select all
#!/bin/bash
#Copyright for this script belongs to Raspberry Pi community
#script to set correct touchscreen orientation after x start
#this won't rotate the displayed image, only the touchscreen input
#to rotate the displayed image add the following to /boot/config.txt
#"display_rotate=1" to rotate display 90 degrees
#"display_rotate=3" to rotate display 270 degrees
#DISPLAY=:0 xinput set-prop 'ADS7846 Touchscreen' 'Evdev Axes Swap' 1
#Uncomment this for 90 rotation
#xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1
#Uncomment this for 270 rotation
DISPLAY=:0  xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 1 0


5) REBOOT aaaaand have fun!!!!!!
Back

Keywords

pi, raspberry, touch, screen,