Memory problem with TFT_eSPI

Greetings everyone,
I recently got a Lilygo T-Deck Plus. The pre-uploaded code worked fine, but I can't seem to get my own code to work. In particular, I think the problem is with the TFT_eSPI library. Everything works great until I try to use the display with the TFT_eSPI library.
This is the error I get:

I tried replacing the TFT_eSPI library with the one from the Github test code, but that didn't work. I tried changing the library version, but that hasn't worked either. If anyone has any ideas on what the problem is or how to fix it I would really appreciate it.

As I understand it, when you put the text of a Guru Meditation error through the ESP Exception Decoder, it'll tell you exactly what line of your program the error occurred on.

We don't have your program, we can't reasonably do anything with a screenshot of an error, so... it's back to you.

#include <Arduino.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include "utilities.h"

typedef struct {
    uint8_t cmd;
    uint8_t data[14];
    uint8_t len;
} lcd_cmd_t;

lcd_cmd_t lcd_st7789v[] = {
    {0x01, {0}, 0 | 0x80},
    {0x11, {0}, 0 | 0x80},
    {0x3A, {0X05}, 1},
    {0x36, {0x55}, 1},
    {0xB2, {0x0C, 0x0C, 0X00, 0X33, 0X33}, 5},
    {0xB7, {0X75}, 1},
    {0xBB, {0X1A}, 1},
    {0xC0, {0X2C}, 1},
    {0xC2, {0X01}, 1},
    {0xC3, {0X13}, 1},
    {0xC4, {0X20}, 1},
    {0xC6, {0X0F}, 1},
    {0xD0, {0XA4, 0XA1}, 2},
    {0xD6, {0XA1}, 1},
    {0xE0, {0XD0, 0X0D, 0X14, 0X0D, 0X0D, 0X09, 0X38, 0X44, 0X4E, 0X3A, 0X17, 0X18, 0X2F, 0X30}, 14},
    {0xE1, {0XD0, 0X09, 0X0F, 0X08, 0X07, 0X14, 0X37, 0X44, 0X4D, 0X38, 0X15, 0X16, 0X2C, 0X3E}, 14},
    {0x21, {0}, 0}, //invertDisplay
    {0x29, {0}, 0},
    {0x2C, {0}, 0},
};

TFT_eSPI  tft;

// LilyGo  T-Deck  control backlight chip has 16 levels of adjustment range
// The adjustable range is 0~15, 0 is the minimum brightness, 16 is the maximum brightness
void setBrightness(uint8_t value)
{
    static uint8_t level = 0;
    static uint8_t steps = 16;
    if (value == 0) {
        digitalWrite(BOARD_BL_PIN, 0);
        delay(3);
        level = 0;
        return;
    }
    if (level == 0) {
        digitalWrite(BOARD_BL_PIN, 1);
        level = steps;
        delayMicroseconds(30);
    }
    int from = steps - level;
    int to = steps - value;
    int num = (steps + to - from) % steps;
    for (int i = 0; i < num; i++) {
        digitalWrite(BOARD_BL_PIN, 0);
        digitalWrite(BOARD_BL_PIN, 1);
    }
    level = value;
}


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

    Serial.println("T-DECK factory");

    //! The board peripheral power control pin needs to be set to HIGH when using the peripheral
    pinMode(BOARD_POWERON, OUTPUT);
    digitalWrite(BOARD_POWERON, HIGH);

    //! Set CS on all SPI buses to high level during initialization
    pinMode(BOARD_SDCARD_CS, OUTPUT);
    pinMode(RADIO_CS_PIN, OUTPUT);
    pinMode(BOARD_TFT_CS, OUTPUT);

    digitalWrite(BOARD_SDCARD_CS, HIGH);
    digitalWrite(RADIO_CS_PIN, HIGH);
    digitalWrite(BOARD_TFT_CS, HIGH);

    pinMode(BOARD_SPI_MISO, INPUT_PULLUP);
    SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD

    Serial.print("Init display id:");
    Serial.println(USER_SETUP_ID);

    tft.begin();

    /**
     * * T-Deck-Plus and T-Deck display panels are different.
     * * This initialization is used to override the initialization parameters.
     * * It is used when the display is abnormal after the TFT_eSPI update. */
#if 0
    for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
        tft.writecommand(lcd_st7789v[i].cmd);
        for (int j = 0; j < (lcd_st7789v[i].len & 0x7f); j++) {
            tft.writedata(lcd_st7789v[i].data[j]);
        }

        if (lcd_st7789v[i].len & 0x80) {
            delay(120);
        }
    }
#endif

    tft.setRotation( 1 );
    tft.fillScreen(TFT_BLACK);

    tft.setTextDatum(MC_DATUM);
    tft.setFreeFont(&FreeSansOblique12pt7b);
    tft.drawString("Hello World", TFT_WIDTH / 2, TFT_HEIGHT / 2);


    pinMode(BOARD_BL_PIN, OUTPUT);
    for (int i = 0; i <= 16; ++i) {
        setBrightness(i);
        delay(30);
    }
}

void loop()
{
    tft.setTextColor(random(0xFFFF));
    tft.fillScreen(TFT_BLACK);
    tft.drawString("Hello World", random(5, 320), random(5, 240));
    delay(5000);
}

This is the HelloWorld example code.

How does that help? You said it was your code that was failing, not an example.

You were pointed towards the ESP Exception Decoder, which would have told you exactly where the program errored out. You seem to have ignored that. That's fine. If you won't put in the effort to help yourself, I'm certainly not going to prod you to do it. Good-bye.

I apologize for not mentioning that it was an example not working and not a program I wrote myself. As for the ESP Exception Decoder I already know which part is causing the error. It's the tft initialization, I apologize for not mentioning that as well. What I'm stumped on and what I've been troubleshooting on for hours is how to fix it and why this happens only on the T-Deck and not anything else.

It has ESP32-S3, right?

There are several similar issue threads in TFT_eSPI Issues.

In summary, two potential solutions are discussed:

  1. Use 2.0.14 of Espressif board package.
  2. Define USE_HSPI_PORT in User_Setup.h.

No.2 had solved in my case (XIAO ESP32-S3). But not for everyone.
So I think those are worth a try.

#1 worked! :grin:
Thanks for providing a list of threads as well as what worked for you. I really appreciate it.

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