1.8 TFT LCD Screen for Arduino

Hi, I'm using a 1.8" TFT LCD display with an Arduino Uno, and I've connected the wires according to the instructions in the video https://www.youtube.com/watch?v=boagCpb6DgY&t=2s&ab_channel=educ8s.tv . I'm also using the example code provided in the video, but I've encountered a problem: there are two white lines appearing at the bottom and right edges of the screen. Is there any way to solve this issue?

Usually when that happens either your screen size is not set correctly or you have something overflowing the screen buffer. I am going to guess the screen size is not set correctly.

Check the library you are using for the model of display you have.

Hello, thanks for your suggestion. I have adjusted the code according to my display size, which is 160x128 . However, the original code still includes the line tft.fillScreen(ST7735_BLACK) . Despite this, two white lines are still appearing at the bottom and right edges of the screen. Could you please check my code below for any potential improvements?

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

#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9

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

float p = 3.1415926;

void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));

tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // Rotate display for portrait mode

Serial.println(F("Initialized"));

uint16_t time = millis();
for (int y = 0; y < 160; y++) {
** tft.drawFastHLine(0, y, 128, ST77XX_BLACK);**
** }**
time = millis() - time;

Serial.println(time, DEC);
delay(500);

// Call your setup functions here
tftPrintTest(); // Example function call
}

void loop() {
// Your loop code here
}

void testlines(uint16_t color) {
tft.fillScreen(ST77XX_BLACK);
for (int16_t y = 0; y < tft.height(); y += 6) {
tft.drawLine(0, 0, tft.width() - 1, y, color);
delay(0);
}
for (int16_t x = 0; x < tft.width(); x += 6) {
tft.drawLine(0, 0, x, tft.height() - 1, color);
delay(0);
}

// Similar adjustments for other line drawing functions
}

void testdrawtext(char *text, uint16_t color) {
// Adjust text positioning for portrait mode
tft.setCursor(2 , 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}

void tftPrintTest() {
tft.setTextWrap(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println("Hello World!");
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(3);
tft.println("Hello World!");
tft.setTextColor(ST77XX_BLUE);
tft.setTextSize(4);
tft.print(1234.567);
delay(1500);
tft.setCursor(0, 0);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(0);
tft.println("Hello World!");
tft.setTextSize(1);
tft.setTextColor(ST77XX_GREEN);
tft.print(p, 6);
tft.println(" Want pi?");
tft.println(" ");
tft.print(8675309, HEX); // print 8,675,309 out in HEX!
tft.println(" Print HEX!");
tft.println(" ");
tft.setTextColor(ST77XX_WHITE);
tft.println("Sketch has been");
tft.println("running for: ");
tft.setTextColor(ST77XX_MAGENTA);
tft.print(millis() / 1000);
tft.setTextColor(ST77XX_WHITE);
tft.print(" seconds.");
}

Can you put your code in code tags. Select your code and press " <CODE/> "

Nothing seems out of place, are there any other demos you can run? It's either the library is not configured properly or your display was somehow damaged.

I asked the supplier, and they mentioned that since the TFT display can light up, there shouldn't be any issues. I've checked and confirmed that the Adafruit ST7735 library can indeed be used for a 1.8-inch TFT display. However, the problem persists.

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

#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9

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

float p = 3.1415926;

void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));

tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // Rotate display for portrait mode

Serial.println(F("Initialized"));

uint16_t time = millis();
for (int y = 0; y < 160; y++) {
** tft.drawFastHLine(0, y, 128, ST77XX_BLACK);**
** }**
time = millis() - time;

Serial.println(time, DEC);
delay(500);

// Call your setup functions here
tftPrintTest(); // Example function call
}

void loop() {
// Your loop code here
}

void testlines(uint16_t color) {
tft.fillScreen(ST77XX_BLACK);
for (int16_t y = 0; y < tft.height(); y += 6) {
tft.drawLine(0, 0, tft.width() - 1, y, color);
delay(0);
}
for (int16_t x = 0; x < tft.width(); x += 6) {
tft.drawLine(0, 0, x, tft.height() - 1, color);
delay(0);
}

// Similar adjustments for other line drawing functions
}

void testdrawtext(char *text, uint16_t color) {
// Adjust text positioning for portrait mode
tft.setCursor(2 , 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}

void tftPrintTest() {
tft.setTextWrap(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println("Hello World!");
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(3);
tft.println("Hello World!");
tft.setTextColor(ST77XX_BLUE);
tft.setTextSize(4);
tft.print(1234.567);
delay(1500);
tft.setCursor(0, 0);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(0);
tft.println("Hello World!");
tft.setTextSize(1);
tft.setTextColor(ST77XX_GREEN);
tft.print(p, 6);
tft.println(" Want pi?");
tft.println(" ");
tft.print(8675309, HEX); // print 8,675,309 out in HEX!
tft.println(" Print HEX!");
tft.println(" ");
tft.setTextColor(ST77XX_WHITE);
tft.println("Sketch has been");
tft.println("running for: ");
tft.setTextColor(ST77XX_MAGENTA);
tft.print(millis() / 1000);
tft.setTextColor(ST77XX_WHITE);
tft.print(" seconds.");
}

The problem still occurs even when I change from landscape to portrait view.


There are many variants of the ST7735 chip, the configuration registers change from manufacturer to manufacturer, the library does not cover them all. Those pixels that stand out on the edge are due to the fact that the chip has a slight displacement of the pixel surface. On the ST7735 I have, it has 2-pixel left and 1-pixel up.

Modify the library, adding a corrector for TFTs with this type of displacement. In the sketch setup you only have to use this constructor

  //tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
    tft.initR(INITR_18BLACKTAB_OFFSET);

Adafruit_ST7735_and_ST7789_Library.zip (53.1 KB)

If the pixel-offset is not correct, it can be modified within the library's ccp file. These are the lines in which it can be corrected (240 to 244):

          if (options == INITR_18BLACKTAB_OFFSET) { 
            //added by TFTLCDCyg: TFT ZJY180-TV2.0  1.8" 160x128 Touch            
            _colstart = 2; //move 2 pixels to the right
	        _rowstart = 1; //move down 1 pixel
          }
2 Likes

By the way, I use a Teensy 3.6 board to take advantage of the native SDIO reader and not mess with microUSB wiring, you just have to connect the ST7735 and that's it.

1 Like

Thank for your solution it works well :grinning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.