XPT2046 touchscreen giving junk coordinate data on NodeMCU
Posted: Sat Jan 12, 2019 5:30 pm
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:
I have an interrupt set up to pin 2, the IRQ pin of the touchscreen
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)
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 all
spi.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 all
gpio.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