TFT Touch display on (XIAO) ESP32 (S3) #13595
Replies: 5 comments 22 replies
-
Since TFT and touch have different CS pins, you can use the same SPI object alternating for both. You should not create different SPI objects. Only you might have to switch the SCK frequency, since the touch only allows 1 MHz. You can do that with spi.init(freq=xyz). |
Beta Was this translation helpful? Give feedback.
-
I do not know the internal wiring of the display you use. Could it be that the interrupt handler is only called when CS of the touch is low? Do you get touch events when you poll the touch sensor in main()? |
Beta Was this translation helpful? Give feedback.
-
I can confirm that the setup works with a single SPI object. My solution is to make a small change to "xpt2046.py". ...
def raw_touch(self):
"""Read raw X,Y touch values.
Returns:
tuple(int, int): X, Y
"""
self.spi.init(baudrate=2000000) # set rate to 2Mhz
x = self.send_command(self.GET_X)
y = self.send_command(self.GET_Y)
self.spi.init(baudrate=5000000) # set rate to 5Mhz
if self.x_min <= x <= self.x_max and self.y_min <= y <= self.y_max:
return (x, y)
else:
return None
... And this is my "test.py" from machine import Pin, SPI
import esp
from ili9341 import Display, color565
from xpt2046 import Touch
from xglcd_font import XglcdFont
esp.osdebug(None)
spi = SPI(1, baudrate=50000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
# display
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=240, height=320, rotation=180)
print('Loading font unispace')
unispace = XglcdFont('Unispace12x24.c', 12, 24)
# touch
def handle_touch(x,y): # Display x and y of touch
print(f'touched at x:{x} y:{y}')
touch = Touch(spi, cs=Pin(33), int_pin=Pin(32), int_handler=handle_touch)
def main():
lines = [f'This is line {n+1}' for n in range(11)]
y = 0
for l in range(len(lines)):
display.draw_text(0, y, lines[l], unispace, color565(255, 255-y, y), background=color565(0,0,0))
y += 28
main() Works on esp32 board:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for looking into this guys. @robert-hh: Thanks for mentioning that the 'rdagger-display' (with separate SPI's) works on a P Pico W. @shariltumin: I just tried your suggestion to make that change to the baudrate in xpt2046.py and also tried your test code. At this point I will no longer be testing with the XIAO ESP32-S3. Truth table mentioned above:
Board: XIAO ESP32-S3 Code shows initial baudrate of 20_000_000 but an initial baudrate of 1_000_000 Test code:
|
Beta Was this translation helpful? Give feedback.
-
I got my Pico's and displays today and I can confirm that my test code as posted before works. I think the conclusion is that the board I started out with just doesn't play nice with Micropython. Thanks guys! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm trying to use a TFT touch display on a XIAO ESP32-S3, this is the display:
https://www.openhasp.com/0.6.1/displays/ILI9341_IPS/
I have it hooked up and I can either show text/graphics or use the touch functionality.
But not both at this point.
I'm struggling with the SPI bus and hoping someone could let me know how to solve this.
My connections and code are below.
The library I'm working with is: https://github.com/rdagger/micropython-ili9341/tree/master
In the examples two SPI instances/buses(?) are used for the display and touchscreen.
Note: The display can handle a 40 MHz baudrate while the touch does not work above 1 MHz.
Should I use soft SPI to create a separate SPI for the touchscreen?
If so, how would I connect the MISO/MOSI/SCK from both the hardware and soft SPI to the display?
I've also been reading about daisy chaining, HSPI and VSPI but it's a bit beyond me what to do with that info.
So if someone has any suggestion, thanks in advance!
connections and code:
Beta Was this translation helpful? Give feedback.
All reactions