1

Code is below. I'm using the Adafruit Huzzah Feather with the Feather wing TFT display. I'm trying to create a simple GUI that has a few buttons on it. The initial buttons being displayed is lightning quick, at least as far as I can tell. When I hit the touchscreen to go to a new "page" I can see the rectangle being drawn over a second and then the same thing with the new button that I'm drawing. Is this thing supposed to be this slow or am I doing something that stupid? I'm even using the "faster" TFT_eSPI library. With other examples, like a push button the display updates really quick. Any ideas?

#include <SPI.h>
#include <Wire.h>      // this is needed even tho we aren't using it
#include <ESP8266WiFi.h>
#include "FS.h"
#include <TFT_eSPI.h>    // Core graphics library
#include <Adafruit_STMPE610.h> // Touchscreen Controller

#define CALIBRATION_FILE "/TouchCalData3"
#define REPEAT_CAL false
#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750

const char *ssid = "AP"; // The name of the Wi-Fi network that will be created
const char *password = "changeme";   // The password required to connect to it, leave blank for an open network
Adafruit_STMPE610 ts = Adafruit_STMPE610(16);

int currentPage = 0;
bool allSelected = true;

TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h
void setup(void) {
  Serial.begin(115200);

  delay(10);  

  if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
  }
  Serial.println("Touchscreen started");

  tft.init();
  tft.setRotation(0);

  setupAp();
  drawHomePage();
}

void drawHomePage() { 
  wipe();
  Serial.println("Drawing HP");

  long time1 = millis();
  tft.drawRoundRect(10, 10, 220, 145, 7, ILI9341_WHITE);
  tft.drawCentreString("LIGHTS", 120, 60, 2);

  tft.drawRoundRect(10, 165, 220, 145, 7, ILI9341_YELLOW);
  tft.setTextColor(ILI9341_YELLOW);
  tft.drawCentreString("GAUGES", 120, 220, 2);

  long time2 = millis();
  long result = time2 - time1;
  Serial.print("HP Took: "); Serial.println(result);
}

void drawLightsHomePage() {
  wipe();
  Serial.println("Drawing Lights");
  long time1 = millis();

  if(allSelected) {
    tft.fillRect(10, 10, 58, 52, ILI9341_WHITE);
    tft.setTextColor(ILI9341_BLACK);
    tft.drawCentreString("All", 34, 20, 2);
  }
  else {
    tft.drawRect(10, 10, 68, 52, ILI9341_WHITE);
    tft.setTextColor(ILI9341_WHITE);
    tft.drawCentreString("All", 34, 60, 2);
  }

  long time2 = millis();
  long result = time2 - time1;
  Serial.print("Lights Took: "); Serial.println(result);
}

void wipe() {
  long time1 = millis();
  Serial.println("Wiping screen");
  tft.fillRect(0, 0, 240, 320, ILI9341_BLACK);
  long time2 = millis();
  long result = time2 - time1;
  Serial.print("Wiping took: "); Serial.println(result);
}

void loop() {
  // Retrieve a point  
  TS_Point p = ts.getPoint();

  if (ts.bufferSize()) {
    p = ts.getPoint(); 
  } else {    
    p.x = p.y = p.z = -1;// this is our way of tracking touch 'release'!
  }

  if (p.z != -1) {
    tft.fillCircle(p.x, p.y, 2, TFT_WHITE);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    Serial.print("("); Serial.print(p.x); Serial.print(", "); 
    Serial.print(p.y); Serial.print(", "); 
    Serial.print(p.z); Serial.println(") ");

    if(currentPage == 0) {
      if(p.y < 160) {
        Serial.println("Hit Button");
        currentPage = 1;
        drawLightsHomePage();
      }
      else if(p.y > 160 && p.y < 320) {
      }
    }
  }
}

void setupAp() {
  Serial.println('\n');

  WiFi.softAP(ssid, password);             // Start the access point
  Serial.print("Access Point \"");
  Serial.print(ssid);
  Serial.println("\" started");

  Serial.print("IP address:\t");
  Serial.println(WiFi.softAPIP());         // Send the IP address of the ESP8266 to the computer
}

Sample output of the times is below, but I could swear even drawing the button take a good half a second. It's agony!

Wiping screen
Wiping took: 48
Drawing HP
HP Took: 6
(109, 111, 50)
Hit Button
Wiping screen
Wiping took: 1234
Drawing Lights
Lights Took: 52
rball
  • 6,925
  • 7
  • 49
  • 77
  • 1
    is there a command to clear the lcd that would work instead of drawing a ton of black pixels using the rectangle? – dandavis Jul 27 '18 at 20:25
  • There is although it doesn't seem to work consistently. Not sure why. I'm wondering if voltage is the issue. I'll swap that in to take a look at those times. Worth a try. – rball Jul 28 '18 at 04:28
  • The other function that clears the screen runs in the same amount of time. I'm guessing this is running so slowly because of hardware. – rball Jul 28 '18 at 19:44
  • that sounds more like a library issue if other examples work faster. it pays to shop around. ESP8266's have a lot of CPU+RAM, so you might try a buffered interface, which can only update the pixels that need it instead of sending out all the pixels each time. I know the adafruit libs have such an option. You should also overclock your ESP if you haven't yet. And make sure you're on the hardware SPI line, or else it will run a lot slower... You lib supports sprites, look into that. – dandavis Jul 28 '18 at 19:47
  • What I ended up doing is sort of what you're talking about. I just drew buttons, had a multidim array and checked it for diff's. From there, I only updated the buttons that needed to be redrawn. Works pretty well. I can sometimes see it draw when a lot of the buttons need to be updated, but it's pretty manageable. I'll look into the sprites thing, although I didn't see that option. I'm also plugging right into the featherwing, so I'm unsure if I'm using the hardware SPI line. I'll most likely be buying some cheap displays and use TFT_eSPI in the future. This was my first touchscreen. – rball Aug 07 '18 at 05:15

1 Answers1

0

After reading around the simple answer is: Because the hardware/library is that slow.

rball
  • 6,925
  • 7
  • 49
  • 77