notes on using a 1.8" 128x160 TFT display [ST7735] with an ESP32 dev board

The 1.8-inch 128x160 TFT display, driven by the ST7735 controller, is a compact and versatile module widely utilized in embedded systems for graphical output. Its integration with microcontrollers like the ESP32 enables developers to create rich visual interfaces in resource-constrained environments.
The following post includes information on related Arduino libraries and offers illustrative guidance on wiring configurations and example code. The provided example sketch demonstrates initializing the display, setting its rotation, and rendering text using the Adafruit libraries.

Example


Materials

- ESP32 DevKitc
- USB cable
- TFT 1.8 inch 160x128 w/ microSD
breadboards
- wires

Setup



1.8" 128x160 TFT display [ST7735] pinout [1]


Lite        - this is the PWM input for the backlight control. Connect to 3-5VDC to turn on the backlight. Connect to ground to turn it off. Or, you can PWM at any frequency.
MISO     - this is the SPI Microcontroller In Serial Out pin, its used for the SD card. It isn't used for the TFT display which is write-only
SCLK     - this is the SPI clock input pin
MOSI     - this is the SPI Microcontroller Out Serial In pin, it is used to send data from the microcontroller to the SD card and/or TFT
TFT_CS - this is the TFT SPI chip select pin
Card CS - this is the SD card chip select, used if you want to read from the SD card.
D/C        - this is the TFT SPI data or command selector pin
RST        - this is the TFT reset pin. Connect to ground to reset the TFT! Its best to have this pin controlled by the library so the display is reset cleanly, but you can also connect it to the Arduino Reset pin, which works for most cases.
Vcc         - this is the power pin, connect to 3-5VDC - it has reverse polarity protection but try to wire it right!
GND       - this is the power and signal ground pin

Other notes on Arduino Libraries
(libraries to be installed)

Adafruit_GFX
Adafruit_ST7735
Adafruit_BusIO

Sketch

/*
* TFT
*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define TFT_CS 15
#define TFT_DC 25
#define TFT_MOSI 13
#define TFT_SCLK 14
#define TFT_RST 26

#define BLUE 0x001F
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define BLACK 0x0000
int m_contador = 0;
int m_o_contador = 65;
char cc = m_o_contador;
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void testdrawtext(char *text, uint16_t color, uint8_t size) {
tft.setCursor(74, 49);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.setTextSize(size);
tft.print(text);
}
void setup(void) {
Serial.begin(115200);
Serial.print(F("start ... "));
tft.initR(INITR_BLACKTAB);
tft.setRotation(1);
tft.fillScreen(WHITE);
delay(500);
Serial.print(F(" done"));
}

void loop() {
Serial.print(F("iter"));
Serial.println(m_contador, DEC);
m_contador += 1;
delay(1000);

if (m_o_contador >= 64){
tft.fillScreen(BLUE);
delay(10);
tft.fillScreen(GREEN);
delay(10);
tft.fillScreen(BLACK);
delay(10);
tft.fillScreen(WHITE);
if (m_o_contador > 90) {
m_o_contador = 65;
}
cc = m_o_contador;
testdrawtext(&cc,BLACK,5); // escrita de texto no ecrâ
m_o_contador += 1;
}
delay(10);
}

References

[1] https://learn.adafruit.com/1-8-tft-display/pinouts

Comments