ddxfish / XPT2046_Bitbang_Arduino_Library

A software implementation of SPI to access the XPT2046 on the 2432S028 board and similar
GNU General Public License v3.0
5 stars 2 forks source link

Always getting a touch event #6

Closed eccessivo75 closed 1 month ago

eccessivo75 commented 1 month ago

Hi, thank you for this great job. I am getting trouble getting it working. My board is a esp32-2432S028R , i started using the touch library for the hardware SPI made by Stoffergen. It was a working good. As i needed to use the SD card reader i looked to your lib to avoid the problems of sharing the SPI. I integrated it easily, it woks giving me back the correct touch coordinates, but the condition Point.x or point.Y !=0 is always met even if i dont't touch the display. This makes me impossible to understand when the pressure is released. I saw some example with a Zraw, that seem to be nomore supported. Any help would be appreciated

ddxfish commented 1 month ago

Hello @eccessivo75 !

I've seen this before on one of my CYDs. It was bad calibration data, but I only remember redoing my calibration, not the specifics. Here are ideas:

1- #define RERUN_CALIBRATE true
Add this to your code at the top. Redo the calibration with a precise pointer, make sure you get the corners accurately in calibration. If it still fails to map properly, rotate the device 180 degrees and recalibrate with the new orientation. Make sure you remove this line when you are done or each time you boot it will require you to recalibrate, and failure to recalibrate would possibly cause the error you may be seeing.

2- Check the serial output for SPIFFS errors. It's the esp32 filesystem on the flash chip that stores the calibration data. This filesystem can be erased in Arduino IDE and calibration data rebuilt using the RERUN_CALIBRATE true. You may want to use a snippet of code to print the SPIFFS file contents of: /calxpt2040.txt to see if it has our calibration data. If it's missing it would cause this.

3- Check your code. You put "Point.x or point.Y !=0" which is checking if point.x is True, not whether it not equals zero. Here is what I use. if (touch.x != 0 || touch.y != 0) {

Oh and Z-touch aka how hard it was pressed, seemed super unreliable in my original testing, so I removed that feature in favor of the XY-only system. It may have been me misusing Z in the driver, but it seemed a lost cause at the time.

Tell me what you find with these. I'd be happy to advise :)

eccessivo75 commented 1 month ago

Hi @ddxfish and thank you for providing ideas. I want to share my results 1 I tried using a pencil with a small foot print . this improve the result reducing the false touches. Rotating the touch completely breaks the coordinates relationship with the UI 2 i was not getting any Spiff error but i wrote a simple code to read the calibration data, here they are: 1904 108 195 1841 I don't know if they are in the range expected.

3 that is what i was using to be extremely selective if ((touch.x != 0 and touch.y != 0) and (touch.x <238 and touch.y<318))

Final consideration: after your suggestions the the touch is more stable but i get some false touch events (a couple per minute or so) always around the same area: Touch at X: 237, Y: 243 Touch at X: 237, Y: 242 I would think to a defective touch panel , but it is working good with the standard library. Maybe i can create a filter to make the touch panel reactive after a more than a single event. so i can ignore a single fake touch.

ddxfish commented 1 month ago

@eccessivo75 sounds like you really narrowed it down. I had similar issues as those phantom touches, but only on one of my CYDs. I think it is due to the entire lack of filtering on this driver: no smoothing, sanity checking, Zraw or anything outside the raw X,Y data. This one driver you mentioned without the SPI setup we need for the CYD does indeed read the Z value to filter weak and phantom touches. https://github.com/PaulStoffregen/XPT2046_Touchscreen/tree/master If I come back to this driver for a major rework I will try adding Z values again, but it would be early next year.

You could do that double touch idea, and just nest another if statement with another getTouch() function call. It would feel like a long-press sort of. Or you could create a "deadzone" of sorts by using if statements again. Not ideal by any means, but they could get you closer.

Let me know if I can help. I'll close this issue for now, but I'm here if you need anything. Good luck!