TFT displays controlled by ST7789VI chip Arduino boards are a great choice for Arduino and other microcontroller projects. These small but high-resolution displays allow you to display graphics, text, and images in a clear and precise manner. However, their integration can be a bit challenging for those unfamiliar with protocols like SPI or power and control requirements. In this guide, we'll dive into all the aspects of connecting, using libraries, and configuring these displays with your Arduino.
In addition, you will learn how to connect them with different boards such as the NodeMCU ESP8266 and the classic Arduino Nano. In this way, you will be able to take full advantage of the graphic and technical capabilities of this type of display, whether for Internet of Things (IoT) projects or for any other type of application, without depending on SD cards or complex circuits.
What is a TFT display with ST7789VI controller?
The screens TFT (Thin Film Transistor) are characterized by offering a much higher image quality than other types of screens such as normal LCDs or smaller OLEDs. The controller ST7789VI It is the brain of these screens, responsible for processing the signals sent by a microcontroller such as the Arduino or the ESP8266, and converting those signals into images, colors and complex graphics.
One of the great advantages of these screens is that they use the SPI communication bus, which simplifies the connection with most microcontrollers, using only four control pins (SDA, SCL, RES and DC). This allows to considerably reduce the wiring and they are perfect for compact projects.
Connecting the TFT display with the ST7789VI chip
In order to work with these displays, it is essential to know how to properly connect them to your Arduino or ESP8266. Depending on the microcontroller you use, the power supply and connection pins may vary slightly. Below we detail the most important connections.
Basic connections:
- VCC: Connect to the power signal, which is generally 3.3V (not 5V to avoid damage to the screen).
- GND: It is connected to ground.
- SCL (sometimes marked as CLK): This is the serial clock pin and goes to the pin D13 on a plate Arduino Uno or Nano.
- SDA (also labeled MOSI): This is the pin that sends the data and connects to the D11.
- ORS: It connects to the pin in charge of resetting the screen; in this case, to the D8 from the Arduino.
- DC: The command/data pin, which connects to the pin D9.
As for the plates ESP8266, you will notice that these operate at 3.3V, so you will not need to worry about adjusting the voltage levels, as is the case with Arduino, where it is necessary to use voltage dividers with resistors to protect the display controller.
Using libraries in Arduino
Once you have all the connections made correctly, you will need to install some libraries in the Arduino IDE. To work with these screens, the most commonly used option is the library Adafruit ST7789, which is highly compatible with the hardware of these screens and we can use it together with the library Adafruit GFX to create advanced graphics.
To install the libraries follow these steps:
- Go to Sketch -> Include Library -> Manage Libraries.
- Write ST7789 in the search bar and select the option Adafruit.
- Do the same for the library Adafruit GFX.
With these two libraries already installed, you are ready to write your first code and display images, text or any graphics you want.
Basic code for “Hello, World!” on TFT screen
A good starting point for testing your screen is to display a simple “Hello, World!” on the screen. Here is some basic code you can use for this purpose. Remember that this code is designed to Arduino Uno or Nano, but if you're using other boards you'll probably need to adapt the pins.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.init(240, 240);
tft.setRotation(1);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(50, 120);
tft.println("Hello World!");
}
void loop() {
// Nada que hacer en el loop
}
This little code initializes the screen, puts it in a horizontal position and displays the text "Hello World" in the center of the screen. You can experiment with different text sizes or colors using the methods setTextColor, setTextSize, among others.
Graphic capabilities of the ST7789VI display
The graphical capabilities of these displays are quite comprehensive. Using the Adafruit GFX library, you can draw lines, rectangles, circles, and more with just a few commands. Here are some of the most commonly used ones:
- drawLine(x0, y0, x1, y1, color): Draw a line from the point (x0, y0) to (x1, y1).
- fillRect(x, y, w, h, color): Draws a filled rectangle on the screen.
- fillCircle(x, y, r, color): Draw a solid circle with radius r from the point (x, y).
These basic methods will allow you to bring your screen to life quickly, but the library also allows you to import images in Bitmap, which is very useful if you want to display complex graphics.
To work with images, you will need to first convert them into a format that the Arduino can understand, as explained below.
Import images to the screen without using an SD card
Loading images onto a TFT display usually requires an attached SD card, which stores the image and allows it to be loaded from it. However, we can avoid this step by converting the images to bitmap code and storing them directly into the microcontroller's memory.
The process is simpler than it seems. You just need to use some software to convert your image and then integrate it into a header file. Here are the steps to follow:
- Choose an image, preferably 240x240 pixels (the size of the display).
- Use a program like LCD Image Converter to convert the image to an array of values.
- Save the generated array and copy the data into the header (.h) file of your Arduino project.
Then, using the function pushImage() from the Adafruit ST7789 library, you can load that array and display the image in question.
Remember that this method is ideal for small to medium-sized projects, as microcontroller memory limitations can work against you if you try to load many large images at once.
Finally, working with TFT displays with ST7789VI in your Arduino or ESP8266 projects opens up a world of graphical possibilities. With proper configuration and the right software tools, you can implement attractive and functional interfaces without too many setbacks.