Using the 1.44″ TFT ST7735 Color display with Arduino.

tft st7735 display with arduino

A number of display devices like LEDs, 7-segments, character and graphic displays can be attached to microcontrollers to create an interface between the user and an electronic system for displaying data or controlling the system. Sometimes you may need to add colorful images or graphics to your project, that’s where the TFT color displays come in handy.

ST7735 TFT display description.

TFT LCD is a variant of a liquid-crystal display (LCD) that uses thin-film-transistor (TFT) technology to improve image qualities such as addressability and contrast. In this tutorial we are going to show how to interface a 1.44″ TFT color display based on the ST7735 driver. It has 128×128 color pixels and can display full 16-bit color.

The display uses 4-wire SPI to communicate and has its own pixel-addressable frame buffer, it can be used with every kind of microcontroller.

Connecting TFT display to Arduino.

tft st7735 display

This is the type of display am using but they come with various pin configurations. However all the displays will have the major pins stated below and should be connected to the Arduino board as follows:
SCK to  Digital pin 13
SDA to  Digital pin 11
DC   to  Digital pin 9
Reset to  Digital pin 8
CS  to  Digital pin 10
GND to Arduino GND
VCC  to Arduino 3.3V

This TFT display uses 3.3V but comes with an on board voltage regulator therefore the VCC can be connected to the Arduino 5V. However for best practice it’s better to use the 3.3V.

Most code Libraries for this TFT ST7735 display with Arduino are programmed with the SDA and SCL pins connected to Arduino pins 11 and 13 respectively. Make sure you don’t change that order otherwise the display may not work.

tft st7735 display with arduino schematic

Code for running the ST7735 TFT Display.

There are a number of libraries that have been developed to run the TFT ST7735 color display using Arduino but I found the Adafruit-ST7735-Library the best to use. Make sure you have this library installed in your IDE.

Basic commands.

Most TFT libraries have been programmed to support the following commands:

  • tft.fillScreen();This function is for changing the color of the screen.
  • tft.setCursor(x,y);For setting the cursor position using x and y coordinates of the screen.
  • tft.setTextColor(t);For setting the color of text.
  • tft.setTextColor(t,b);Setting the color of text and its background.
  • tft.setTextSize();For setting the size of text. This should be from 1 to 5.
  • tft.setRotation();Rotating the screen. Can take values of 0 for 0 degrees, 1 for 90 degrees, 2 for 180 degrees and 3 for 270 degrees.
  • tft.print();For displaying a string.
  • tft.println();Displaying a string and moves the cursor to the next line.
  • tft.drawFastVLine(x,y,h,t); This function draws a vertical line that starts in x, y location, and its length is h pixel and its color is t.
  • tft.drawFastHLine(x,y,w,t); This function draws a horizontal line that starts in x, y location, and its length is w pixel and its color is t.
  • tft.drawLine(xi,yi,xj,yj,t); This function draws a line that starts in xi and yi location ends is in xj and yj and the color is t.
  • tft.drawRect(x,y,w,h,t); function draws a rectangle in x and y location with w width and h height and t color.
  • tft.fillRect(x,y,w,h,t); function draws a filled rectangle in x and y location. w is width, h is height and t is color of the rectangle
  • tft.drawCircle(x,y,r,t); function draws a circle in x and y location and r radius and t color.
  • tft.fillCircle(x,y,r,t); function draws a filled circle in x and y location and r radius and t color.
  • tft.drawTriangle(x1,y1,x2,y2,x3,y3,t); function draws a triangle with three corner location x, y and z, and t color.
  • tft.fillTriangle(x1,y1,x2,y2,x3,y3,t); function draws a filled triangle with three corner location x, y and z, and t color.
  • tft.drawRoundRect(x,y,w,h,r,t); function draws a Rectangle with r radius round corners in x and y location and w width and h height and t color.
  • tft.fillRoundRect(x,y,w,h,r,t); function draws a filled Rectangle with r radius round corners in x and y location and w width and h height and t color.

There are many other functions and commands which you can use to program the TFT color display but the above are the commonest. You will meet many more with practice.

Before we can write our personal code we need to first test the display using the already made code examples from the installed library. This is done by going to File>Examples>Adafruit ST7735 and ST7789 Library. Then you can select any of the examples and upload it to the setup to see if the display works fine.In the diagram below I have shown how to access the graphics test code.

accessing example codes

The example below shows the basic use of the above commands and functions for displaying simple colored shapes, lines and words on the TFT display.

#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library

#define TFT_CS        10
#define TFT_RST        7 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         9

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

void setup(void) {
  tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
  //tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(0); // set display orientation 
}

void loop() {
  tft.fillScreen(ST77XX_CYAN);
  print_text(25,30,"HELLO",3,ST77XX_ORANGE);
  print_text(20,70,"WORLD!",3,ST77XX_BLUE);
  delay(5000);
  
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
  delay(5000);
  
  tft.fillScreen(ST77XX_CYAN);
  tft.drawRect(5,5,120,120,ST77XX_RED);
  tft.drawFastHLine(5,60,120,ST77XX_RED);
  tft.drawFastVLine(60,5,120,ST77XX_RED);
  delay(5000);
}

void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
  tft.setCursor(x_pos, y_pos);
  tft.setTextSize(text_size);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

Please also check out these other projects to better understand how the ST7735 TFT display is used with Arduino;

  • Displaying Images from Micro SD card on ST7735 Display using Arduino.
  • Simple Ultrasonic Radar.
  • Weather Station using BME280 Temperature and humidity sensor and Arduino.