Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By wardg32
#80035 I'm having some trouble getting a 2.8" SPI touchscreen using the XPT2046 chipset working on a Lolin v3 board running a recent dev build of nodemcu which has an xpt2046 module. It's connected up correctly (similar to this guide) and I am getting readings but they are borderline nonsense. You get lower readings towards the (0,0) corner than you do in (320,240) but even averaged out using the xpt2046.getPositionAvg() function, the results are unusable.

For debugging purposes I connected up the touchscreen controller only to the HSPI bus, not the ILI93141. This didn't make any difference.


I have set it up like so:
Code: Select allspi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 16, spi.FULLDUPLEX)

--xpt2046.init(cs_pin, irq_pin, height, width)
xpt2046.init(0,2,320,240)


I have an interrupt set up to pin 2, the IRQ pin of the touchscreen

Code: Select allgpio.trig(2, "down", function()
   print(tmr.now(), xpt2046.getRaw())
end)

The interrupt works as intended but

getPositionAvg() often returns -1 for x or y
getRaw() often returns 2048

I did verify the screen does definitely have an XPT2046 just now with a loupe. Other than that I'm all out of ideas. I don't have a logic analyser or another module to try unfortunately.

Some example getPositionAvg() output that should range from (0,0) to (320,240)
Code: Select all-1    -1
90    110
-1    -1
49    103
91    140
53    127
49    125
-1    -1
49    125
49    125
-1    -1
84    144
-1    -1
-1    -1
84    143
-1    -1
-1    -1
57    122
-1    -1
55    121
-1    -1
-1    -1
-1    -1
56    123
-1    -1
80    116
102    100
103    71
20    40
-1    -1
-1    -1
22    42
21    40
-1    -1
User avatar
By QuickFix
#80048 Not sure, but I had a similar problem a long time ago and IIRC I fixed it by only handling the coordinates after an interrupt occurred (so you'll have to use the IRQ line as well).
User avatar
By wardg32
#80052
QuickFix wrote:Not sure, but I had a similar problem a long time ago and IIRC I fixed it by only handling the coordinates after an interrupt occurred (so you'll have to use the IRQ line as well).


Thanks. To be clear though, I am using it in an interrupt driven way at the moment. In that sample data, each line is one interrupt.