SPI TFT kit/One line of code/06. Wiring for your board
One line of code · 06 of 12

Wiring for your board

The library keeps one set of pins for the ESP32-S3 and one for the classic ESP32, and picks between them from the board you chose in Tools. The panel has no say in it — which is the point, and also where the one gap in the table is.

Pins belong to the board

Which pin goes where
ESP32-S3 · HSPI
Board
Panel — watch what happens
SPI bus
HSPI
Clock
GPIO 12
Data
GPIO 11
Backlight
GPIO 41
The panel picker does nothing, and that is the lesson. Pins belong to the board you selected in Tools ▸ Board; the driver, the resolution and the backlight polarity belong to the screen. The library keeps two rows — one for the ESP32-S3 and one for the ESP32 — and picks between them at compile time. There is no third row, so an ESP32-C3 gets the ESP32 numbers, and GPIO 23 and GPIO 32 do not exist on a C3. On that chip, set the pins yourself.

Two controls. The top one changes every number on the drawing. The bottom one — the panel size — changes nothing at all, and that is the thing worth sitting with for a moment.

The GPIO a wire lands on is a property of the board you are compiling for. The driver chip, the resolution, the offsets and the backlight polarity are properties of the glass. They never meet, so there is no combination to look up: pick your board, pick your panel, and the two answers are independent.

The library goes further and picks the board row for you, from what you selected in Tools ▸ Board. Compile for an ESP32-S3 and you get the S3 pins; compile for an ESP32 Dev Module and you get the classic ones. Nothing to edit.

The gap in the table

There are two rows and no third one. The library chooses the S3 row when it is built for an S3, and the classic-ESP32 row otherwise.

Otherwise includes the ESP32-C3, and the classic row hands out GPIO 23 for data and GPIO 32 for the backlight. A C3's pins stop at GPIO 21. Neither of those exists.

So on a C3 — and on anything else that is not one of the two named chips — the default pins are not a starting point, they are wrong, and you set them yourself:

LB_Wiring pins = LB_WIRING;   // start from the default for this chip
pins.cs   = 7;                // ...then change what your board actually has
pins.dc   = 6;
pins.rst  = 10;
pins.mosi = 3;
pins.sclk = 2;
pins.backlight = 5;

display.setWiring(pins);      // before begin()
display.begin();

Copy LB_WIRING rather than declaring an empty one. It carries an SPI bus number whose meaning is not the same on every chip, and starting from the default gives you a bus that is already correct for the chip you are building for.

printInfo() prints the pins actually in use and marks any you overrode, which turns a wiring mistake into a line in the serial log instead of a blank screen.

More than one display

Clock and data are shared. Each display gets its own CS, and DC and RST can be common. That is ordinary SPI, and it is the reason CS exists — without it, two panels on one bus both take every byte.

When it does not work

I am using an ESP32-C3 and nothing works

The library has two wiring rows, one for the ESP32-S3 and one for everything else, and everything else means the classic ESP32's pins — GPIO 23 for data and GPIO 32 for the backlight. Neither number exists on a C3, which only goes up to GPIO 21. Copy LB_WIRING, change the pins to ones your C3 has, and call setWiring before begin.

The pins I want are already used by something else

Override them. Copy LB_WIRING into a variable, change only the fields that differ, and pass it to setWiring before begin. Start from the default rather than filling one in from scratch — the SPI bus number in it means different things on different chips, and copying gets that right for free.

Do I need to change anything when I swap panels?

No. Pins belong to the board, the driver and resolution belong to the screen, and the two do not interact. Swapping a panel changes one constant in the sketch and no wiring at all.

Can two displays share the bus?

Yes — clock and data are shared, and each display gets its own CS pin. DC and RST can be shared too. That is the normal way to run several SPI devices, and chip select is what stops them talking over each other.

Where this goes next

What a single panel constant resolves to, and why five settings hide behind it.

The one line that changes

Edit this page — content/books/spi-tft-kit/wiring-for-your-board.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

SPI TFT LCD Display Kit, 6-Pack from 0.96 to 3.5 inch

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum