TFT makes esp32 reboot

hello everyone
I'm using:
esp32 board
ILI9341 TFT screen

this is my code:

#include <SPI.h>
#include <TFT_eSPI.h>
#include <string.h>
 
#define len 256
#define default_xStart 5
#define default_yStart 80
#define default_width 80
#define default_height 50
 
TFT_eSPI tft = TFT_eSPI();  // Invoke custom library
//const int default_height = 40;
const uint8_t font_size = 2;
const byte cornerRadius = 4;
const int default_btn_color = TFT_WHITE;
uint16_t x = 0, y = 0;
 
char color[len], message[len], clk_commands[len][4];
void printText(uint16_t Xstart, uint16_t Ystart, uint8_t size, char color[len], char message[len]);
uint16_t calData[5] = { 585, 3260, 329, 3289, 7 };
 
 
struct Square {
  int xStart;
  int yStart;
  int width;
  int height;
  int color;
  char touchMessage[len];
};
 
Square Lightbtn = {
  default_xStart,
  default_yStart,
  default_width,
  default_height,
  default_btn_color,
  "LIGHT",
};
 
Square Waterbtn = {
  Lightbtn.xStart + Lightbtn.width + 35,  //120
  default_yStart,
  default_width,
  default_height,
  default_btn_color,
  "WATER"
};
 
Square Soundbtn = {
  Waterbtn.xStart + Waterbtn.width + 30,  //230
  default_yStart,
  default_width,
  default_height,
  default_btn_color,
  "SOUND"
};
 
Square Okbtn = {
  Soundbtn.xStart + 30,
  200,
  default_width - 20,
  default_height - 10,
  TFT_GREEN,
  "Ok"
};
 
 
Square buttonArray[] = { Lightbtn, Waterbtn, Soundbtn, Okbtn };
 
void setup() {
 
  Serial.begin(115200);
  tft.setRotation(1);
  tft.init();
  //touch_calibrate();
  tft.setTouch(calData);
  tft.fillScreen(TFT_BLACK);
  printText(5, 5, 2, TFT_WHITE, "How would you like to wake up?");
 
  for (Square draw : buttonArray) {
    drawSquare(draw);
 
    if (draw.xStart == Okbtn.xStart && draw.yStart == Okbtn.yStart)
      printText(draw.xStart + (draw.width / 3), draw.yStart + (draw.height / 4) + 5, font_size, TFT_WHITE, draw.touchMessage);
 
    else
      printText(draw.xStart + (draw.width / 4) - 7, draw.yStart + (draw.height / 4) + 7, font_size, TFT_BLUE, draw.touchMessage);
  }
}
 
 
//--------------------------------------------------------------------------------------
void loop() {
  checkTouched();
}
//------------------------------------------------------------------------------------------
 
// Code to run a screen calibration, not needed when calibration values set in setup()
void touch_calibrate() {
  uint16_t calData[5];
  uint8_t calDataOK = 0;
 
  // Calibrate
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(20, 0);
  tft.setTextSize(font_size - 0.5);
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
 
  tft.println("Touch corners as indicated");
 
  tft.setTextFont(1);
  tft.println();
 
  tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
 
  Serial.println();
  Serial.println();
  Serial.println("// Use this calibration code in setup():");
  Serial.print("  uint16_t calData[5] = ");
  Serial.print("{ ");
 
  for (uint8_t i = 0; i < 5; i++) {
    Serial.print(calData[i]);
    if (i < 4) Serial.print(", ");
  }
 
  Serial.println(" };");
  Serial.print("  tft.setTouch(calData);");
  Serial.println();
  Serial.println();
 
  tft.fillScreen(TFT_BLACK);
 
  //tft.setTextColor(TFT_GREEN, TFT_BLACK);
  Serial.println("Calibration complete!");
  Serial.println("Calibration code sent to Serial port.");
}
 
 
//This function will take a Square struct and use these variables to display data
//It will save us more code the more elements we add
void drawSquare(Square toDraw) {
  tft.fillRoundRect(
    toDraw.xStart,
    toDraw.yStart,
    toDraw.width,
    toDraw.height,
    cornerRadius,
    toDraw.color);
}
 
uint count_btn_touch = 0;
 
void checkTouched() {
 
  if (tft.getTouch(&x, &y)) {
 
    for (Square btn : buttonArray) {
      if (x > btn.xStart && x < btn.xStart + btn.width && y > btn.yStart && y < btn.yStart + btn.height) {
        if (count_btn_touch >= 3)
          count_btn_touch = 0;
 
        if (btn.yStart != Okbtn.yStart && btn.xStart != Okbtn.xStart) {
          if (count_btn_touch == 0)
            tft.fillRoundRect(Waterbtn.xStart - 5, Waterbtn.yStart + Waterbtn.height + 20, 210, 40, 20, TFT_BLACK);
 
          delay(200);
          printText(Lightbtn.xStart, Lightbtn.yStart + Lightbtn.height + 30, font_size, TFT_WHITE, "You chose");
          printText(Waterbtn.xStart + (count_btn_touch * 70), Waterbtn.yStart + Waterbtn.height + 30, font_size, TFT_WHITE, btn.touchMessage);
 
          if (count_btn_touch >= 1 && count_btn_touch <= 3)
            printText(Waterbtn.xStart + (count_btn_touch * 70) - 10, Waterbtn.yStart + Waterbtn.height + 30, font_size, TFT_WHITE, ",");
          //Serial.print(btn.touchMessage);
          //Serial.print("\t");
          count_btn_touch ++;
 
 
        } else
          for (int i = 0; i >= count_btn_touch; i++)
            sprintf(clk_commands[i], "%s", btn.touchMessage);
      }
    }
    Serial.print("x,y = ");
    Serial.print(x);
    Serial.print(",");
    Serial.println(y);
  }
}
 
 
void printText(uint16_t Xstart, uint16_t Ystart, uint8_t size, int color, char message[len]) {
  tft.setCursor(Xstart, Ystart);
  tft.setTextSize(size);
  tft.setTextColor(color);
  tft.print(message);
}
 

whenever I touch the bottom right corner of my TFT screen the esp keeps resetting the this message appears on the Seirla monitor

ets Jun  8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0

does anyone know what's the issue here?

Please provide a complete wiring diagram

There are questions that doesn't answer.
How is this powered? How are they connected to the power?

the TFT is connected to the 3.3v pin on the esp32
and the power comes from my PC with a USB cable

1 Like

It's restarting because you are browning it out.
Your MCU is not a power supply. You will need to power it differently.

Edit: You will need to power the TFT differently.

I am in a similar spot. Identical wiring. I do have my TFT hooked up to the MCU's 3v3 pin. The MCU will reboot simply by calling the tft.init(). It will do this in a continuous loop. I removed the LED from being powered as well as removing the MCU from my board and it still continues to reboot. So literally, the MCU with nothing hooked up to it and calling tft.init() will just reboot the board continuously. I suspect that there is something odd in the library that is not compatible with this MCU. I am using NodeMCU-32S.

/******************************
   wiring of IFI9488 to ESP32 dev board:
      
      IFI9488       ESP32

      VCC           3V3
      GND           GND
      CS            D15   (GPIO15)
      RESET         D4    (GPIO4)
      DC/RS         D2    (CS)
      SDI (MOSI)    D23   (MOSI)
      SCK           D18   (SCK)
      LED           3V3
      SDO (MISO)    D19   (MISO)

******************************/
      
#define USER_SETUP_LOADED
#define ILI9488_DRIVER
#define TFT_MISO  19
#define TFT_MOSI  23
#define TFT_SCLK  18
#define TFT_CS    15
#define TFT_DC    2
#define TFT_RST   4   //-1  

#include <SPI.h>
#include <TFT_eSPI.h>      // Graphics library

TFT_eSPI tft = TFT_eSPI(); // Invoke library

#ifdef ARDUINO_ARCH_ESP8266
  ADC_MODE(ADC_VCC); // Read the supply voltage
#endif

setup_t user; // The library defines the type "setup_t" as a struct
              // Calling tft.getSetup(user) populates it with the settings
//------------------------------------------------------------------------------------------

void setup() {
  // Use serial port
  Serial.begin(115200);

  Serial.println("tft.init()");
  // Initialise the TFT screen
  tft.init();
  Serial.println("done setup");
}

//------------------------------------------------------------------------------------------

void loop(void)
{

}

This is the serial output (that continues to repeat):

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13220
ho 0 tail 12 room 4
load:0x40080400,len:3028
entry 0x400805e4
tft.init()
ets Jul 29 2019 12:21:46

I figured it out - it wasn't brownout - it was that I was missing a few macros and the library was causing the reboot. If you are replacing your user setup header file with your custom values in your sketch, make sure to include SMOOTH_FONT and the 3 SPI settings.

You have found at least one of your problems. Your uC is not a power supply. You will need to power your screen directly and make sure to connect a signal ground back to the uC.

1 Like

Can I use a LiPo battery that powers the board (and gets charged while the board is plugged into USB) but also drives the TFT? Or how does one go about making a portable project with TFT display without purchasing one of the integrated boards/microcontrollers?

Googe similar project. See what you find.

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