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.
Jerremy09
Posts: 26
Joined: Wed May 08, 2019 7:40 am

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 12:38 pm

Hmmm, why GPIO14? I thought that :

IO14 - CS used by TFT display - used in ILI9341
IO12 - CS used by touch leyer of TFT display

-----------------------------------------------------------------
#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)
tft_cs = machine.Pin(14, 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)
tft_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)
tft_cs.value(1)
-----------------------------------------------------------------
still receiving rame values "(512, 128)" :-(

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

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 1:01 pm

HEllo Thank you,

does it mean that IO14 should be 0?

I tested it with IO14 (1/0) and same result :-(

Roberthh - did you test the module also with another board that pyboard?

Jan

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

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 1:02 pm

Hmmm, why GPIO14? I thought that :

IO14 - CS used by TFT display - used in ILI9341
IO12 - CS used by touch leyer of TFT display

-----------------------------------------------------------------
#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)
tft_cs = machine.Pin(14, 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)
tft_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)
tft_cs.value(1)
-----------------------------------------------------------------
still receiving rame values "(512, 128)" :-(

Second test:
-----------------------------------------------------------------
#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)
tft_cs = machine.Pin(14, 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)
tft_cs.value(1)

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)
tft_cs.value(0)
-----------------------------------------------------------------
still receiving rame values "(512, 128)" :-(

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

Re: xpt2046

Post by Roberthh » Thu Nov 21, 2019 2:04 pm

tft_cs should be 1.
And yes, I tested that with another board too, dont't know whther it was ESP32 or ESP8266. But I can repeat that with an ESP32. You may also try the non-SPI version. 512/128 is a strange value pair.

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

Re: xpt2046

Post by Roberthh » Thu Nov 21, 2019 2:57 pm

I found a reason: Thw SPI baud rate is too high. For the XPT2046 it must not be more than 2000000 (2 MHz).

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

Re: xpt2046

Post by Jerremy09 » Thu Nov 21, 2019 7:39 pm

Hello Roberthh,

many thanks now I receive different values for different touch in differen part of display :-).

Thank you

Jan

solano8
Posts: 1
Joined: Fri Jan 17, 2020 10:28 am

Re: xpt2046

Post by solano8 » Fri Jan 17, 2020 4:13 pm

SPI baud rate is too high. For the XPT2046 it must not be more than 2000000 (2 MHz)
I have already made my first ili9341/xpt2046 project in Arduino, but since I am more comfortable with (Micro-)python I would like to use that for my second project using Lolin TFT-2.4 and Lolin D32 Pro.

Thanks to @Roberthh for his baud info (and @Jerremy09 for asking...) it works now with basic display and touch functionality using ili934xnew.py and xpt2046_syn.py. I will probably also need a xpt.rotate() function. Could not find that in the xpt2046_syn.py. Do you know how to enable that, @Roberthh?

I also have some calibration issues, getting x- and y-values outside the expected 240 x 320 boundary, from (3,-9) to (462,275) using the same parameters for xpt.get_touch as @Jerremy09. Is this easy to solve?

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

Re: xpt2046

Post by Roberthh » Fri Jan 17, 2020 4:57 pm

Rotations is a simple linear transformation, which you can do in your code, like: x_new = a + b * x, where the a and b values have to be determines experimentally. Rotating by 90° or 270° would then only require to swap x and y. I cannot help you much with the calibration values, since that would require access to a simalar touch and LCD device. But the transformation mentioned above would also cover the calibration. You can use raw=Trrue in the call to get_touch to get the raw values. If you do the transformation yourself, you do not need the built-in method.

Post Reply