TFT_eSPI crashes but sketch keeps running?

Hi, I have a Waveshare ESP32-S3-Nano and a 3.5" IPS Display.

I found it a bit hard to find a suitable touch library for the FT6336U but I ended up using https://github.com/aselectroworks/Arduino-FT6336U

Based on one of the library examples I've came up with the following code:

#include "FT6336U.h"
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();

// GPIO pin numbering
#define I2C_SDA 11   // GPIO 11 is A4
#define I2C_SCL 12   // GPIO 12 is A5
#define RST_N_PIN 5  // GPIO 5 is D2
#define INT_N_PIN 6  // GPIO 6 is D3

uint16_t curCoord = 0;

FT6336U ft6336u(I2C_SDA, I2C_SCL, RST_N_PIN, INT_N_PIN);

void setup() {
    Serial.begin(115200);

    ft6336u.begin();

    tft.begin();
    tft.fillScreen(TFT_BLACK);
    tft.setRotation(1);
    tft.setTextSize(2);

}

FT6336U_TouchPointType tp;
void loop() {
    tp = ft6336u.scan();
    char tempString[128];
    sprintf(tempString, "FT6336U TD Count %d / TD1 (%d, %4d, %4d) / TD2 (%d, %4d, %4d)\r", tp.touch_count, tp.tp[0].status, tp.tp[0].x, tp.tp[0].y, tp.tp[1].status, tp.tp[1].x, tp.tp[1].y);
    Serial.println(tempString);

    // single touch detection
    if (tp.touch_count == 1) {
        
        tft.setCursor(100,100);
        tft.print("Press at ");
        if (tp.tp[0].y <= 480) {
          tft.print(tp.tp[0].y);
          tft.println("      ");
          curCoord = tp.tp[0].y; // store y coord
        } else {
          tft.println("erratic!");
        }

    } else {
      tft.setCursor(100,100);
      tft.println("                  ");
    }
}

This works fine when only using one finger on the display. However, as soon as I place two fingers on it and move them around, the display goes blank and nothing will be displayed anymore but the sketch continues to run as the output to the serial monitor continues to be perfectly fine when moving my finger(s) on the display. To make things worse the issue seems to lie in the following statement:

curCoord = tp.tp[0].y;

I am simply storing - at least trying to - the y value of the coordinate where the touch display is pressed. As soon as I comment this line out, I can't get the screen to quit despite trying for minutes. After uncommenting the line again I can get the display to go and stay blank within a few seconds with serial monitor continuing to run. I uploaded both versions multiple times and it is 100% reproducable.

Thoughts?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.