I’m having an issue with the Adafruit 2.4" TFT touchscreen panel. In essence, everything seems to work fine, except the touchpoint I’m receiving is always the previous one.
I have the touch panel effectively divided into 3 portions. We’ll call them top, middle and bottom. When the device first starts and I touch, I don’t get a point printed out. However, upon the second touch, I’m getting the coordinates of the first touch. Then with each subsequent touch, I get the prior touch’s location. I can see this as I move from “top”, to “middle” or “bottom”.
I’m sure I’m doing something dumb here, but can’t see it. The library that was loaded was the 1.0.1 version ported by @rickkas7. I noticed the library is now up to 1.3.1(?), so I copied the code from that library and posted it into my .cpp and .h library files, hoping that might resolve the issue. However, it had no effect. The one change with the newer version is that it does empty the buffer when calling ts.getPoint()
to return the “last” touch coordinates.
Here’s the relevant code from my app. Yes, it’s pretty simple, but just the starting point. Once I get this working properly, then I need to call some webhooks to change Ecobee thermostat settings. It’s an interesting project, but just a wee bit frustrating right now due to this issue and I’m hoping someone can shed some light on what I’m doing wrong.
Here’s the relevant code:
//Create the display object
Adafruit_ILI9341 tft(TFT_CS, TFT_DC); //create display object
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); //create touch object
boolean processTouch = true; //used to indicate if touchscreen should be ignored while finger is held down
//in setup()
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
while (1);
}
Serial.println("Touchscreen started");
//the main loop
void loop() {
if (ts.touched()) {
//Serial.println("touched");
if (processTouch) {
getXYZ();
}
processTouch = false;
}
else {
count = 0;
processTouch = true;
//Serial.println("not touched");
}
}
void getXYZ() {
if (!ts.bufferEmpty()) {
count += 1;
p = ts.getPoint();
if (!ts.bufferEmpty()) {
Serial.println("Buffer wasn't empty");
p = ts.getPoint();
}
x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
z = p.z;
Serial.print("Final x=");Serial.print(x);
Serial.print(", Final y=");Serial.print(y);
Serial.print(", Final z =");Serial.print(z);
Serial.print(", Count = ");Serial.println(count);
delay(10);
}
}
By the way, it never prints “Buffer not empty” and always prints count=1.