Page 3 of 3

Re: xpt2046

Posted: Thu Feb 18, 2021 11:03 am
by Roberthh
I have update the xp2046_syn.py file to accept a cs parameter after the spi parameter. You have to take into account, that the XPT2046 cannot ruin at a clock speed of 27 MHz. Maximum for the XP2046 is 2.5 MHz. So you have to reconfigure SPI between accesses. And when you call spi.init(), you have to specify all non-default parameters again.

Re: xpt2046

Posted: Thu Feb 18, 2021 12:20 pm
by gurrae
Hi.
Thank you Roberthh for a fast reply (& quick fix !!)

I tried adding the XPT2046 part to my existing software, but it complains about my extra cs argument.
I understand that I have to change (lower) the baudrate in the spi declaration for the 2046, when I access it, but it seems as if I got a mixup of the spi declaration for the display and the 2046.
Please feel fre to correct my lines .....

Code: Select all

import ili934
from machine import SPI, Pin
from xglcd_font import XglcdFont
spi = SPI(1, baudrate=27000000, sck=Pin(14), mosi=Pin(13))
# display_TFT = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=240, height=320, rotation=180)
# width, height & rotation is optional
display_TFT = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
print('Loading unispace')
unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24)
display_TFT.draw_text(0, 0, 'Hello World', unispace, color565(255, 255, 255))

from xpt2046_syn import XPT2046
from time import sleep
cs = Pin(9,Pin.OUT)
spi2 = SPI(1, baudrate=1000000, cs = 9)
xpt = XPT2046(spi2)

while True:
    p = xpt.get_touch(raw=True)
    if p is not None:
        print(p)
    sleep(0.1)
    if p[0] < 500 and p[1] < 500:
        break
This outputs :
TypeError: extra keyword arguments given
for the line :
spi2 = SPI(1, baudrate=1000000, cs = 9)

Re: xpt2046

Posted: Thu Feb 18, 2021 12:24 pm
by Roberthh
Die you use the new version xpt2046_syn.py version from the repository?
And if, it has to be a Pin object: cs=Pin(9, Pin.OUT)

Re: xpt2046

Posted: Thu Feb 18, 2021 12:36 pm
by gurrae
Oops, a bit embarrassing about the missing Pin.OUT -line :-)

Anyway, the same problem remains.
I did use the latest driver (that was timestamped about an hour ago....)

The display driver only defines the mosi pin, and I assume that the XPT2046 needs the miso as well ??
How do I define this in the 2046 definition ??

Re: xpt2046

Posted: Thu Feb 18, 2021 12:49 pm
by Roberthh
You define miso as part if the SPI object setup outside the Xpt2046 driver. For the display it does not matter if miso is defined.

Re: xpt2046

Posted: Fri Feb 19, 2021 1:25 pm
by gurrae
@roberthh

I modified my program as per your instructions, and now the LOLIN 2.4" TFT display works fine with the xpt2046_syn.py, (colors, images, fonts, touch input etc.) so I am very happy.
Thank you again for your fast reply & quick fix !!