# TFT\_eSPI Sketch will not run on ILI9143 TFT Display

**URL:** <https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074>\
**Category:** Displays\
**Created:** [January 22, 2022, 5:53pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074 "2022-01-22T17:53:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![grenken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grenken/32/1013044_2.png) [@grenken](https://forum.arduino.cc/u/grenken)\
**Post date:** [January 22, 2022, 5:53pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/1 "2022-01-22T17:53:44Z")

</div>

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:

```cpp
/*
      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:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/a/a/aaa764ac953110307481f1b912cb5565f718fca5.jpeg)

---

<div class="post-metadata">

**Author:** ![DaveEvans](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/daveevans/32/340502_2.png) [@DaveEvans](https://forum.arduino.cc/u/DaveEvans)\
**Post date:** [January 24, 2022, 5:09am UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/2 "2022-01-24T05:09:38Z")

</div>

> [@grenken](#):
>
> What have I missed?

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

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

---

<div class="post-metadata">

**Author:** ![grenken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grenken/32/1013044_2.png) [@grenken](https://forum.arduino.cc/u/grenken)\
**Post date:** [January 24, 2022, 12:24pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/3 "2022-01-24T12:24:44Z")

</div>

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

Best wishes

---

<div class="post-metadata">

**Author:** ![DaveEvans](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/daveevans/32/340502_2.png) [@DaveEvans](https://forum.arduino.cc/u/DaveEvans)\
**Post date:** [January 24, 2022, 6:52pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/4 "2022-01-24T18:52:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bodmer](https://avatars.discourse-cdn.com/v4/letter/b/65b543/32.png) [@bodmer](https://forum.arduino.cc/u/bodmer)\
**Post date:** [January 27, 2022, 10:01pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/5 "2022-01-27T22:01:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grenken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grenken/32/1013044_2.png) [@grenken](https://forum.arduino.cc/u/grenken)\
**Post date:** [January 27, 2022, 10:55pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/6 "2022-01-27T22:55:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![grenken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grenken/32/1013044_2.png) [@grenken](https://forum.arduino.cc/u/grenken)\
**Post date:** [January 28, 2022, 4:24pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/7 "2022-01-28T16:24:35Z")

</div>

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:

```cpp
//######################################################################
//######################################################################
//
// 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](https://europe1.discourse-cdn.com/arduino/original/4X/d/f/e/dfe6540a525e3f1220599ff811effad95cd42d4e.jpeg)

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

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/a/a/aaa764ac953110307481f1b912cb5565f718fca5.jpeg)

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

```cpp
//########################################################
//########################################################
//
// 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:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/9/7/e/97ef35852c53aef016b99b87bca0bd15e7d8c5f8.jpeg)

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:

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 27, 2022, 4:24pm UTC](https://forum.arduino.cc/t/tft-espi-sketch-will-not-run-on-ili9143-tft-display/950074/8 "2022-07-27T16:24:55Z")

</div>

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