With TFT_eSPI installed and yourDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Marcussacapuces91/doc-TFT_eSPI/llms.txt
Use this file to discover all available pages before exploring further.
User_Setup.h configured for your hardware, you are ready to write and upload your first sketch. The workflow follows a familiar Arduino pattern — include the library, create a display object, initialize the hardware in setup(), and render graphics in loop(). Because TFT_eSPI’s configuration lives inside the library rather than the sketch, your sketch stays lean: there are no pin numbers or driver constants cluttering the top of the file.
You must configure
User_Setup.h (or platformio.ini build flags) for your specific display and pin wiring before any sketch will work correctly. Uploading a sketch without configuring the library first will result in a blank screen. See the Configuration guide for full details.Hello World Step by Step
Include the library
Add the TFT_eSPI header at the top of your sketch. The The
SPI.h library is pulled in automatically on most platforms, but including it explicitly avoids IDE-specific quirks.#include <TFT_eSPI.h> directive brings in the entire TFT_eSPI class along with all font data you have enabled in User_Setup.h.Create a TFT_eSPI instance
Declare a global The constructor reads pin and driver settings from the
TFT_eSPI object. This object is your interface to every drawing primitive in the library.User_Setup.h you configured earlier — no arguments are needed here.Initialize the display in setup()
Call
tft.init() to send the initialization sequence to the display controller, then set the screen orientation with tft.setRotation().setRotation() accepts values 0–3, stepping through 90° increments clockwise. Value 1 gives landscape orientation on most displays.Complete Hello World Sketch
Here is the full, upload-ready Hello World sketch combining all the steps above:What each method does
| Method | Description |
|---|---|
tft.init() | Sends the controller initialization sequence and powers on the display. Equivalent to tft.begin() on some driver builds. |
tft.setRotation(r) | Rotates the display coordinate system. 0 = portrait, 1 = landscape, 2 = portrait flipped, 3 = landscape flipped. |
tft.fillScreen(color) | Fills every pixel with the specified 16-bit RGB565 colour constant. Use built-in constants like TFT_BLACK, TFT_WHITE, TFT_RED, TFT_GREEN, TFT_BLUE. |
tft.setCursor(x, y) | Sets the pixel position of the next print() / println() call. (0, 0) is the top-left corner. |
tft.setTextColor(fg) | Sets the foreground text colour. A second argument sets the background fill colour: setTextColor(TFT_WHITE, TFT_BLACK). |
tft.setTextSize(s) | Scales the active font by integer multiplier s. 1 = no scaling, 2 = double size, etc. |
tft.setTextFont(f) | Selects the active built-in font by number. Font 1 is the tiny 8px Adafruit GFX font; font 2 is a smooth 16px font. |
tft.println(text) | Prints a string at the current cursor position and moves the cursor to the start of the next line. Inherited from Arduino’s Print class. |
Drawing Shapes and Positioned Text
The following example demonstrates coordinate-based text withdrawString, a filled rectangle, and a circle — the building blocks of most display UIs:
Built-in Colour Constants
TFT_eSPI defines a set of 16-bit RGB565 colour constants you can use anywhere a colour argument is expected:| Constant | Colour |
|---|---|
TFT_BLACK | Black |
TFT_WHITE | White |
TFT_RED | Red |
TFT_GREEN | Green |
TFT_BLUE | Blue |
TFT_YELLOW | Yellow |
TFT_ORANGE | Orange |
TFT_CYAN | Cyan |
TFT_MAGENTA | Magenta |
TFT_NAVY | Dark blue |
TFT_DARKGREEN | Dark green |
TFT_MAROON | Dark red |
tft.color565(r, g, b) method, which converts 8-bit red, green, and blue component values into the packed 16-bit format the display expects.