How to use a 1.77 inch TFT display with NodeMCU?

To use a 1.77 inch TFT display with NodeMCU, you need to connect the display’s SPI pins to the NodeMCU’s hardware SPI pins and upload a compatible library, like the Adafruit ST7735 or TFT_eSPI, to drive the 128x160 pixel resolution. The specific model often uses the ST7735S controller, which communicates over a 4-wire SPI interface. Start by wiring the display’s CS (chip select) to NodeMCU’s D8 (GPIO15), DC (data/command) to D4 (GPIO2), RESET to D3 (GPIO0), SDA (MOSI) to D7 (GPIO13), SCL (SCLK) to D5 (GPIO14), VCC to 3.3V, and GND to ground. The backlight LED pin typically connects to 3.3V through a 100-ohm resistor to limit current to around 20mA, though some modules have a built-in resistor. The NodeMCU’s 3.3V output can supply up to 600mA, which is sufficient since the display draws about 80mA with backlight on. The 1.77 inch 128x160 tft display uses the ST7735S driver, which supports 262K colors (18-bit RGB) and a 132x162 pixel active area, but the visible resolution is 128x160 pixels with a 1.77-inch diagonal (28.03mm x 35.04mm). The SPI clock frequency can go up to 24MHz, but NodeMCU’s ESP8266 runs at 80MHz, so you should set the SPI speed to 20MHz in code to avoid signal degradation. The display’s datasheet specifies a typical response time of 15ms, refresh rate of 60Hz, and viewing angle of 12 o’clock (6 o’clock is typical for TN panels). For power, the display operates at 2.8V to 3.3V, and the logic input high level is 0.7*VCC (about 2.31V at 3.3V), which is compatible with NodeMCU’s 3.3V logic. The NodeMCU’s GPIO pins output 3.3V, but the ESP8266’s GPIO pins are not 5V tolerant, so avoid connecting to 5V sources. The display’s SPI interface uses 4 lines: CS, DC, SDA, and SCL, plus the reset line. Some libraries, like TFT_eSPI, allow you to configure these pins in a user setup file, where you define TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, and TFT_BL (optional). For example, in TFT_eSPI’s User_Setup.h, you can set: #define TFT_CS 15, #define TFT_DC 2, #define TFT_RST 0, #define TFT_MOSI 13, #define TFT_SCLK 14. The library supports 8-bit and 16-bit color modes, but for 128x160, you’ll use 16-bit (RGB565) to reduce memory usage. The frame buffer for a full 128x160 image at 16-bit color requires 128*160*2 = 40,960 bytes, which fits within the NodeMCU’s 80KB of user RAM (the ESP8266 has 160KB of RAM total, but 80KB is available for user data). The display’s pixel format is RGB565, meaning each pixel uses 2 bytes (5 bits red, 6 bits green, 5 bits blue). The ST7735S supports rotation, with 0, 1, 2, 3 corresponding to portrait and landscape orientations. The display’s visible area starts at column offset 2 and row offset 1 (for the 132x162 panel), so you need to set the column and row address in the initialization sequence. The typical initialization sequence includes commands like SWRESET (0x01), SLPOUT (0x11), COLMOD (0x3A) set to 0x05 (16-bit color), DISPON (0x29), and MADCTL (0x36) for orientation. The display’s datasheet lists the command set, including CASET (0x2A) for column address and RASET (0x2B) for row address. The SPI transaction must be done with the correct mode (mode 0: CPOL=0, CPHA=0). The NodeMCU’s hardware SPI uses mode 0 by default, but you can set it in code with SPI.setDataMode(SPI_MODE0). The clock polarity and phase are critical: the ST7735S expects data to be latched on the rising edge of SCL. The display’s maximum SPI clock is 24MHz, but the ESP8266’s SPI clock divider can be set to 4 (80MHz/4=20MHz) or 2 (40MHz), but 20MHz is safer for signal integrity. The wiring distance between the NodeMCU and display should be under 10cm to avoid signal reflections. Use short jumper wires, preferably under 5cm, and avoid running them near high-current lines like the USB power line. The display’s backlight LED typically has a forward voltage of 3.0V at 20mA, so a 100-ohm resistor in series with the 3.3V supply drops 0.3V, giving 3.0V across the LED. Some modules have a transistor driver for the backlight, but if not, you can control it with a PWM pin on NodeMCU (e.g., D1, GPIO5) to adjust brightness. The PWM frequency should be around 1kHz to avoid flicker. The NodeMCU’s PWM is software-based, but it works fine for backlight control. The display’s operating temperature range is -20°C to +70°C, which is typical for consumer electronics. The ST7735S driver IC has a built-in voltage generator for the LCD bias, so you don’t need external components. The display’s interface is 3.3V only, so no level shifting is needed. The NodeMCU’s GPIO pins are 3.3V, but the ESP8266’s maximum output current per pin is 12mA, so do not draw more than that from any pin. The display’s logic pins draw less than 1mA each, so it’s safe. The SPI bus can be shared with other devices, but you need separate CS lines. For example, if you have an SD card module, you can use the same MOSI, MISO, SCLK lines, but different CS. The display’s MISO pin is not used in 4-wire SPI (it’s 3-wire plus DC), but some modules have a MISO pin for readback, which you can leave unconnected. The NodeMCU’s hardware SPI pins are fixed: MOSI on D7 (GPIO13), MISO on D6 (GPIO12), SCLK on D5 (GPIO14). You cannot change these for hardware SPI, but you can use software SPI with any pins (e.g., using the Adafruit library’s software SPI constructor). However, software SPI is slower (around 4MHz max) and uses more CPU cycles. Hardware SPI is recommended for better performance. The display’s initialization sequence in the Adafruit ST7735 library includes a specific set of commands for the 1.77-inch variant. The library has a constructor like Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); where you pass the pin numbers. The library automatically handles the reset sequence. The TFT_eSPI library is faster because it uses direct register access and optimized SPI writes. For example, the TFT_eSPI library can push pixels at up to 20MHz, giving a theoretical frame rate of 20MHz / (128*160*2 bytes) = 488 frames per second, but in practice, the library overhead and the ESP8266’s CPU speed limit it to around 30-60 FPS for simple graphics. The display’s response time of 15ms means it can show up to 66 FPS, so the NodeMCU is not the bottleneck. The display’s gamma correction is built into the ST7735S, with default gamma curves that can be adjusted via commands like GMCTRP1 (0xE0) and GMCTRN1 (0xE1). The typical color accuracy is 60% NTSC, which is lower than IPS panels, but acceptable for basic graphics. The display’s contrast ratio is around 500:1, typical for TN panels. The viewing angle is narrow: 6 o’clock is best, and 12 o’clock is worst. The display’s brightness is typically 250 cd/m² with backlight at full current. The NodeMCU can drive the display with a simple sketch that draws shapes, text, or images. For images, you need to convert them to 16-bit RGB565 format. The TFT_eSPI library has a function to draw JPEG images from SPIFFS or SD card, but the NodeMCU’s flash memory (4MB) can store images. The SPIFFS file system can be used to store bitmap files. The display’s resolution is 128x160, so a full-screen image is 40KB. The NodeMCU’s flash memory has 3MB available for SPIFFS after the firmware, so you can store many images. The display’s pixel clock is 24MHz, but the ESP8266’s SPI clock is limited to 20MHz for stability. The display’s datasheet specifies the timing requirements: CS must be low for the entire transaction, DC must be set before the first byte, and data is latched on the rising edge of SCL. The minimum SCL high and low times are 40ns each, so the maximum clock period is 80ns, which is 12.5MHz, but the datasheet says 24MHz is typical, so the 20MHz clock (50ns period) is within spec. The display’s power consumption is 80mA with backlight on, 20mA without backlight. The NodeMCU’s 3.3V regulator can supply up to 600mA, so it’s fine. The display’s backlight can be controlled with a PWM pin to save power. For battery-powered projects, you can turn off the backlight when not in use. The display’s sleep mode (SLPIN command) reduces current to 0.1mA. The NodeMCU’s deep sleep mode (80µA) combined with the display’s sleep mode can give long battery life. The display’s driver IC supports partial display mode, where you can update only a portion of the screen to save power. The NodeMCU’s WiFi module can be used to fetch data from the internet and display it. For example, you can display weather data, stock prices, or sensor readings. The display’s SPI interface is fast enough for real-time updates. The library’s text rendering uses a 5x7 font, but you can use custom fonts for better readability. The display’s pixel size is 0.22mm, so text at 8pt is readable. The display’s color depth is 262K, but the NodeMCU’s library uses 16-bit color, which gives 65,536 colors. The difference is noticeable for gradients. The display’s gamma correction can be adjusted to improve color reproduction. The typical gamma curve is set to 2.2. The display’s response time of 15ms is fast enough for animations. The display’s refresh rate of 60Hz is standard. The NodeMCU’s SPI driver uses DMA for some operations, but the ESP8266’s SPI controller is simple. The TFT_eSPI library uses a technique called “SPI transaction” to ensure atomic operations. The display’s initialization sequence must be sent in the correct order: reset, sleep out, color mode, display on. The reset pin is active low, so you need to pull it low for at least 10ms, then high. The NodeMCU’s GPIO0 is used as the reset pin, but it’s also the boot mode pin. During boot, GPIO0 must be high to run the sketch. If you use GPIO0 as reset, you need to ensure it’s not pulled low during boot. The display’s reset pin is typically connected to NodeMCU’s D3 (GPIO0), but you can use any other GPIO, like D1 (GPIO5), to avoid boot issues. The display’s CS pin is active low, so you need to pull it low to select the display. The NodeMCU’s D8 (GPIO15) is used as CS, but GPIO15 must be low during boot to enter normal mode. If you use GPIO15 as CS, you need to ensure it’s high during boot, which is not the case. So, use a different pin for CS, like D2 (GPIO4). The typical wiring: CS to D2 (GPIO4), DC to D4 (GPIO2), RST to D1 (GPIO5), MOSI to D7 (GPIO13), SCLK to D5 (GPIO14), VCC to 3.3V, GND to GND, BL to 3.3V via 100 ohm. This avoids conflicts with boot pins. The NodeMCU’s D4 (GPIO2) is also used for the onboard LED, but it’s fine to use it for DC. The display’s library requires you to define the pin numbers correctly. The TFT_eSPI library’s User_Setup.h file has a section for the ST7735 driver. You need to set the driver to ST7735_DRIVER, and define the pin numbers. The library also has a function to set the rotation, which changes the MADCTL register. The display’s visible area is 128x160, but the panel is 132x162. The library handles the offset automatically if you set the correct driver. The Adafruit library has a specific constructor for the 1.8-inch display, but the 1.77-inch uses the same driver. The initialization sequence in the Adafruit library includes a function initB() for the 1.8-inch, but for the 1.77-inch, you might need to use initR(INITR_BLACKTAB) or similar. The TFT_eSPI library has a built-in initialization for the ST7735 with the correct offsets. You can check the library’s documentation for the exact parameters. The display’s SPI speed can be set in the library. In TFT_eSPI, you can set #define SPI_FREQUENCY 20000000 to 20MHz. The library also supports 80MHz, but it’s not recommended for long wires. The display’s backlight can be controlled with a PWM pin. In the library, you can set #define TFT_BL 5 for the backlight pin. The library then handles the PWM automatically. The NodeMCU’s PWM frequency is 1kHz, which is fine for backlight. The display’s brightness can be adjusted with analogWrite(pin, value) where value is 0-1023. The display’s power consumption is 80mA at full brightness, 20mA at 0 brightness. The display’s sleep mode can be triggered with the command 0x10. The library has a function tft.sleep() to put the display to sleep. The display’s wake-up command is 0x11. The library also has a function tft.wakeup(). The display’s temperature range is -20 to 70°C, so it’s not suitable for extreme environments. The display’s humidity tolerance is 60% RH. The display’s storage temperature is -30 to 80°C. The display’s module has a 4-pin header for SPI, but some modules have a 6-pin header with backlight control. The pinout is usually labeled on the back. The display’s PCB has mounting holes for M2 screws. The display’s dimensions are 34.5mm x 47.5mm x 3.5mm. The display’s weight is 8g. The display’s connector is a 0.5mm pitch FPC, but the module has a breakout board. The NodeMCU’s board dimensions are 48mm x 26mm, so it’s a good match. The display’s interface is 3.3V, so you can power it from the NodeMCU’s 3.3V pin. The NodeMCU’s input voltage is 5V via USB, but the 3.3V regulator can supply up to 600mA. The display’s current draw is 80mA, so it’s safe. The NodeMCU’s WiFi module draws 80mA in active mode, so total current is 160mA, which is within the USB 500mA limit. The display’s backlight can be turned off to save power. The NodeMCU’s deep sleep mode draws 80µA, and the display’s sleep mode draws 0.1mA, so total is 0.18mA, which is good for battery projects. The display’s SPI interface is fast enough for video, but the NodeMCU’s RAM is limited. The display’s 128x160 resolution at 16-bit color requires 40KB per frame. The NodeMCU’s RAM is 80KB, so you can buffer one frame. For video, you need to stream frames from SPIFFS or SD card. The SPIFFS read speed is around 1MB/s, so you can read a 40KB frame in 40ms, giving 25 FPS. The display’s write speed is 20MHz, so 40KB takes 16ms. Total time per frame is 56ms, giving 18 FPS. This is acceptable for simple animations. The display’s color depth is 16-bit, which is good for photos. The display’s contrast ratio is 500:1, so blacks are not pure black. The display’s viewing angle is narrow, so you need to view it from the front. The display’s surface is glossy, so it reflects light. The display’s polarizer is linear, so you can use it with polarized sunglasses. The display’s driver IC supports 8-bit and 9-bit SPI modes,

Back to Blog