How to Wire a 1.77 Inch TFT Display to ESP32
To wire a 1.77 inch 128x160 tft display to an ESP32, you need to connect the display’s SPI interface pins to the ESP32’s hardware SPI pins, plus a few additional control lines. The display typically uses the ST7735S driver IC, which operates over SPI with a maximum clock speed of 15 MHz. The ESP32’s default SPI pins are VSPI: MOSI (GPIO 23), MISO (GPIO 19), SCK (GPIO 18), and CS (GPIO 5). For the TFT, you’ll also need to connect DC (data/command) to GPIO 16, RESET to GPIO 17, and backlight control to GPIO 4. Power the display with 3.3V from the ESP32’s 3.3V output, and ground both boards. The display’s LED backlight pin (often labeled LEDA) can be tied to 3.3V through a 100-ohm resistor, or directly to a PWM-capable GPIO for dimming. This wiring works for the 1.77-inch variant with a resolution of 128x160 pixels, which uses a 1.44-inch active area but a 1.77-inch module size due to the bezel. The SPI interface uses 4-wire mode (no MISO needed for write-only operations), so you can leave MISO unconnected if you’re only sending data to the display. Double-check your specific module’s pinout—some have a 14-pin or 8-pin header, with common labels like SDA (MOSI), SCL (SCK), CS, DC, RST, BL, VCC, and GND. The ESP32’s 3.3V logic level is compatible with the ST7735S, which operates at 2.8V to 3.6V, so no level shifting is required. However, if your display expects 5V (rare for this size), a logic level converter is needed. The total current draw for the display with backlight at full brightness is around 80 mA, which the ESP32’s regulator can handle, but avoid drawing more than 500 mA from the board’s 3.3V pin.
Pin-by-Pin Wiring Details
Let’s break down each connection with exact pin numbers. The ESP32 dev board (like the ESP32-WROOM-32) has 38 pins, but we only need 7 or 8 for this display. The SPI MOSI pin (GPIO 23) connects to the display’s SDA or MOSI pin. The SPI SCK pin (GPIO 18) connects to the display’s SCL or SCK pin. The CS (chip select) pin on the display goes to GPIO 5 on the ESP32—this selects the display when multiple SPI devices are on the bus. The DC (data/command) pin connects to GPIO 16; this tells the display whether the incoming data is a command (low) or pixel data (high). The RESET pin connects to GPIO 17; a low pulse resets the display controller. The BL (backlight) pin connects to GPIO 4, which can be used with PWM for brightness control. If you don’t need dimming, connect BL to 3.3V through a 100-ohm resistor (limits current to about 33 mA at 3.3V). The VCC pin goes to the ESP32’s 3.3V output (pin 1 on many dev boards). The GND pin goes to any ground pin on the ESP32 (e.g., pin 38). Some displays have a separate LEDA pin for the backlight anode—treat it like BL. If your display has a MISO pin (rare for these small TFTs), leave it unconnected or tie it to GND to avoid floating inputs. The SPI clock speed in software should be set to 10 MHz or lower to avoid signal integrity issues with long wires. Use short jumper wires (under 10 cm) to reduce noise and crosstalk, especially if you’re using a breadboard.
Power Supply Considerations
The ESP32’s 3.3V regulator can supply up to 600 mA, but the actual usable current depends on the board design. The 1.77-inch TFT display with the ST7735S driver draws about 20 mA for the logic, plus 50 to 80 mA for the backlight at full brightness, totaling 70 to 100 mA. This is well within the ESP32’s limits, but if you’re powering other peripherals (like sensors or an SD card), the total current could exceed 500 mA. In that case, use an external 3.3V regulator like the AMS1117-3.3, which can handle 1A. The display’s backlight is typically a white LED with a forward voltage of 3.0V to 3.2V, so a 100-ohm resistor in series with the 3.3V supply limits current to about 3 mA to 10 mA, depending on the LED’s internal resistance. For PWM dimming, connect the BL pin to a GPIO and set the PWM frequency to 1 kHz with a duty cycle of 0% to 100%. The ESP32’s LEDC peripheral can generate this easily. Avoid powering the display from the 5V pin—the ST7735S will be damaged if overvolted. The display’s VCC pin has a maximum rating of 3.6V, so 3.3V is safe. If you’re using a battery-powered ESP32, the display’s current draw will reduce battery life—a 1000 mAh battery would last about 10 hours with the display on continuously.
SPI Bus Configuration and Speed
The ESP32 has two SPI controllers: VSPI (default) and HSPI. VSPI uses GPIO 18 (SCK), 19 (MISO), 23 (MOSI), and 5 (CS). HSPI uses GPIO 14 (SCK), 12 (MISO), 13 (MOSI), and 15 (CS). For this display, use VSPI because it’s the default in most libraries like Adafruit_ST7735 and TFT_eSPI. The SPI clock speed should be set to 10 MHz for reliable operation—faster speeds (like 15 MHz) can cause glitches if the wiring is long or the breadboard has parasitic capacitance. The display’s ST7735S supports up to 15 MHz, but the ESP32’s SPI controller can go up to 80 MHz. In practice, 10 MHz is a sweet spot for stability and speed. The display’s data format is 8-bit SPI, with the most significant bit first. The command set includes initialization sequences that set the display to 128x160 mode, color depth (16-bit or 18-bit), and orientation. The typical frame buffer size is 128x160x2 bytes (40,960 bytes) for 16-bit color, which fits in the ESP32’s 520 KB SRAM. The SPI transaction time for a full frame at 10 MHz is about 32 ms, giving a maximum refresh rate of 30 Hz. If you’re using double buffering, you’ll need 81,920 bytes of RAM, which is still manageable. The display’s pixel clock is derived from the SPI clock, so the actual pixel rate is 10 MHz / 8 bits per pixel = 1.25 million pixels per second. For a 128x160 display (20,480 pixels), that’s 61 frames per second, but the ESP32’s overhead reduces it to around 30 FPS in practice.
Library and Software Setup
After wiring, you need to install a library for the ST7735S driver. The most common is the Adafruit ST7735 library (available in the Arduino IDE Library Manager), which requires the Adafruit GFX library for graphics primitives. Alternatively, the TFT_eSPI library by Bodmer is optimized for ESP32 and offers better performance with DMA support. In TFT_eSPI, you configure the pins in the User_Setup.h file. For the wiring above, set: #define TFT_CS 5, #define TFT_DC 16, #define TFT_RST 17, #define TFT_MOSI 23, #define TFT_SCLK 18, and #define TFT_BL 4. Also set #define TFT_WIDTH 128, #define TFT_HEIGHT 160, and #define SPI_FREQUENCY 10000000. The library automatically handles the initialization sequence for the ST7735S, which includes commands like SWRESET, SLPOUT, COLMOD (set to 16-bit color), DISPON, and CASET/RASET for the 128x160 window. The display’s orientation is controlled by the MADCTL register—default is portrait, but you can rotate it 90, 180, or 270 degrees. The library also supports RGB565 color format, where each pixel is 2 bytes (5 bits red, 6 bits green, 5 bits blue). The color depth is 65,536 colors, which is sufficient for most graphics. If you need higher color accuracy, you can use 18-bit mode (3 bytes per pixel), but this reduces frame rate and increases memory usage. The TFT_eSPI library also supports SPI transactions with the beginTransaction() and endTransaction() functions to avoid conflicts with other SPI devices.
Common Wiring Mistakes and Fixes
One frequent issue is connecting the display’s VCC to 5V instead of 3.3V. The ST7735S is not 5V tolerant—it will overheat and potentially fail within minutes. Always use a multimeter to verify the voltage at the display’s VCC pin. Another mistake is swapping MOSI and MISO. Since this display uses 4-wire SPI (no data output), you can leave MISO unconnected, but if you accidentally connect MOSI to the display’s SDO pin (if present), no data will be sent. Check the datasheet for your specific module—some 1.77-inch displays have a 14-pin header with extra pins like SDO (MISO) and LEDK (backlight cathode). If your display has a separate LEDK pin, connect it to GND, not to a GPIO. The backlight pin (LEDA) should be connected to 3.3V or a GPIO through a resistor. A common error is omitting the resistor, which can draw up to 100 mA and damage the LED. Use a 100-ohm resistor for a 3.3V supply—this gives a current of (3.3V - 3.0V) / 100 ohms = 3 mA, which is dim but safe. For full brightness, use a 10-ohm resistor (30 mA), but ensure the LED’s maximum rating (typically 20 mA to 30 mA) is not exceeded. The display’s RESET pin should be pulled high with a 10k-ohm resistor to 3.3V if not connected to a GPIO, but since we’re using GPIO 17, the ESP32’s internal pull-up is sufficient. The CS pin must be pulled high when not in use—the ESP32’s GPIO 5 has a pull-up by default, but in some libraries, you need to set it explicitly. The DC pin is also a digital output, so no pull-up is needed. If the display shows garbled colors or no image, check the SPI clock polarity and phase—the ST7735S expects SPI mode 0 (CPOL=0, CPHA=0), which is the default in most libraries. If you’re using a logic analyzer, you can verify the SPI signals: CS should go low before the first clock pulse, and DC should be set high for data or low for commands.
Performance Benchmarks and Data
In real-world tests, the 1.77-inch TFT display with the ST7735S driver achieves a refresh rate of 30 FPS when using the TFT_eSPI library with DMA on an ESP32 at 240 MHz. The SPI bus runs at 10 MHz, and the DMA controller transfers data directly to the SPI peripheral without CPU intervention, reducing overhead. The frame buffer is 40,960 bytes for 16-bit color, and the DMA buffer size is typically 1024 bytes, so it takes 40 DMA transactions per frame. The total time to update the entire screen is about 33 ms, including the command overhead. The display’s pixel response time is around 10 ms (typical for TN panels), so motion blur is minimal. The viewing angles are limited—about 60 degrees horizontally and 40 degrees vertically—due to the TN technology. The contrast ratio is typically 300:1, and the brightness is around 200 cd/m² with the backlight at full current. The color accuracy is decent for a low-cost display, with a Delta E of around 10 (measured against sRGB). The power consumption at 3.3V with backlight on is 80 mA (264 mW), and with backlight off, it’s 20 mA (66 mW). The ESP32 itself draws about 80 mA at 240 MHz, so the total system power is 160 mA (528 mW) with the display on. If you’re using deep sleep, the display can be turned off by setting the BL pin low and cutting power to the display’s VCC via a MOSFET, reducing total power to 10 µA.
Alternative Wiring for Different ESP32 Boards
If you’re using an ESP32-S3 or ESP32-C3, the pin assignments differ. The ESP32-S3 has SPI pins on GPIO 11 (MOSI), 12 (SCK), 10 (CS), and 13 (DC) for the default SPI2 controller. The ESP32-C3 has SPI on GPIO 6 (MOSI), 7 (SCK), 5 (CS), and 4 (DC). The wiring procedure is the same, but you must update the library’s pin configuration accordingly. The ESP32-S3 operates at 3.3V logic, same as the ESP32, so no level shifting is needed. The ESP32-C3 has a lower current draw (about 50 mA at 160 MHz), so the total system power is lower. For the ESP32-S2, which has only one SPI controller, use GPIO 35 (MOSI), 36 (SCK), 34 (CS), and 33 (DC). The SPI frequency should be reduced to 8 MHz on the S2 due to its weaker SPI peripheral. If you’re using a breadboard, add a 100 nF capacitor between VCC and GND near the display to decouple noise. The capacitor should be a ceramic type with a low ESR. For longer wires (over 20 cm), use twisted pairs for the SPI signals to reduce electromagnetic interference. The display’s ground plane should be connected to the ESP32’s ground with a thick wire (22 AWG or thicker) to avoid ground loops. If you’re using a shield or breakout board, check the pinout—some 1.77-inch modules have a 2.54 mm pitch header, while others use a 1.0 mm FPC connector. For the FPC type, you’ll need a breakout board or solder wires directly to the pads. The FPC connector has 14 pins, with the pinout typically: 1 (LEDA), 2 (GND), 3 (VCC), 4 (SCL), 5 (SDA), 6 (CS), 7 (DC), 8 (RST), 9 (GND), 10 (MISO), 11 (LEDK), 12 (GND), 13 (NC), 14 (NC). In this case, connect LEDA to 3.3V through a resistor, LEDK to GND, and the SPI pins as before. The MISO pin (pin 10) is optional—leave it unconnected if not used.
Testing the Wiring
After wiring, upload a simple test sketch to verify the display works. Use the Adafruit ST7735 library’s example “graphicstest” or the TFT_eSPI “TFT_SPIFFS_BMP” example. The display should show a color bar pattern, text, and shapes. If the display remains blank, check the backlight: measure the voltage at the BL pin—it should be 3.3V or a PWM signal. If the backlight is on but no image, check the SPI connections with an oscilloscope or logic analyzer. The CS pin should go low when the library sends data, and the SCK should have a clean square wave. The DC pin should toggle between high and low during initialization. If the display shows random pixels, the initialization sequence might be wrong—ensure the library is set to the ST7735S driver, not the ST7735R or ST7735B. The ST7735S has a different command set for the gamma correction and display window. The resolution is 128x160, but some libraries default to 128x128—you need to set the correct width and height in the library. The display’s offset is zero for both axes, so no adjustment is needed. If the colors are inverted, check the MADCTL register—the RGB order might be swapped (e.g., BGR instead of RGB). In TFT_eSPI, set #define TFT_INVERSION_ON or #define TFT_RGB_ORDER TFT_BGR in the setup file. The display’s refresh rate can be increased by using the setSwapBytes