Skip to content

The Screen and Touch

Dustin Watts edited this page Jan 31, 2021 · 3 revisions

Screen

ESP32 TouchDown uses an ILI9488 480*320 TFT screen. It is set up in 4-wire SPI mode. The ILI9488 is not connected to MISO (meaning you can't read from the screen) so the only pins that are used for SPI are:

  • GPIO15 -> TFT_CS
  • GPIO18 -> SPI Clock
  • GPIO23 -> SDI (MOSI)

Furthermore the screen needs two more pins:

  • GPIO2 -> DC_RS
  • GPIO4 -> TFT_RESET

TFT_RESET is pretty self-explanatory. DC_RS is the Data/Command pin of the screen. Before sending something over SPI we need to tell the screen what we are sending. Data or a command. This is should be done by the library you use, but it might help to know what it is for.

Speaking of libraries. For the display I like to use TFT_eSPI by Bodmer. This is a well maintained and easy to use library. The only thing to keep in mind is that you have to change the User_Setup.h file to match that of your screen. An example configuration is included in this repository.

If you are going to use the Touch class that comes with the TFT_eSPI library, a TOUCH_CS has to be defined. Although that is not used. So you can choose any pin you like, just make sure it is defined. A very stripped down version of a User_Setup.h can be:

// Define the driver to be used:
#define ILI9488_DRIVER 

// Define the pins that are used:
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS   15
#define TFT_DC    2
#define TFT_RST   4

// By default the backlight is connected to 3V3. If you want control over the backlight,
// you have to change the solder bridge on the back.
#define TFT_BL   32
#define TFT_BACKLIGHT_ON HIGH

// Although the pin is not used, we need the Touch class:
#define TOUCH_CS 21

// Font loading is optional.
#define LOAD_GLCD 
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
#define SMOOTH_FONT

// We need to define the SPI frequency:
#define SPI_FREQUENCY  27000000

As mentioned in the configuration above, if you want control over the backlight in your program, you have to change the jumper from 3V3 to GPIO32:

TFT Backlight Select

Touch

The Touch Controller used is an FT6236. The FT6236 uses I2C and has address 0x38. The I2C pins on the ESP32 TouchDown are:

  • GPIO21 -> I2C data
  • GPIO22 -> I2C clock

The FT6236 also has an interrupt pin that can be used:

  • GPIO27 -> IRQ

To make it easy to interface with it, I have created a library for it: FT6236. Examples of how to use the library are included in the Examples folder. I've included comments in each example that hopefully show you how you can easily use the library. To get touch coordinates, you basically have to do two simple operations. The first is check if there was a touch, then get the coordinates.

if (ts.touched()){
   TS_Point p = ts.getPoint();
}

Now p.x and p.y contain the X and Y coordinates of the touch point. Keep in mind that the normal mode for the screen is in portrait mode, so in landscape mode, the x-axis is the y-axis and the x-axis is the y-axis. You will have to flip things around to get the correct point. You can see this process being used in the examples, so I encourage you to take a look at those!