TFT_eSPI Sketch will not run on ILI9143 TFT Display

I am trying to get a TFT_eSPI sketch to run on an ESP32 Dev Module driving an MSP2807 LCD display using an ILI9341 driver. The sketch is supposed to print some lines of text and draw some ellipses. It compiles and uploads OK. Nothing shows on the MSP2807 display. What have I missed?

The sketch listing follows:

/*
      Ellipse drawing example with some text

*/

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

//#########################################################
//#########################################################
//
//       User Setup Defined Below
//
//#########################################################
//#########################################################

#define ILI9341_DRIVER

#define TFT_SCK    18 // Green Wire
#define TFT_MOSI   23 // Yellow Wire 
#define TFT_MISO   19 // Gray Wire
#define TFT_CS     15 // Brown Wire
#define TFT_DC      2 // Orange Wire
#define TFT_RESET   4 // Red Wire

// #define TFT_BKL  22 // Connected to +3.3V

#define SPI_FREQUENCY  27000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY  2500000

   #define TFT_BLACK       0x0000      /*   0,   0,   0 */
   #define TFT_NAVY        0x000F      /*   0,   0, 128 */
   #define TFT_WHITE       0xFFFF      /* 255, 255, 255 */ 
     
//#########################################################
//#########################################################
//#
//#         End User Setup
//#
//#########################################################
//#########################################################   

void setup(void) {
  tft.init();

  tft.setRotation(1);

}

void loop() {

  tft.fillScreen(TFT_WHITE);
  
// First we test printing with using a background colour set
  
  tft.setTextSize(1);
  tft.fillScreen(TFT_WHITE);
  tft.setTextColor(TFT_NAVY, TFT_WHITE);

  tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
  tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);

  // Draw some random ellipses
  
  for (int i = 0; i < 40; i++)
  {
    int rx = random(60);
    int ry = random(60);
    int x = rx + random(320 - rx - rx);
    int y = ry + random(240 - ry - ry);
    tft.fillEllipse(x, y, rx, ry, random(0xFFFF));
  }

  delay(2000);
  tft.fillScreen(TFT_NAVY);

  for (int i = 0; i < 40; i++)
  {
    int rx = random(60);
    int ry = random(60);
    int x = rx + random(320 - rx - rx);
    int y = ry + random(240 - ry - ry);
    tft.drawEllipse(x, y, rx, ry, random(0xFFFF));
  }

  delay(2000);
}

The pin wiring drawing:

That the Displays section of the forum would be a better section for this question?

(You can ask the moderators to move it there.)

Thank you Dave. How do I go about asking the moderators to make this move?

Best wishes

Click the waving flag icon (between the link icon and pencil icon) of any of your posts.

You cannot define the pins etc in the sketch. You must edit the User_Setup.h file in the library or use User_Setup_Select.h to point to an existing or custom setup. Read the comments in those files for more info.

Run the diagnostic "Read_User_Setup" sketch to check the serial output for the settings the compiler is picking up.

Thank you Mr. Bodmer. I was unaware that one has to follow this procedure. I was lead to believe that if I copied the specific setup for the ILI9341 which I intended to use and pasted this setup into the sketch, then everything would work.

I will try to follow your instructions and read the notes in the User_Setup.h file and the User_Setup_Select.h.

I will probably get back to you if I have problems implementing znd following ths set of instructions.

Besr wushes

Mr. Bodmer: I apologize for being confused, but I am. I was successful using the Arduino GFX Library to implement driving the ILI9341 to display text and to draw a red square on the ILI9341 display. This sketch is listed below:

//######################################################################
//######################################################################
//
//            Arduino GFX Draw Text and Square
//
//            Comm Port:  COM3
//
//######################################################################
//######################################################################

//
//  The pin definitions below are altered to be in line
//  with those define in Bodmer's TFT_eSPI Library
//

#include <Arduino_GFX_Library.h>
 
#define TFT_SCK    18 // 18
#define TFT_MOSI   23 // 23
#define TFT_MISO   19 // 19
#define TFT_CS     15 // 22
#define TFT_DC      2 //  2
#define TFT_RESET   4 // 17
 
void setup(void)
{
  
  Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
  Arduino_ILI9341 display = Arduino_ILI9341(&bus, TFT_RESET);

//  Note that the ILI9341 Display Driver is defined to be:  "display" 
  
  display.begin();

  display.fillScreen(WHITE);
  display.setCursor(40, 20);
  display.setTextSize(2);
  display.setTextColor(BLUE);
  display.print("From Arduino");
  display.setCursor(25,40);
  display.print("This is the text");
  display.setCursor(70, 60);
  display.print("statement");
 
  display.drawRect(70, 200, 100, 100, RED);
  display.fillRect(70, 200, 100, 100, RED);
 
}
  
void loop() {}

This sketch created the following display:

image

Consistent with the pin connections in this sketch is the wiring diagram for same:

I want to run this same sketch using the TFT_eSPI Library. This sketch is shown below:

//########################################################
//########################################################
//
//      Draw Text and Square Using TFT_eSPI
//
//                    1-27-22
//
//########################################################
//########################################################

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include <Setup109_ILI9341_JR.h>  // User Setup File

//#########################################################
//#########################################################
//
//       Define some colors
//
//#########################################################
//#########################################################


   #define TFT_BLACK       0x0000      /*   0,   0,   0 */
   #define TFT_NAVY        0x000F      /*   0,   0, 128 */
   #define TFT_WHITE       0xFFFF      /* 255, 255, 255 */ 
     

void setup(void) {

  TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

  tft.init();
  
  tft.fillScreen(TFT_WHITE);  // OK
   
  tft.setTextSize(2);        // OK  

  tft.setTextColor(TFT_NAVY, TFT_WHITE);
  
  tft.drawString("This is the text", 0, 0, 2);

  tft.drawRect(70, 200, 100, 100, TFT_RED);
  
  tft.fillRect(70, 200, 100, 100, TFT_RED);
  
}

void loop() {}

Note that I have added the line: "#include <Setup109_ILI9341_JR.h> // User Setup File"
to read in my desired User Setup instructions.

This sketch compiles, and uploads just fine. It does not run. Why?

This setup file is listed below:

// See SetupX_Template.h for all options available

#define ILI9341_DRIVER // Select ILI9341 Driver

//###################################################
//#
//# Define Pin Connections
//#
//###################################################

#define TFT_CS   PIN_D8  // Chip select control pin D8
#define TFT_DC   PIN_D3  // Data Command control pin
#define TFT_RST  PIN_D4  // Reset pin (could connect to NodeMCU RST, see next line)
            // #define TFT_RST  -1    // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V

#define TFT_SCK PIN_D18 // Green Wire
#define TFT_MOSI PIN_D23 // Yellow Wire
#define TFT_MISO PIN_19 // Gray Wire

//#####################################################
//#
//# Pin definitions - Commented Out
//#
//#####################################################

// #define TFT_CS PIN_15 // Brown Wire
// #define TFT_DC 2 // Orange Wire
// #define TFT_RST 4 // Red Wire

// #define TFT_BKL 22 // Connected to +3.3V

//##########################################
//#
//# Load some fonts
//#
//##########################################

#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

#define SMOOTH_FONT

//#########################################
//#
//# Define SPI, SPI_Read and SPI_Touch
//# Frequencies
//#
//#########################################

// #define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000
// #define SPI_FREQUENCY 80000000

#define SPI_READ_FREQUENCY 20000000

#define SPI_TOUCH_FREQUENCY 2500000

// #define SUPPORT_TRANSACTIONS

Now I come down to the issue causing my confusion.

  1. I am using a 30-pin, ESP32 Development Board:

  1. With reference to my User Setup File: Setup109_ILI9341_JR.h, this ESP32 module has no Pin D8
    and no Pin D3..What must I do to solve this problem?

  2. I ran the Read User Setup sketch on this sketch configuration. The output from this sketch is
    shown below:

    On 1-28-22

TFT_eSPI ver = 2.4.2
Processor = ESP32
Frequency = 240MHz
Transactions = Yes
Interface = SPI
Display driver = 9341
Display width = 240
Display height = 320

MOSI = GPIO 23
SCK = GPIO 18
TFT_CS = GPIO 15
TFT_DC = GPIO 0
TFT_RST = GPIO 2

Font GLCD loaded
Font 2 loaded
Font 4 loaded
Font 6 loaded
Font 7 loaded
Font 8 loaded
Smooth font enabled

Display SPI frequency = 27.00

What am I doing wrong, or what should I be doing to solve this problem?

Best wishes