zappology
Posts: 2
Joined: Fri Mar 24, 2017 1:30 pm

3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Fri Mar 24, 2017 4:38 pm

Dear everybody,

after a "hard struggle" I found the solution for making a 3.5 touch screen, a XPT2046 Touch Controller, to work on Raspberry!
I read it's compatible with ADS7846, so I suppose it's the same procedure.

These guidelines are based on Raspbian, I don't know how much is the same for other operating systems.
My Raspberry is the Pi B+ model.

The touch screen should be connected to the Raspberry via GPIO.

This procedure is based on this:
http://ozzmaker.com/piscreen-driver-ins ... uctions-2/

Let's go!

Connect the touch screen to the Raspberry hardware through the GPIO and then switch your Raspberry on.
Use a HDMI with an external monitor, USB keyboard and mouse.
A Wi-Fi or cable internet connection is required.

First of all enable SPI by using the terminal command:
raspi-config
Navigate to 'Advanced options' and then enable both SPI and SSH.

Reboot if needed through the command in the terminal:
sudo reboot

The touch screen should turn on and be white colored.

Give the following commands for Raspbian updating:
sudo rpi-update
sudo reboot


Then after restart:
sudo apt-get update
sudo apt-get upgrade
sudo reboot


At this point let's set-up an ethernet connection for controlling remotely the RPi through a PC running Linux (or Windows).

In the terminal of RPi:
sudo nano /etc/network/interfaces
then comment the line
# iface eth0 inet dhcp
and add
iface eth0 inet static
address 10.42.0.10
netmask 255.255.255.0
gateway 10.42.0.1
broadcast 10.42.0.255

then give Ctrl+X, save and exit.

Give
sudo reboot

At the end of rebooting process check the parameters by giving:
ifconfig eth0
you should read the parameters just added in the interfaces file.

Now configure a new connection on the PC:
with graphical linux go to "Connections.." and add a new Ethernet connection.
Give the name 'Raspberry connection', go to IPv4 settings and select 'shared with other computers'. Save, close and connect an ethernet cable between the RPi and the PC.
On the PC select among the available connections the last created one and connect it.
For Windows PC should be the same.

Check with "Connections informations" on the PC that the parameter are the same of RPi, otherwise reboot both the PC and RPi.
If the parameters are still different make the interfaces ones match the PC ones.

On the Linux PC install two softwares: PUTTY and REMMINA.
For Windows look for equivalents.

Launch PuTTY on the PC.
On the left of the PuTTY configuration window expand 'Connection' and 'SSH' and select 'X11', then enable X11 forwarding.
Go to 'Session' then and in the Host Name put
10.42.0.10
then select
SSH
put the name 'Raspberry Pi SSH'
then "Save" and "Open".

You should see "login as:".
Put your RPi login, usually pi, then the password, usually raspberry.
Ok, now you have a terminal for the RPi.

For a graphical session launch Remmina on the PC.
Then create a new connection.
Put the name 'Raspberry RDP'
Protocol: RDP - Remote desktop
Server: 10.42.0.10
Login: pi (or a different login)
Password: raspberry (or different)

Save and connect.
You should see your Raspberry desktop if a graphical session is running.
Otherwise with PuTTY give the terminal command:
startx
then run again Remmina and connect again.

Ok, now we can go without problems.

Open on PuTTY or Remmina a terminal and give the command:
sudo nano /boot/config.txt
then add this line to the bottom
dtoverlay=piscreen,speed=16000000,rotate=90
give Ctrl+X then save and exit.

Give the command:
sudo reboot

Now the touch screen should be abled, so let's tell RPi to use it.

WARNING: after next commands you will not see the Raspberry on the HDMI monitor, so if PuTTY or Remmina are not working you will not be able to see the terminal or desktop of your Raspberry.
So check that PuTTY or Remmina are correctly working after some reboots.

Connect again with PuTTY or Remmina and give the command:
sudo apt-get install fbi
then
sudo reboot

After reboot give:
sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
change the line in the file:
Option "fbdev" "/dev/fb0"
to
Option "fbdev" "/dev/fb1"
Give Ctrl+X, save, exit and reboot with sudo reboot.

Now you should see the screen working, thus not the touch.

To complete the installation create a script for touch axes:
sudo nano /etc/xdg/lxsession/LXDE/touchscreen.sh
then add these lines to the file:
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axes Swap' 0
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 1 0

give Ctrl+X, save and exit.
Then make the file executable:
sudo chmod +x /etc/xdg/lxsession/LXDE/touchscreen.sh

Now let's run this script at startup:
sudo nano /etc/xdg/lxsession/LXDE/autostart
then before the line
@xscreensaver -no-splash
add
@lxterminal --command "/etc/xdg/lxsession/LXDE/touchscreen.sh"
give Ctrl+X, save, exit and reboot your RPi.
(Before 'command' there are two --, not one -)

You should have both the screen and the touch working!

Please let me know for eventual problems or not clear passages.
I could have made some mistakes in reporting the correct procedure.

Simone ;)

zappology
Posts: 2
Joined: Fri Mar 24, 2017 1:30 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sat Mar 25, 2017 7:01 am

In the case the rotation of the axes should not be applied, install evdev before crating the file touchscreen.sh, by giving terminal command:
sudo apt-get install evdev

:roll:
simone

profbit
Posts: 45
Joined: Fri May 05, 2017 4:34 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sat May 06, 2017 8:36 am

Nice tutorial!

btw, the touch display isn't accurate.
When i point my finger on top, the cursor is at the bottom.
I followed all the steps, any help? :)

julio.vera
Posts: 2
Joined: Sat Sep 16, 2017 9:53 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Tue Sep 19, 2017 2:08 am

profbit wrote:
Sat May 06, 2017 8:36 am
Nice tutorial!

btw, the touch display isn't accurate.
When i point my finger on top, the cursor is at the bottom.
I followed all the steps, any help? :)
@profbit, did you get to fix the mirrored touch?

User avatar
Imperf3kt
Posts: 3512
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Tue Sep 19, 2017 4:46 am

Why do you need sudo rpi-update
This should almost never be used
55:55:44:44:4C
52:4C:52:42:41

aswinvr
Posts: 1
Joined: Sun Oct 08, 2017 5:01 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sun Oct 08, 2017 5:23 pm

Soon after the step

sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
change the line in the file:
Option "fbdev" "/dev/fb0"
to
Option "fbdev" "/dev/fb1"
Give Ctrl+X, save, exit and reboot with sudo reboot.


my 3.5-inch screen starts to work with touch capability. I think steps after this not necessary, as"sudo apt-get install evdev" not supported and commands which placed under /etc/xdg/lxsession/LXDE/autostart not getting executed whenever reboot happens

But screen X axis was reversed.

I found a fix with command

DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' "Coordinate Transformation Matrix" -1 0 1 0 1 0 0 0 1

I tried to make a cron job for above command for every reboot, placed in autostart but seems not working. now I have to run it manually for every reboot. :(

Any help :)

rabbi
Posts: 1
Joined: Sat Oct 21, 2017 7:35 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sat Oct 21, 2017 7:49 pm

aswinvr wrote:
Sun Oct 08, 2017 5:23 pm
Soon after the step

sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
change the line in the file:
Option "fbdev" "/dev/fb0"
to
Option "fbdev" "/dev/fb1"
Give Ctrl+X, save, exit and reboot with sudo reboot.


my 3.5-inch screen starts to work with touch capability. I think steps after this not necessary, as"sudo apt-get install evdev" not supported and commands which placed under /etc/xdg/lxsession/LXDE/autostart not getting executed whenever reboot happens

But screen X axis was reversed.

I found a fix with command

DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' "Coordinate Transformation Matrix" -1 0 1 0 1 0 0 0 1

I tried to make a cron job for above command for every reboot, placed in autostart but seems not working. now I have to run it manually for every reboot. :(

Any help :)


Hi All,

I've follow the instructions and my lcd already displaying the desktop + the touch screen is working.

But i'm also having trouble with the x axis, if i touch the right side of the screen the cursor will go to the left and vice versa.
What to do?

And is there anyway to switch between lcd and hdmi at run-time?

Thanks,
Rabbi

omvr18
Posts: 2
Joined: Tue Sep 19, 2017 2:33 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Mon Nov 20, 2017 5:55 pm

Hi, I have the same problem, I follow the instructions but the x axis is inverted.I tied to found different methods but any work

Any help with this problem?

jfzaki
Posts: 1
Joined: Fri Dec 22, 2017 8:59 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Fri Dec 22, 2017 9:13 am

Hello Everyone

New here and new to pi so no claims of anything...

I found a simple solution to the x axis inversion problem. However, I still can't see the HDMI and touch at the same time if someone could help?

Solution to x-axis inversion or even x and y inversion.

What came to my mind after following the procedure and resulted in x-axis inversion is to use a screen calibration. Then after the success in the trial, I put the configuration into an autostart file and it worked!!!

Steps

Code: Select all

sudo apt-get install -y xinput-calibrator
go to
Menu -> Preferences -> Calibrate Touchscreen.

you will see a + sign on the screen click on it even if your cursor goes to the other side of the screen (you should click on the + sign exactly).
after the first click, you will get another + sign on the other side of screen, click on it... you will notice that starting from this point onward, your pointer(mouse cursor) is where you click. not like the first + sign it was on the other side of the screen. This way you have calibrated the screen. you will be shown with a screen that has the new calibration coordinates. Save these few lines in a text file for later use.

Now if you restart it will return back to the old position (inverted axis). So you need to ensure that every time it loads, it takes the right coordinates. This is where the few lines you have just saved from the calibration come into action.

put them in the file below

Code: Select all

sudo nano /usr/X11/xorg.conf.d/99-calibration.conf
in some configuration it may be

Code: Select all

 sudo nano /etc/X11/xorg.conf.d/99-calibration.conf
instead of /usr

Code: Select all

Section "InputClass"
	Identifier	"calibration"
	MatchProduct	"ADS7846 Touchscreen"
	Option	"Calibration"	"3937 218 208 3970"
	Option	"SwapAxes"	"0"
EndSection
The above is my own calibration lines.... you should replace these with yours... it is just here for argument sake.

JessyMathault
Posts: 1
Joined: Sun Jan 21, 2018 3:45 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sun Jan 21, 2018 4:04 am

Hey all,

soon after
"Option "fbdev" "/dev/fb1"
Give Ctrl+X, save, exit and reboot with sudo reboot."
The screen started working with the touchscreen, with the only error that the x axis was mirrored.

I tried the calibration again and again but nothing worked. Then I read here :
viewtopic.php?f=28&t=172025&p=1123456
that libinput was overriding the evdev config. What worked for me is :
sawjam wrote:

Code: Select all

apt-get install xserver-xorg-input-evdev 
Then go to /usr/share/X11/xorg.conf.d and list the files

Code: Select all

cd  /usr/share/X11/xorg.conf.d
ls 
The ##-evdev.conf must load after ##-libinput.conf for me the files were 10-evdev.conf and 40-libinput.conf, which caused the confg libinput to overide the evdev config.

Code: Select all

sudo mv 10-evdev.conf 45-evdev.conf
change the initial number to higher than the libinput number, this then loads the evdev config after the libinput config.

Code: Select all

reboot
This resolved my inverted axis issue, then run the calibration, graphically or from comand line.
This did not work for me since I already tried the calibration and the file :

Code: Select all

/etc/X11/xorg.conf.d/99-calibration.conf
had been modified. So according to here :
https://github.com/notro/fbtft/issues/445

I wrote smaller numbers in so that in "/etc/X11/xorg.conf.d/99-calibration.conf", it was :

Code: Select all

Option "Calibration" "3932 300 294 3801"
Then everything worked fine.

tldr : reverse libinput and evdev. The calibration now outputs way too big numbers so go back to default if you calibrated and it doesn't work.

Lexicographical
Posts: 1
Joined: Sun Apr 01, 2018 5:47 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sun Apr 01, 2018 5:48 am

Thank you for the great tutorial! I was finally able to get my XPT2046 to work with my RPi 3.
I have a question, though. I noticed that it has a very slow framerate on the monitor itself. Is there a way to increase this?

blandman
Posts: 1
Joined: Sun May 20, 2018 2:17 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sun May 20, 2018 2:19 am

Lexicographical wrote:
Sun Apr 01, 2018 5:48 am
Thank you for the great tutorial! I was finally able to get my XPT2046 to work with my RPi 3.
I have a question, though. I noticed that it has a very slow framerate on the monitor itself. Is there a way to increase this?
Not to my knowledge, framerate will be limited to SPI I believe.

User avatar
aamir24
Posts: 9
Joined: Thu Jan 11, 2018 7:58 pm
Contact: Website YouTube

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Mon Jun 04, 2018 9:45 pm

Hey guys , i am sharing the super easy way to install raspberry pi 3.5 inch LCD. You can install your LCD in few seconds just follow the step in this video: https://youtu.be/Fj3wq98pd20

Adarsh Singh
Posts: 21
Joined: Mon Jun 06, 2016 9:18 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Wed Jun 06, 2018 5:34 pm

How do I make it work with Raspbian Lite, it lacks sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf

Elmore
Posts: 1
Joined: Tue Aug 07, 2018 11:16 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Tue Aug 07, 2018 11:26 pm

Okay. I Actually got this to work eventually with new Raspbian (07.08.2018)
Turns out, most of the shit above is pointless and/or useless. Here are the instruction from start to finish in a sensible format and useful modification instructions assuming you already have functioning ssh connection:

THIS IS FOR VERTICAL SCREEN ORIENTATION (horizontal modification below)

sudo nano /boot/config.txt
Add this line to the bottom
dtoverlay=piscreen,speed=16000000,rotate=180
sudo reboot

sudo apt-get install fbi
sudo reboot


sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
change the line in the file:

Code: Select all

Option "fbdev" "/dev/fb0"
to

Code: Select all

Option "fbdev" "/dev/fb1"
Give Ctrl+O + Ctr+X
Then:
sudo touch /etc/profile.d/swap.sh
sudo nano /etc/profile.d/swap.sh
Add these lines to the file:

DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' “Coordinate Transformation Matrix” -1 0 1 0 1 0 0 0 1
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axes Swap' 1
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1

give Ctrl+O + Ctrl+X
Done.

(For horizontal mode replace red areas with these in order:)
90
0
0 0

ekonik3
Posts: 2
Joined: Sat Jul 21, 2018 2:00 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Tue Aug 14, 2018 2:18 pm

Does this tricks work on Kedei tft Kedei 3.5 inch V6.3?

DirkS
Posts: 10315
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Tue Aug 14, 2018 5:30 pm

ekonik3 wrote:
Tue Aug 14, 2018 2:18 pm
Does this tricks work on Kedei tft Kedei 3.5 inch V6.3?
If it uses the same touch controller and has the same resolution then it will probably work.
Just try it after making a backup of your SD card.

al-pal
Posts: 1
Joined: Fri Oct 05, 2018 2:17 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Fri Oct 05, 2018 2:25 am

The quick method on Youtube works like a charm for me and my 3.5" display is great using the stylus supplied. However I have a problem. I want to use an 8GB SD card to setup my rpi as a Kodi Box, but as this is a new operating system install, it will revert to needing a monitor, keyboard and mouse and my little touchscreen is ignored. This would be fine it I could use Terminal to setup the 3.5" screen, but neither of the NOOBS options for Kodi allow a direct interface. So, does anyone know of a Kodi install that allows a terminal interface, or is pre-loaded to include the 3.5" screen?

unixproxy
Posts: 1
Joined: Mon Oct 08, 2018 11:15 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Mon Oct 08, 2018 11:20 pm

Guys, you need to get the driver from github.

Code: Select all

$ git clone https://github.com/goodtft/LCD-show.git

Code: Select all

$ chmod -R 755 LCD-show/ 

Code: Select all

$ cd LCD-show/

Code: Select all

sudo ./LCD35-show

tomvt
Posts: 2
Joined: Thu Mar 21, 2019 11:21 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Thu Mar 21, 2019 11:30 am

Hi,

I followed the install procedure a while ago and it worked marvelous.

Now I want to do something else with my Raspberry. I removed the touchscreen, attached a standard monitor (one that worked before the install of the touchscreen) and inserted a SD card with NOOBS. The system starts but the resolution is bad and the screen is constantly flashing.

So, inserting another SD is obviously not enough to undo the previous install.

What is the easiest way to undo the changes to the Raspberry Pi 3B + board...?

Tom...

fruitoftheloom
Posts: 22706
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Thu Mar 21, 2019 12:40 pm

tomvt wrote:
Thu Mar 21, 2019 11:30 am
Hi,

I followed the install procedure a while ago and it worked marvelous.

Now I want to do something else with my Raspberry. I removed the touchscreen, attached a standard monitor (one that worked before the install of the touchscreen) and inserted a SD card with NOOBS. The system starts but the resolution is bad and the screen is constantly flashing.

So, inserting another SD is obviously not enough to undo the previous install.

What is the easiest way to undo the changes to the Raspberry Pi 3B + board...?

Tom...

There is no means of saving changes on the Raspberry Pi SBC itself, probably best to start with a new post about your issues as they are not related to previously using a XPT2046 Touch Screen ;)
Rather than negativity think outside the box !

Asus ChromeBox 3 Celeron is my other computer.

tomvt
Posts: 2
Joined: Thu Mar 21, 2019 11:21 am

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Thu Mar 21, 2019 2:44 pm

fruitoftheloom wrote:
Thu Mar 21, 2019 12:40 pm
tomvt wrote:
Thu Mar 21, 2019 11:30 am
Hi,

I followed the install procedure a while ago and it worked marvelous.

Now I want to do something else with my Raspberry. I removed the touchscreen, attached a standard monitor (one that worked before the install of the touchscreen) and inserted a SD card with NOOBS. The system starts but the resolution is bad and the screen is constantly flashing.

So, inserting another SD is obviously not enough to undo the previous install.

What is the easiest way to undo the changes to the Raspberry Pi 3B + board...?

Tom...

There is no means of saving changes on the Raspberry Pi SBC itself, probably best to start with a new post about your issues as they are not related to previously using a XPT2046 Touch Screen ;)
Hi I discovered that there is something with my monitor. If I attach the RPi to another monitor it is working fine. Sorry for the fuzz. :oops:

rithikthegr8
Posts: 1
Joined: Sat Oct 05, 2019 8:42 pm

Re: 3.5 Inch RPi Display Touch - XPT2046 (480x320) - Install

Sat Oct 05, 2019 8:46 pm

I have raspberry pi 3 v1.2. i made the steps. the touch is not working, but the screen is working

Return to “General discussion”