Working with TFT_eSPI begins with creating a class instance and running a handful of setup calls before any pixels can be drawn. This page walks through every step of that process — from the constructor and initialization methods, through rotation modes, to the coordinate system that governs where everything appears on screen.Documentation 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.
Instantiating TFT_eSPI
TheTFT_eSPI class is the central object you interact with throughout your sketch. Declare one global instance before setup() so it is accessible everywhere:
User_Setup.h configuration file, so the no-argument form is almost always correct. Providing explicit dimensions is useful when you want to use a smaller logical canvas than the physical panel.
Initializing the Display
Before any drawing function will work you must callinit() (or its alias begin()). Both methods perform the same hardware initialization sequence — begin() exists purely for backwards compatibility with older sketches.
tc (tab colour) parameter applies only to ST7735 displays and selects the display variant. For every other controller you can omit it entirely and rely on the TAB_COLOUR default.
init() and begin() are fully interchangeable. New sketches should prefer init() for clarity, but both compile to identical code.Configuring Screen Rotation
After initialization you will typically callsetRotation() to orient the display correctly for your enclosure or use-case:
m parameter accepts values 0 – 3, each rotating the coordinate system by a multiple of 90 degrees:
| Value | Orientation | Width → Height |
|---|---|---|
0 | Portrait (default) | native W × H |
1 | Landscape (90° CW) | native H × W |
2 | Portrait flipped (180°) | native W × H |
3 | Landscape flipped (270°) | native H × W |
4 – 7 are also accepted and mirror their 0 – 3 counterparts for use with BMP drawing routines.
Complete Setup Example
The following is a typicalsetup() function drawn directly from library examples:
Declare the instance
Create a global
TFT_eSPI tft before setup() so the object is accessible from every function.Call init() or begin()
Run
tft.init() at the very start of setup() to configure SPI, reset the panel, and apply driver settings.Set rotation
Call
tft.setRotation(n) immediately after init to establish the coordinate system before any drawing.Coordinate System Overview
TFT_eSPI uses a pixel-based Cartesian coordinate system with the origin(0, 0) fixed at the top-left corner of the display after rotation is applied:
- The X axis increases from left to right.
- The Y axis increases from top to bottom.
- Every coordinate is expressed in whole pixels.
(319, 239).
Querying Current Dimensions
AftersetRotation() the logical width and height of the screen change. Use the two dimension accessors to write rotation-aware code:
width() and height() always reflect what is currently visible:
width() and height() are virtual methods inherited through the display driver chain, so they also work correctly on TFT_eSprite objects that share the same coordinate API.