mastermushi
Posts: 37
Joined: Thu Apr 07, 2016 8:47 am

XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Apr 07, 2016 6:12 pm

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.
Tested with 5 Inch 800x480 and 4 inch IPS 800x480 displays.


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) Create directory /etc/X11/xorg.conf.d and file 99-calibration.conf in that directory
Add the following into the file

Code: Select all

Section "InputClass"
        Identifier "calibration"
        MatchProduct "ADS7846 Touchscreen"
        Option "Calibration" "3853 170 288 3796"
        Option "SwapAxes" "1"
EndSection
3) REBOOT aaaaand, have fun!!!!!!

AAAAAND that is basically it!! I have moved the rest of old instructions to comment cause they are not needed any more

FAQ:

What else do i need?
Just to maintain the testing and supportability, I recommend you to perform the following installations:
sudo apt-get update
sudo apt-get install -y libts-bin evtest xinput python-dev python-pip
sudo pip install evdev
sudo apt-get install -y xinput-calibrator

After those installations you will be able to test touch and other controllers and calibrate screen.

What on screen keyboard for Raspberry Pi do you recommend?
As the onscreen keyboard I use xvkbd cause it is resizable and can be tuned
sudo apt-get install -y xvkbd

I did all instructions but touch does not work and reacts strangely. What can be the reason?
Please take a look at this thread: viewtopic.php?f=44&t=173993&p=1112311#p1112311

Can I have some screensavers and screen blanking controll?
yes you can
sudo apt-get install -y xscreensaver xscreensaver-data-extra xscreensaver-gl-extra
However, some screensavers may be buggy at RPI. And GL ones eat current so do not use them in battery operation mode.

What current are we talking about? How much will my Raspberry Pi drain from the battery?
RPI [email protected]+ Screen with backlight 650mA - 2.1A (>0.88A with GLMatrix full screen)
RPI [email protected] + Screen with backlight 650mA - 2.9A (>1A with GLMatrix full screen)
Last edited by mastermushi on Fri Feb 10, 2017 9:29 pm, edited 5 times in total.

dallas84
Posts: 1
Joined: Tue Jan 03, 2017 3:52 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Jan 03, 2017 3:58 am

This worked great for me. I have one issue though. The middle of the screen is calibrated perfectly, but the closer I get to the edges of the screen, the more the pointer is off. I turned off overscan and resolution is set to 800 x 480. Any help would be great.

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Fri Jan 06, 2017 4:59 pm

Hi,

I don't have this screen with SPI touch on XPTxxxx. But I wonder why you invert axis, why not just run calibration tool and then use those calibration values this take into account inversion too... Well, won't give you a ready recipe :D but you might be able to get better calibration, check this git repo: https://github.com/saper-2/rpi-5inch-hd ... een-driver , in description, you'll find how to run calibration from tslib and use it.

liderbug
Posts: 152
Joined: Sat Oct 08, 2011 4:47 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Sun Jan 08, 2017 5:44 pm

I have followed these instruction to the letter. I have the xpt2046 screen. Pi-3 and Jessie (update/upgrade)d. The screen lights up on power up but I can never get anything else - just a bright white screen [blank]. Suggestions???
Thanks

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Sun Jan 08, 2017 5:55 pm

liderbug wrote:I have followed these instruction to the letter. I have the xpt2046 screen. Pi-3 and Jessie (update/upgrade)d. The screen lights up on power up but I can never get anything else - just a bright white screen [blank]. Suggestions???
Thanks
What screen (waveshare/clone/etc., symbol, maybe where you bought it, photos will be helpful too)?

White screen mean, that Pi didn't recognized your display and/or it's settings. There is on forum a post/topic how to find out those (you can do it via SSH). I would first, connect the display to computer to see if it's detected at all (e.g. my waveshare clone is recognized by Windows when I connect it to my laptop via HDMI).
I think you have to force HDMI mode and "hard code" it's HDMI settings to Pi, but first give info what you have (photos will be helpful too - upload them to photo service or upload them to One- or Google drive).

abagos
Posts: 1
Joined: Wed Jan 11, 2017 7:02 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Jan 17, 2017 7:45 am

Hello,
I am using a 3.4 inch XPT2046 display using the dtoverlay=piscreen. The display works as well as the touchscreen (recognized as /dev/input/event1) with inverted axis unfortunately.

Do I need the ads module in config.txt and modprobe, or can simply do with the script? The touch screen is reported as adsxxxx

Thank you,
Alex.

pavul
Posts: 13
Joined: Wed Jan 18, 2017 4:13 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Feb 02, 2017 3:42 pm

somebody knows if this lcd screens works with RPI ZERO?

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Feb 02, 2017 6:01 pm

Why not? If it works with Pi A+/B+ then with Pi0 should work too, only you'd have to figure out how to connect the HDMI signal from miniHDMI on Pi0 to display if you want this to be small (nothing sticking out too much). As for stacking, no problem, just solder headers into Pi0, and stack on pi0 the display, or extend it by short "dupont male to female" wires (this is how Chinese sellers call those header jumper wires) - you don't have to connect all 40 (or 26) pins, only those pins that are required by display (I believe power & spi signals).

roguejedi_x
Posts: 1
Joined: Sat Feb 04, 2017 3:49 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Sat Feb 04, 2017 3:52 am

I can guarantee 100% that this works with Pi Zero. I am using it and it is performing flawlessly.

jonaslorander
Posts: 19
Joined: Wed Oct 29, 2014 6:14 am
Contact: Website

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Feb 07, 2017 8:44 pm

I'm having the same issue as dallas84. the screen seems calibrated at centre, but the closer to the border I get the more out of calibration it gets. It looks like the area of the screen and touch is out of sync...

Anyone know what the problem might be?
I'm using a RPi3.

Regards,
Jonas

mastermushi
Posts: 37
Joined: Thu Apr 07, 2016 8:47 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Fri Feb 10, 2017 8:49 pm

OLD INSTRUCTIONS

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!!!!!!

liderbug
Posts: 152
Joined: Sat Oct 08, 2011 4:47 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Feb 21, 2017 4:12 am

saper_2 wrote:
liderbug wrote:I have followed these instruction to the letter. I have the xpt2046 screen. Pi-3 and Jessie (update/upgrade)d. The screen lights up on power up but I can never get anything else - just a bright white screen [blank]. Suggestions???
Thanks
What screen (waveshare/clone/etc., symbol, maybe where you bought it, photos will be helpful too)?

White screen mean, that Pi didn't recognized your display and/or it's settings. There is on forum a post/topic how to find out those (you can do it via SSH). I would first, connect the display to computer to see if it's detected at all (e.g. my waveshare clone is recognized by Windows when I connect it to my laptop via HDMI).
I think you have to force HDMI mode and "hard code" it's HDMI settings to Pi, but first give info what you have (photos will be helpful too - upload them to photo service or upload them to One- or Google drive).

OK, got the screen up - see posting below this one setting: dtoverlay=piscreen in /boot/config.txt [ note: there seem to be several lines in that file that are dupes or unused??? - but that's for another t&p ] So the screen comes up - looks good. cursor seems to be 90 or 270 out - to get to the top-right I have to stylus to the bottom-left etc. Google hasn't be any help. So I turn to you. Also how does one get a keyboard on the touchscreen - or will that solve when get the calibration done?
Thanks in advance.

mastermushi
Posts: 37
Joined: Thu Apr 07, 2016 8:47 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Feb 21, 2017 2:53 pm

liderbug wrote: OK, got the screen up - see posting below this one setting: dtoverlay=piscreen in /boot/config.txt [ note: there seem to be several lines in that file that are dupes or unused??? - but that's for another t&p ] So the screen comes up - looks good. cursor seems to be 90 or 270 out - to get to the top-right I have to stylus to the bottom-left etc. Google hasn't be any help. So I turn to you. Also how does one get a keyboard on the touchscreen - or will that solve when get the calibration done?
Thanks in advance.
First please install calibrator and perform the calibration process
sudo apt-get install -y xinput-calibrator
You will see the touch calibration which you have to put into file
/etc/X11/xorg.conf.d/99-calibration.conf

If the screen is still inverted then you need to play with the parameters string ( Option "Calibration" ) in that file/ For example you have something like

Code: Select all

Section "InputClass"
        Identifier "calibration"
        MatchProduct "ADS7846 Touchscreen"
        Option "Calibration" "3853 170 288 3796"
        Option "SwapAxes" "1"
EndSection
try to change it to

Code: Select all

Section "InputClass"
        Identifier "calibration"
        MatchProduct "ADS7846 Touchscreen"
        Option "Calibration" "170 3853 288 3796"
        Option "SwapAxes" "1"
EndSection
or put Swap Axes parameter to value 0

As for onscreen keyboard, I recommend to use XVKBD
sudo apt-get install -y xvkbd
Later, I will give you more instructions on how to make Show Keyboard button at the task bar.

liderbug
Posts: 152
Joined: Sat Oct 08, 2011 4:47 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Feb 21, 2017 7:16 pm

East is east and West is west and now my cursor doth follow my stylis.
Option "Calibration" "170 3853 3796 288"

and went with matchbox-keyboard

Why is the light at the end of the tunnel moving?

Thanks

fq1888
Posts: 10
Joined: Mon Mar 06, 2017 1:13 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Tue Mar 07, 2017 2:25 am

I have the same problem with you,and I have try all the ways,who can help!!!

DarkoSan
Posts: 4
Joined: Fri Mar 03, 2017 1:25 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Wed Mar 08, 2017 9:24 am

I've followed this guide for setup: viewtopic.php?t=175616

My setup is:
HW: Raspberry Pi 3 Model B
SW: Raspbian Jessie with Pixel March 2017 (Latest)

To rule out it is not a hardware issue I've tested with Raspbian image from kedei and it is working fine.

No matter what I've put in the
/etc/X11/xorg.conf.d/99-calibration.conf
or
/usr/share/X11/xorg.conf.d/99-calibration.conf
has no effect.

I've tried what's recoomended by this article: https://raspberrypi.stackexchange.com/q ... ation-conf

xinput list
\u23a1 Virtual core pointer id=2 [master pointer (3)]
\u239c \u21b3 Virtual core XTEST pointer id=4 [slave pointer (2)]
\u239c \u21b3 ADS7846 Touchscreen id=6 [slave pointer (2)]
\u23a3 Virtual core keyboard id=3 [master keyboard (2)]
\u21b3 Virtual core XTEST keyboard id=5 [slave keyboard (3)]

xinput list-props 6
Device 'ADS7846 Touchscreen':
Device Enabled (116): 1
Coordinate Transformation Matrix (117): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Calibration Matrix (246): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Calibration Matrix Default (247): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Send Events Modes Available (248): 1, 0
libinput Send Events Mode Enabled (249): 0, 0
libinput Send Events Mode Enabled Default (250): 0, 0
Device Node (251): "/dev/input/event1"
Device Product ID (252): 0, 0
libinput Horizontal Scroll Enabled (253): 0

But don't have the options for:
xinput set-prop 6 "Evdev Axis Calibration" <Min-X> <Max-X> <Min-Y> <Max-Y>
xinput set-prop 6 "Evdev Axes Swap" 1

Where could possibly these settings be set?

jonaslorander
Posts: 19
Joined: Wed Oct 29, 2014 6:14 am
Contact: Website

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Wed Mar 08, 2017 11:44 am

DarkoSan, what if you were to put the same SD-card in a RPi1 or RPi2? Can you see the parameters then? I'm thinking there could be something iffy with the overlays and device tree for the RPi3...


fq1888
Posts: 10
Joined: Mon Mar 06, 2017 1:13 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Wed Mar 15, 2017 8:52 am

Finally find a solution to the problem of reason, tested with Raspbian 2017-03-02 is Perfect,
The link is as follows:
https://github.com/goodtft/LCD-show

If you are using the newest Raspbian version: 2017-03-02
You need to additional excute this two command bellow after Step1, 2, 3 excuted.
If not so, the Resistive touch to reverse or always be calibrated.
This additional command bellow is just for Raspbian - 2017-03-02:

sudo apt-get install xserver-xorg-input-evdev
sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf
sudo reboot

DarkoSan
Posts: 4
Joined: Fri Mar 03, 2017 1:25 pm

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Wed Mar 15, 2017 10:31 pm

Jonaslorander thank you for pointing me in the right direction! Something is definitely iffy with the overlays. I didn’t have a RPi 1 or 2 at hand but did the following.

Red the [Review] KeDei 3.5" HDMI display with touch for Raspberry Pi over again. This time flashed the “2017-01-11-raspbian-jessie.img” and it works!
On all consequent builds it is not working.

Thank you GAMELASTER for the advice but found a workaround.

fq1888 I’ll check the LCD-show

fiveseven808
Posts: 10
Joined: Fri Mar 03, 2017 1:56 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Mar 16, 2017 7:41 am

Posting to subscribe to this lol.

I have a 5" waveshare clone and while the instructions got my display's input to work, it's not calibrated and I can't get it to seem to calibrate using the instructions for xinput-calibrator... I replaced the stuff in the .conf file, but the touch screen is just as off (calibrated near the center, but doesn't touch the edges)

Other than that, I love that you can do this without sketchy chinese drivers!
Need to get a "headless" pi up and running with a hardware input/output and minimal effort? Check out the hueBerry project here!
https://github.com/fiveseven808/HueBerry_SmartSwitch

The (soon-to-be) extensible home automation controller platform!

jonaslorander
Posts: 19
Joined: Wed Oct 29, 2014 6:14 am
Contact: Website

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Mar 16, 2017 7:52 am

fiveseven808,

I hade the same problem until yesterday. fq1888's pro tip worked for me! I didn't even have to recalibrate.
You can see my thread about this topic here: viewtopic.php?f=44&t=173993

Regards,
Jonas

alexbleite
Posts: 3
Joined: Thu Mar 23, 2017 2:20 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Mar 23, 2017 2:49 am

hi,
I need to do project that I will work with two 3.5 displays in the same raspberry.
Can anyone help me? Is it possible work?
Thanks a lot
Alexandre

fiveseven808
Posts: 10
Joined: Fri Mar 03, 2017 1:56 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Mar 23, 2017 5:07 pm

alexbleite wrote:hi,
I need to do project that I will work with two 3.5 displays in the same raspberry.
Can anyone help me? Is it possible work?
Thanks a lot
Alexandre
Hi Alexandre, I believe this is the wrong place to post your question, but to answer it quickly:

Yes I believe you can have two 3.5" displays, but it all depends on what you plan to do with it. If you want to run Raspbian desktop and have an "extended" desktop? I'm not 100% sure this is possible.

One display will have to be via HDMI (aliexpress has 3.5" HDMI displays now), and the other display will have to be SPI
Need to get a "headless" pi up and running with a hardware input/output and minimal effort? Check out the hueBerry project here!
https://github.com/fiveseven808/HueBerry_SmartSwitch

The (soon-to-be) extensible home automation controller platform!

alexbleite
Posts: 3
Joined: Thu Mar 23, 2017 2:20 am

Re: XPT2046 Touch Screen instructions for Raspbery Pi 3

Thu Mar 23, 2017 6:34 pm

fiveseven808 wrote:
alexbleite wrote:hi,
I need to do project that I will work with two 3.5 displays in the same raspberry.
Can anyone help me? Is it possible work?
Thanks a lot
Alexandre
Hi Alexandre, I believe this is the wrong place to post your question, but to answer it quickly:

Yes I believe you can have two 3.5" displays, but it all depends on what you plan to do with it. If you want to run Raspbian desktop and have an "extended" desktop? I'm not 100% sure this is possible.

One display will have to be via HDMI (aliexpress has 3.5" HDMI displays now), and the other display will have to be SPI
ok, let me reformulate. I want to run two 3.5 displays via spi. Could you help me? I made a post explaining. thank you

viewtopic.php?f=44&t=178273&e=0

Return to “Interfacing (DSI, CSI, I2C, etc.)”