1.8 TFT Display (ST7735)
The 1.8 TFT display is a 128 x 160 pixel color LCD module based on the ST7735 driver IC. It communicates over SPI and supports 65K colors (16-bit RGB565), making it suitable for displaying text, graphics, bitmaps, and basic user interfaces in embedded projects. The display includes an SD card slot on the back (using a separate SPI bus).
For this interfacing you need the following components:
- Arduino board (Uno, Nano, Mega, etc.)
- 1.8 TFT display module (ST7735, 128 x 160)
- Breadboard and jumper wires
- USB cable to connect Arduino to your computer
- (Optional) MicroSD card for image storage
Schematic
Connect the 1.8 TFT display to the Arduino as follows:
TFT Display Arduino
----------- -------
VCC --> 5V (or 3.3V)
GND --> GND
CS --> Digital Pin 10
RESET --> Digital Pin 9
DC (A0) --> Digital Pin 8
MOSI (SDA) --> Digital Pin 11 (MOSI)
SCK (SCL) --> Digital Pin 13 (SCK)
LED --> 3.3V (or PWM pin for brightness control)
The LED pin controls the backlight. Connect it to 3.3V for full brightness or to a PWM-capable pin for adjustable brightness.
Pin Map
| TFT Pin | Name | Arduino Connection |
|---|---|---|
| VCC | Power | 5V (or 3.3V β check module specs) |
| GND | Ground | GND |
| CS | Chip Select | Pin 10 (SS) |
| RESET | Reset | Pin 9 |
| DC (A0) | Data / Command | Pin 8 |
| MOSI (SDA) | SPI Data | Pin 11 (MOSI on Uno/Nano) |
| SCK (SCL) | SPI Clock | Pin 13 (SCK on Uno/Nano) |
| LED | Backlight | 3.3V (or PWM pin) |
For Mega 2560: MOSI = Pin 51, SCK = Pin 52, SS = Pin 53. For Leonardo: MOSI = ICSP-4, SCK = ICSP-3, CS = any digital pin.
Backlight brightness control
For adjustable backlight, connect the LED pin to a PWM-capable pin and use analogWrite():
analogWrite(backlightPin, 128); // 0 = off, 255 = full brightness
SD card slot
The displayβs SD card slot uses a separate SPI bus with its own CS pin (typically pin 4 on the module). MOSI, SCK, and GND are shared with the display.
Install necessary Library
Install the following libraries via the Library Manager (Tools > Manage Libraries):
- Adafruit ST7735 Library by Adafruit
- Adafruit GFX Library by Adafruit (required dependency)
Alternatively, using arduino-cli:
arduino-cli lib install "Adafruit ST7735 Library"
arduino-cli lib install "Adafruit GFX Library"
Code with complete explanation
This sketch demonstrates drawing shapes, text, colors, and bitmaps on the 1.8 TFT display using the Adafruit GFX library.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup()
{
Serial.begin(9600);
Serial.println("1.8 TFT Display Test");
tft.initR(INITR_BLACKTAB); // Initialize for ST7735S (black tab)
// tft.initR(INITR_REDTAB); // Use this variant if display has a red tab
tft.fillScreen(ST77XX_BLACK);
// Text demo
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(1);
tft.setCursor(10, 10);
tft.println("Hello, World!");
tft.setTextColor(ST77XX_CYAN);
tft.setTextSize(2);
tft.setCursor(10, 30);
tft.println("Arduino");
delay(2000);
tft.fillScreen(ST77XX_BLACK);
delay(500);
// Shape demo
drawShapes();
delay(2000);
tft.fillScreen(ST77XX_BLACK);
delay(500);
// Color bars
drawColorBars();
delay(2000);
tft.fillScreen(ST77XX_BLACK);
delay(500);
// Lines and arcs
drawLines();
}
void loop()
{
// Nothing in loop β run setup once
}
void drawShapes()
{
// Filled rectangle (red)
tft.fillRect(10, 10, 60, 40, ST77XX_RED);
// Filled circle (green)
tft.fillCircle(120, 30, 20, ST77XX_GREEN);
// Filled triangle (blue)
tft.fillTriangle(30, 100, 10, 140, 50, 140, ST77XX_BLUE);
// Filled rounded rectangle (yellow)
tft.fillRoundRect(70, 90, 50, 50, 8, ST77XX_YELLOW);
// Outlined shapes
tft.drawRect(10, 10, 60, 40, ST77XX_WHITE);
tft.drawCircle(120, 30, 20, ST77XX_WHITE);
tft.drawTriangle(30, 100, 10, 140, 50, 140, ST77XX_WHITE);
tft.drawRoundRect(70, 90, 50, 50, 8, ST77XX_WHITE);
}
void drawColorBars()
{
int barWidth = tft.width() / 8;
tft.fillRect(0 * barWidth, 0, barWidth, 30, ST77XX_RED);
tft.fillRect(1 * barWidth, 0, barWidth, 30, ST77XX_GREEN);
tft.fillRect(2 * barWidth, 0, barWidth, 30, ST77XX_BLUE);
tft.fillRect(3 * barWidth, 0, barWidth, 30, ST77XX_YELLOW);
tft.fillRect(4 * barWidth, 0, barWidth, 30, ST77XX_CYAN);
tft.fillRect(5 * barWidth, 0, barWidth, 30, ST77XX_MAGENTA);
tft.fillRect(6 * barWidth, 0, barWidth, 30, ST77XX_ORANGE);
tft.fillRect(7 * barWidth, 0, barWidth, 30, ST77XX_WHITE);
}
void drawLines()
{
for (int i = 0; i < tft.width(); i += 10)
{
tft.drawLine(0, 0, i, tft.height() - 1, ST77XX_RAINBOW);
}
for (int i = 0; i < tft.height(); i += 10)
{
tft.drawLine(0, 0, tft.width() - 1, i, ST77XX_RAINBOW);
}
}
Code breakdown
#include <Adafruit_ST7735.h>β provides the low-level ST7735 driver functions.#include <Adafruit_GFX.h>β provides the high-level graphics primitives (shapes, text, fonts).Adafruit_ST7735 tft(CS, DC, RST)β creates a TFT object with the specified SPI control pins.tft.initR(INITR_BLACKTAB)β initializes the display. The parameter selects the tab color variant:INITR_BLACKTABfor the newer ST7735S orINITR_REDTAB/INITR_GREENTABfor older modules. If colors are inverted or the display doesnβt respond, try a different tab.tft.fillScreen(color)β fills the entire screen with a single color.tft.setTextColor(color)β sets the text foreground color.tft.setTextSize(size)β sets the text size multiplier (1 = 6x8 pixel font, 2 = 12x16, etc.).tft.setCursor(x, y)β positions the text cursor at (x, y) in pixels.tft.println(text)β prints text at the cursor position and advances to the next line.tft.fillRect(x, y, w, h, color)β draws a filled rectangle at (x, y) with width w and height h.tft.fillCircle(x, y, r, color)β draws a filled circle centered at (x, y) with radius r.tft.fillTriangle(x1,y1, x2,y2, x3,y3, color)β draws a filled triangle.tft.fillRoundRect(x, y, w, h, radius, color)β draws a filled rectangle with rounded corners.tft.drawLine(x1, y1, x2, y2, color)β draws a line between two points.tft.width()/tft.height()β returns the display width (128) and height (160) in pixels.
Color constants
| Constant | RGB565 Value |
|---|---|
ST77XX_BLACK | 0x0000 |
ST77XX_WHITE | 0xFFFF |
ST77XX_RED | 0xF800 |
ST77XX_GREEN | 0x07E0 |
ST77XX_BLUE | 0x001F |
ST77XX_CYAN | 0x07FF |
ST77XX_MAGENTA | 0xF81F |
ST77XX_YELLOW | 0xFFE0 |
ST77XX_ORANGE | 0xFC00 |
Using custom 16-bit colors
// Define a custom color using RGB565 macro
#define MY_PURPLE tft.Color565(128, 0, 128) // R, G, B (0-255 each)
tft.fillRect(0, 0, 50, 50, MY_PURPLE);
Displaying a bitmap
To display a bitmap stored in PROGMEM:
#include <Adafruit_GFX.h>
// 16-bit (RGB565) bitmap data, 32 x 32 pixels
const uint16_t logo[] PROGMEM = {
0xFFFF, 0xF800, 0xF800, /* ... */ // pixel data here
};
void drawBitmap()
{
tft.drawRGBBitmap(10, 10, logo, 32, 32); // x, y, bitmap, width, height
}
Steps to perform this interfacing
- Connect the 1.8 TFT display to the Arduino as shown in the schematic.
- Install the Adafruit ST7735 Library and Adafruit GFX Library via the Library Manager.
- Copy the code into the Arduino IDE.
- If your display has a red tab on the flex cable, change
INITR_BLACKTABtoINITR_REDTAB. For green tabs, useINITR_GREENTAB. - Select the correct board and port (
Tools > BoardandTools > Port). - Upload the sketch to the Arduino.
- Observe the display β it will show text (βHello, World!β), then shapes (rectangles, circles, triangles), then color bars, and finally line patterns.
- If colors appear inverted or the display is blank, try a different
initR()parameter.
Caution
- Init tab variant: The 1.8 TFT displays have different driver variants (ST7735B, ST7735R, ST7735S). If the display shows nothing or garbled content, try
INITR_BLACKTAB,INITR_REDTAB, orINITR_GREENTABintft.initR(). Some modules may requiretft.initR(INITR_144GREENTAB)or manual initialization withtft.init(SPI, ...). - Voltage: Most 1.8 TFT modules have an onboard 3.3V regulator and can accept 5V on VCC. However, the logic pins (CS, DC, MOSI, SCK) are 3.3V-only. On 5V Arduino boards, use a voltage divider (2.2kΞ© + 3.3kΞ©) on each control pin, or use a 3.3V Arduino board. Some modules include level shifters β check your module specs.
- Backlight current: The LED pin can draw 20β40 mA. Do not connect it directly to a 5V pin without a current-limiting resistor (use 3.3V or a 100Ξ© series resistor to 5V).
- SPI speed: The default SPI speed (4 MHz) works reliably. Higher speeds (8β16 MHz) may cause display artifacts on long wires. If you see glitches, reduce SPI speed in the library or use shorter wires.
- SD card interference: The SD card slot shares MOSI, SCK, and GND with the display. If you are not using the SD card, leave its CS pin disconnected (not floating β pull it HIGH with a 10kΞ© resistor or set it as an output HIGH).
- Heap memory: The Adafruit GFX library uses RAM for the frame buffer only if you create a buffer. Without a buffer (~40 KB for 128x160 RGB565), drawing is direct to the screen. Calling too many drawing functions in rapid succession may cause latency on slower Arduino boards (Uno/Nano).
- Display orientation: Use
tft.setRotation(n)(0β3) to change between portrait and landscape orientations. Rotation 1 and 2 are landscape; 0 and 3 are portrait.