Page 1 of 2

xpt2046

Posted: Fri Jun 28, 2019 5:41 am
by luigibyte
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 :)

Re: xpt2046

Posted: Fri Jun 28, 2019 7:35 am
by pythoncoder
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.

Re: xpt2046

Posted: Fri Jun 28, 2019 10:23 am
by Roberthh
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.

Re: xpt2046

Posted: Wed Nov 20, 2019 1:48 pm
by Jerremy09
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

Re: xpt2046

Posted: Wed Nov 20, 2019 2:15 pm
by Roberthh
CS is loe activee. So you must set ts_cs to 0 to activate the touch controller.

Re: xpt2046

Posted: Thu Nov 21, 2019 9:15 am
by Jerremy09
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

Re: xpt2046

Posted: Thu Nov 21, 2019 9:16 am
by Jerremy09
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

Re: xpt2046

Posted: Thu Nov 21, 2019 10:28 am
by Roberthh
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.

Re: xpt2046

Posted: Thu Nov 21, 2019 11:26 am
by Jerremy09
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)

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

Re: xpt2046

Posted: Thu Nov 21, 2019 11:58 am
by Roberthh
Looking at the technical Info you supplied, did ouy set TF_CS (GPIO14) to 1? otherwise the TFT is also selected.