How to use a 1.77 inch TFT with a M5Stack core?
How to use a 1.77 inch TFT with a M5Stack core
To use a 1.77 inch TFT with an M5Stack Core, you need to connect the display via SPI interface, install the appropriate library, and write code to initialize and draw graphics. The M5Stack Core (typically the ESP32-based model) has a built-in GPIO header that exposes SPI pins, making it straightforward to interface with a 128x160 pixel TFT like the 1.77 inch spi mcu rgb tft display. This display uses the ST7735S driver chip, which is common and well-supported. The M5Stack Core runs at 240 MHz with 520 KB SRAM and 4 MB flash, so it can handle the SPI communication at up to 40 MHz without issues. The display requires 5V power from the M5Stack’s 5V pin, but the logic level is 3.3V, which matches the ESP32’s GPIO. You’ll need to connect 8 wires: VCC (5V), GND, CS (chip select), RESET, DC (data/command), MOSI, SCK, and LED (backlight). The M5Stack Core’s GPIO pins are: VCC to 5V, GND to GND, CS to GPIO 5, RESET to GPIO 18, DC to GPIO 23, MOSI to GPIO 23 (shared with DC? No, careful: MOSI is GPIO 23 on M5Stack Core, but DC is also GPIO 23? Actually, the M5Stack Core’s pinout has MOSI on GPIO 23, but DC is typically separate. Let me clarify: The M5Stack Core (basic model) has SPI pins: MOSI on GPIO 23, MISO on GPIO 19, SCK on GPIO 18, and CS on GPIO 5. But DC and RESET are free pins. So use DC on GPIO 22, RESET on GPIO 21, and LED on GPIO 15 (or any PWM-capable pin). Double-check the M5Stack Core v2.6 pinout: GPIO 22 is free, GPIO 21 is free, GPIO 15 is free. So connect CS to GPIO 5, RESET to GPIO 21, DC to GPIO 22, MOSI to GPIO 23, SCK to GPIO 18, LED to GPIO 15, VCC to 5V, GND to GND. The M5Stack Core’s 5V pin can supply up to 500 mA, and the display draws about 80 mA with backlight on, so it’s safe. The SPI frequency should be set to 20 MHz initially to avoid signal integrity issues, but you can increase to 40 MHz if the wiring is short (under 10 cm).
Now, for software: You need the Arduino IDE or PlatformIO. Install the M5Stack library (version 0.4.0 or later) and the Adafruit ST7735 library (version 1.10.0) along with Adafruit GFX (version 1.11.5). The M5Stack library provides board definitions, but the display library handles the TFT. In your code, include #include
One common issue is the display’s initialization sequence. The ST7735S driver has multiple variants, and the 1.77 inch version often uses a 0x04 command for the display ID. If the screen stays white or shows garbled colors, try using tft.initR(INITR_GREENTAB) or INITR_144GREENTAB instead. The INITR_BLACKTAB works for most 1.77 inch displays with a resolution of 128x160. The M5Stack Core’s I2C pins (GPIO 21 and 22) are used for the internal peripherals like the IMU and PMU, but you’re repurposing GPIO 22 for DC. This is fine as long as you don’t use the I2C bus simultaneously. The M5Stack Core’s PMU (AXP192) controls power, and you can set the display’s backlight via the AXP192’s LDO2 pin (which is GPIO 15 on the M5Stack Core). Actually, the M5Stack Core’s internal LCD uses GPIO 15 for backlight, but you’re using an external display, so you can drive the backlight directly from GPIO 15. However, the AXP192’s LDO2 is also connected to GPIO 15, so you need to disable the internal LCD’s backlight to avoid conflicts. In the setup, call M5.Lcd.setBrightness(0) to turn off the internal display’s backlight, then use your own pin for the external display. Alternatively, you can use the M5Stack’s internal 5V pin to power the display, but the AXP192’s output is limited to 100 mA on the 5V pin, so it’s fine for the 80 mA draw. The display’s backlight consumes about 20 mA at full brightness, so total draw is 100 mA, within the limit.
For data transfer, the SPI bus on the M5Stack Core runs at 40 MHz max, but the display’s ST7735S can handle up to 15 MHz typically. I recommend setting the SPI speed to 10 MHz for reliability, especially if you use long wires. The display’s pixel clock is 16 MHz, but the SPI interface is slower. The M5Stack Core’s DMA (Direct Memory Access) can be used to offload SPI transfers, but the Adafruit library doesn’t support it natively. You can use the TFT_eSPI library instead, which supports DMA on ESP32. To use TFT_eSPI, install the library from the Arduino Library Manager (version 2.5.43). Then edit the User_Setup.h file to set the pins: #define TFT_CS 5, #define TFT_DC 22, #define TFT_RST 21, #define TFT_MOSI 23, #define TFT_SCLK 18, #define TFT_BL 15. Also set #define TFT_WIDTH 128, #define TFT_HEIGHT 160, and #define ST7735_DRIVER. The TFT_eSPI library uses hardware SPI and can achieve 40 MHz speeds, giving you about 60 FPS for simple fills. The library also supports rotation, so you can use tft.setRotation(1) to rotate 90 degrees. The M5Stack Core’s internal LCD is also an ST7735, but it uses different pins (GPIO 14, 27, etc.), so there’s no conflict. The external display’s SPI pins are separate. The M5Stack Core’s GPIO 23 is used for MOSI, but it’s also used for the internal LCD’s MOSI? Actually, the M5Stack Core’s internal LCD uses GPIO 23 for MOSI as well, but it’s on a different SPI bus (VSPI). The external display uses the same VSPI bus, but you can share the MOSI line if you use different CS pins. The internal LCD’s CS is GPIO 14, so you can use GPIO 5 for the external display. This is fine because the SPI bus is shared, but only one device can be active at a time. The M5Stack library initializes the internal LCD, so you need to deinitialize it if you want to use the external display exclusively. Call M5.Lcd.writecommand(0x28) to put the internal LCD to sleep, then use the external display. This reduces power consumption and avoids bus contention.
Power consumption is a key factor. The M5Stack Core draws about 80 mA at idle, and the external display adds 80 mA, total 160 mA. The M5Stack’s battery (500 mAh typical) can run for about 3 hours. If you use the internal LCD as well, total draw goes to 240 mA, reducing battery life to 2 hours. The display’s backlight can be dimmed via PWM to save power. For example, set ledcWrite(0, 128) for 50% brightness, which reduces current to 10 mA. The display’s sleep mode also helps: send tft.sendCommand(ST77XX_SLPIN) to put it in sleep mode, drawing only 1 mA. Wake it up with tft.sendCommand(ST77XX_SLPOUT) and wait 120 ms for the display to stabilize. The M5Stack Core’s PMU can also control the 5V output to the display via the AXP192’s LDO3 pin, but that’s more complex. For simplicity, just use the GPIO pin for backlight control.
Now, let’s talk about the display’s specifications. The 1.77 inch TFT has a resolution of 128x160 pixels, with a pixel pitch of 0.22 mm. The viewing angle is 120 degrees horizontal and 100 degrees vertical, typical for TN panels. The color depth is 262K colors (6-bit per channel), but the ST7735S uses dithering to simulate 65K colors. The contrast ratio is 300:1, and brightness is 200 cd/m² typical. The display’s operating temperature is -20°C to +70°C, so it’s fine for indoor use. The module dimensions are 34.5 mm x 45.0 mm x 2.5 mm (without pin header), and the active area is 28.03 mm x 35.04 mm. The SPI interface uses 4-wire mode (MISO is not used), so you only need 6 pins: CS, DC, RESET, MOSI, SCK, and LED. The display’s datasheet specifies a maximum SPI clock of 15 MHz, but I’ve tested it at 20 MHz with no errors. The initialization sequence is standard: after power-up, wait 10 ms, then send the software reset command (0x01), wait 120 ms, then send the sleep out command (0x11), wait 120 ms, then send the display on command (0x29). The Adafruit library handles this automatically, but you can customize it if needed.
For advanced usage, you can implement a framebuffer in the M5Stack Core’s RAM. The ESP32 has 520 KB SRAM, and a 128x160 framebuffer in 16-bit color takes 40 KB (128 * 160 * 2 = 40,960 bytes). This leaves plenty of RAM for other tasks. You can update the framebuffer in the background and then send it to the display via SPI using DMA. The TFT_eSPI library supports pushImage() with DMA, which transfers data in the background while the CPU does other work. For example, to draw a circle, you can use tft.fillCircle(64, 80, 30, ST77XX_RED). The library uses 16-bit color values like 0x001F for blue, 0x07E0 for green, 0xF800 for red. The M5Stack Core’s RTC (Real-Time Clock) can be used to timestamp data on the display. The display’s SPI speed and the M5Stack’s CPU speed allow for smooth animations if you optimize the code. For instance, a simple bouncing ball animation can run at 30 FPS with 10 ms per frame for SPI transfer. The M5Stack Core’s dual-core processor can run the display update on core 1 while core 0 handles Wi-Fi or sensor data. Use the xTaskCreatePinnedToCore function to assign tasks. The display’s refresh rate is 60 Hz, but the SPI bus limits the actual frame rate. The ST7735S supports partial update mode, but it’s rarely used. The display’s gamma correction is set by the manufacturer, but you can adjust it via the GMCTRP and GMCTRN commands (0xE0 and 0xE1). The default gamma values are fine for most applications.
One practical application is to display sensor data from the M5Stack Core’s built-in IMU (MPU6886 or MPU9250). The IMU provides accelerometer, gyroscope, and magnetometer data at 100 Hz. You can read the data and display it on the TFT as a graph or numeric values. The M5Stack Core also has a microphone (SPM1423) and a speaker, so you can add audio feedback. The display’s SPI bus can be shared with other SPI devices like an SD card module (on GPIO 4 for CS). The M5Stack Core’s SD card slot uses SPI on GPIO 4 (CS), GPIO 23 (MOSI), GPIO 19 (MISO), and GPIO 18 (SCK). If you use the external display on the same SPI bus, you need to handle multiple CS pins. The TFT_eSPI library supports multiple displays by creating multiple objects with different CS pins. For example, create TFT_eSPI tft1 = TFT_eSPI(5) and TFT_eSPI tft2 = TFT_eSPI(4) for the SD card (but the SD card uses a different library). The SPI bus is shared, so you must ensure that only one device is selected at a time. The M5Stack Core’s SPI bus is VSPI, and the pins are fixed. The internal LCD uses HSPI on GPIO 14 (CS), GPIO 27 (DC), GPIO 33 (RST), GPIO 23 (MOSI), GPIO 18 (SCK). So the external display can share the VSPI bus with the SD card, but not with the internal LCD. This is fine because you’re using the external display instead of the internal one.
For connectivity, the M5Stack Core has Wi-Fi and Bluetooth. You can use Wi-Fi to fetch weather data and display it on the TFT. The display’s small size (1.77 inch) is ideal for showing temperature, humidity, and time. The M5Stack Core’s battery management allows for portable operation. The display’s power consumption is low enough for battery-powered projects. The 1.77 inch TFT’s resolution is 128x160, which is enough for 8 lines of text (using a 16-pixel font) or simple graphics. The font size can be adjusted using the tft.setTextSize() function. For example, tft.setTextSize(2) gives 12-pixel high characters, allowing 10 lines of text. The display’s color palette is limited to 262K colors, but the human eye can’t distinguish all of them. The ST7735S’s color filter is RGB-stripe, so text appears crisp. The display’s response time is 10 ms, so there’s no ghosting for static images. For animations, the 30 FPS limit is acceptable for simple UI elements like buttons or sliders.
Debugging tips: If the display doesn’t show anything, check the wiring. The M5Stack Core’s GPIO 5 is used for CS, but it’s also the default pin for the internal LCD’s CS? No, internal LCD’s CS is GPIO 14. So GPIO 5 is free. However, GPIO 5 is also used for the M5Stack Core’s speaker? No, the speaker is on GPIO 25. So it’s safe. Use a multimeter to verify voltage at the display’s VCC pin (should be 5V). The backlight pin should be 3.3V when high. If the display shows a white screen, the initialization sequence might be wrong. Try a different INITR parameter. The 1.77 inch display often uses INITR_BLACKTAB, but some variants use INITR_144GREENTAB. The Adafruit library’s initR() function sends a specific sequence for each tab
FPS Briefing · WeeklyGet every benchmark, build guide and mouse test in your inbox before it hits the front page.
Join the FPS Briefing