xpt2046

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
luigibyte
Posts: 4
Joined: Fri Sep 28, 2018 9:34 pm

xpt2046

Post by luigibyte » Fri Jun 28, 2019 5:41 am

Hi guys.

I am looking for a micropython library to use an XPT2046 touch screen.

I am working on an ESP8266.

I have a tft module that has that touch controller and the pins that I have available are:
TCLK, TCS, TDIN, TD0, TIRQ

thanks in advance :)
Attachments
IMG_4898.jpg
IMG_4898.jpg (162.32 KiB) Viewed 7809 times

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: xpt2046

Post by pythoncoder » Fri Jun 28, 2019 7:35 am

See https://github.com/robert-hh/XPT2046-to ... or-PyBoard from @robert-hh. touch.py is written for the Pyboard and would require some adaptation for different targets.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: xpt2046

Post by Roberthh » Fri Jun 28, 2019 10:23 am

I made a driver once for PyBoard, and now took your question to adapt & test it on ESP8266. Since it uses SPI for communication, it should be possible to adapt it. You can ignore T_RQ and pull TCS low. Then you need only TCLK = CLK, TDIN = MOSI, and TDO = MISO.
Location: https://github.com/robert-hh/XPT2046-touch-pad-driver
The file for the ESP8266 are xpt2046_syn.py and xpttest as simple test script. It is still relatively large. If that is a problem, it can be tailored small. The minimum is __init__ (some of it), raw_touch() and touch_talk().
@pythoncoder: I'll re-do the asynchronous code. Just for the esp8266 I removed it to keep it as small as possible.

Jerremy09
Posts: 28
Joined: Wed May 08, 2019 7:40 am

Re: xpt2046

Post by Jerremy09 » Wed Nov 20, 2019 1:48 pm

Hello all,

I would like to ask you for help within my issue related to touch screen "Lolin TFT 2.4 " connected to "Lolin d32 pro 2.0.0". I connected it according to producer sheet (TFT cable - documentation ), but unfortunatelly Im not able to get a single touch from screen.

I bet that my code is not correct (belive that module "xpt2046_syn" is good).

Links:
1) Lolin d32 - https://wiki.wemos.cc/products:d32:d32_pro
Documentation - https://wiki.wemos.cc/_media/products:d ... v2.0.0.pdf
2) Lolin TFT 2.4 - https://wiki.wemos.cc/products:d1_mini_ ... 2.4_shield
- both connected by lolin cable

Modules:
1) xpt2046_syn - https://github.com/robert-hh/XPT2046-to ... 046_syn.py
- just added import of "from micropython import const" because of "constants" used in code

-----------------------------------------------------------------------------------------------------
Code:
#Setup
import machine
import xpt2046_syn
import time

spi = machine.SPI(1, baudrate=32000000, miso=machine.Pin(19), mosi=machine.Pin(23), sck=machine.Pin(18))
ts_cs = machine.Pin(12, machine.Pin.OUT)
touch = xpt2046_syn.XPT2046(spi = spi, confidence=5, margin=50, delay=10, calibration=None)
count = 0

ts_cs.value(1)
while citac<10:
stisk = touch.get_touch(initial=False, wait=True, raw=True, timeout=300)
print(str(stisk))
count = ccount + 1
ts_cs.value(0)
-----------------------------------------------------------------------------------------------------

So can anybody help me with coding? I tried the example showned by "Roberthh", but again unsucessfull.

thank you for any commnet.

Jan

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: xpt2046

Post by Roberthh » Wed Nov 20, 2019 2:15 pm

CS is loe activee. So you must set ts_cs to 0 to activate the touch controller.

Jerremy09
Posts: 28
Joined: Wed May 08, 2019 7:40 am

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 9:15 am

Hello Roberthh,

you are right, with previsou settings I receive "none" as result:
[img]C:\Users\CZ011845\Desktop\ts_cs_value_0.png[/img]

and if I change the value to be I receive this:
[img]C:\Users\CZ011845\Desktop\ts_cs_value_1.png[/img]
- this I receive even if I touch / nontouch the screen.

Jan

Jerremy09
Posts: 28
Joined: Wed May 08, 2019 7:40 am

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 9:16 am

Sorry I dont know how to add picture.

Current result is "none"
After change is "(512, 128)" even if I touch or not touch the screen

Jan

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: xpt2046

Post by Roberthh » Thu Nov 21, 2019 10:28 am

That's better. At least you receive something from the device. (512,128) is a little bit strange, as if the device is locked. Resistive touch screens require a decent push, more than a typical smart phone. So you may push with your finger nail. You could try to call raw_touch() instead of touch, which will just return the raw chip reading.

Jerremy09
Posts: 28
Joined: Wed May 08, 2019 7:40 am

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 11:26 am

Hello Roberthh,

I tested a high presure with same result (I do remember times of first touch PDA with resistive screens :-)) (nail test also didnt work and I received same values), unfortunatelly didnt helped. I tried to change TFT display (I have 2 LOLIN TFT 2.4).

-----------------------------------------------------------------
Current Code:
#Setup
import machine
import xpt2046_syn2
import time

spi = machine.SPI(1, baudrate=32000000, miso=machine.Pin(19), mosi=machine.Pin(23), sck=machine.Pin(18))
ts_cs = machine.Pin(12, machine.Pin.OUT)
touch = xpt2046_syn2.XPT2046(spi = spi, confidence=5, margin=50, delay=10, calibration=None)
#Default Values xpt2046_syn.XPT2046(spi = spi, confidence=5, margin=50, delay=10, calibration=None)
citac = 0

ts_cs.value(0)
while citac<50:
stisk = touch.get_touch(initial=False, wait=True, raw=False, timeout=300)
stisk2 = touch.raw_touch()
print(str(stisk2))
citac = citac + 1
ts_cs.value(1)

-----------------------------------------------------------------

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: xpt2046

Post by Roberthh » Thu Nov 21, 2019 11:58 am

Looking at the technical Info you supplied, did ouy set TF_CS (GPIO14) to 1? otherwise the TFT is also selected.

Post Reply