1.44-inch TFT display with Arduino

FunduinoLast updated on

Text, Linien und Formen auf dem ST7735 zeichnen

Ein TFT-Display zeigt nicht nur Zeichen wie ein LCD, sondern echte Grafik in Farbe. Das hier verwendete Modell misst 1,44 Zoll, wird über SPI angesteuert und nutzt den verbreiteten Controller ST7735.

Die Bibliothek Adafruit ST7735 nimmt dir die Ansteuerung ab. Der Beispielsketch führt der Reihe nach vor, was möglich ist: Schrift in vier Größen und mehreren Farben, Linien, gefüllte Kreise sowie umrandete und ausgefüllte Rechtecke.

Connection diagram for the TFT display on the Arduino
This is how to connect the display

What TFT displays are good for

TFT displays are everywhere: in navigation systems and car dashboards, televisions and monitors, digital cameras and smartphones, and now even in ovens and kitchen appliances.

The model used here has a 1.44-inch diagonal, is controlled via SPI, and uses the ST7735 controller.

Connect the display

Three control lines are defined in the sketch: CS on pin 10, DC on pin 9, and RST on pin 8. The SPI lines, power, and ground are also required.

The wiring diagram shows the complete pinout.

Connection diagram for the TFT display on the Arduino
This is how to connect the display

Install the library

In the Library Manager, search under Sketch → Include Library → Manage Libraries for Adafruit ST7735. In the dialog that follows, you must also install the additional required libraries - especially Adafruit GFX, which provides the actual drawing commands.

The overview table shows which commands are available.

The heading in the article names the library “Adafruit ST77735” - with one extra 7. The correct name is ST7735.

Adafruit ST7735 Library in the Library Manager
The Adafruit ST7735 library
Table of the library's drawing commands
The most important commands at a glance
1 / 2

The program

The sketch runs once in its entirety in setup and shows one after another what the display can do: four font sizes in different colors, horizontal lines, nested circles, and outlined and filled rectangles.

The loop remains empty – there is nothing to repeat.

If your display shows shifted edges or swapped colors, the initialization type is incorrect. The sketch uses INITR_REDTAB; depending on the batch, INITR_GREENTAB or INITR_BLACKTAB may be correct. The product page doesn’t mention this.

Draw text, lines, circles, and rectangles
// Pins zuordnen
# define TFT_PIN_CS 10
# define TFT_PIN_DC 9
# define TFT_PIN_RST 8
// Bibliotheken einbinden
# include "SPI.h"
# include "Adafruit_GFX.h"
# include "Adafruit_ST7735.h"
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_PIN_CS, TFT_PIN_DC, TFT_PIN_RST);
void setup()
{
  Serial.begin(9600);
  delay(500);
  Serial.println("Bildschirm: " + String(tft.height()) + " x " + String(tft.width()));
  tft.initR(INITR_REDTAB);
  // Bildschirm um 180 Grad drehen
  tft.setRotation(2);
  // schwarzer Hintergrund
  tft.fillScreen(ST7735_BLACK);
  // verschiedene Schriftgrößen
  tft.setTextSize(1);
  tft.setCursor(1, 5);
  tft.setTextColor(ST7735_BLUE);
  tft.print("Text");
  delay(500);
  tft.setTextSize(2);
  tft.setCursor(1, 20);
  tft.setTextColor(ST7735_GREEN);
  tft.print("Text");
  delay(500);
  tft.setTextSize(3);
  tft.setCursor(1, 40);
  tft.setTextColor(ST7735_RED);
  tft.print("Text");
  delay(500);
  tft.setTextSize(4);
  tft.setCursor(1, 70);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Text");
  delay(2000);
  // Linien ziehen
  tft.fillScreen(ST7735_BLACK);
  tft.drawLine(1, 1, tft.width(), 1, ST7735_ORANGE);
  tft.drawLine(1, 30, tft.width(), 30, ST7735_ORANGE);
  tft.drawLine(1, 60, tft.width(), 60, ST7735_ORANGE);
  delay(2000);
  // Kreise zeichnen
  tft.fillScreen(ST7735_BLACK);
  tft.fillCircle(60, 60, 50, ST7735_MAGENTA);
  tft.fillCircle(60, 60, 30, ST7735_GREEN);
  tft.fillCircle(60, 60, 30, ST7735_YELLOW);
  delay(2000);
  // Rechtecke zeichnen
  tft.fillScreen(ST7735_BLACK);
  tft.drawRect(1, 1, 50, 50, ST7735_ORANGE);
  tft.drawRect(5, 5, 50, 50, ST7735_ORANGE);
  tft.drawRect(10, 10, 50, 50, ST7735_ORANGE);
  delay(2000);
  // ausgefüllte Rechtecke zeichnen
  tft.fillScreen(ST7735_BLACK);
  tft.fillRect(5, 5, 50, 50, ST7735_GREEN);
  tft.fillRect(10, 10, 70, 70, ST7735_BLUE);
  tft.fillRect(15, 15, 90, 90, ST7735_RED);
}
void loop()
{
  // nichts zu tun, das Programm
  // läuft nur einmal
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.