Arduino and 160×128 TFT display with a ST7735S controller

by Floris Wouterlood – The Netherlands – August 4, 2017

Summary
This Bare Basic deals with connecting an Arduino with a breakout, serial SPI interfaced, 160×128 pixel color TFT display with a screen diagonal of 1.8 inch. The controller chip is a ST7735S.
160×128 pixels is a handy mini format to create an attractive, colorful display of, for instance, an Arduino weather station.

Introduction
The Sitronics ST7735 is a versatile display controller chip used to drive affordable, Arduino compatible TFT screens with moderate dimensions (1.8 inch display diameter; 160×128 pixels; 16-bit color). Displays with this chip can be applied as output color graphics / text display in an Arduino environment. An interesting library written by Adafruit exits that provides sufficient tools to create colorful, attractive presentation of data.
Once an Arduino has collected and manipulated data, display of the output is obvious. Reporting can be arranged via the Arduino IDE and Serial Monitor, but in this situation the Arduino must be connected to a computer while there is no way to directly produce graphical output. A separate display can be very handy for graphical data display and is especially recommended in standalone applications.
Displays for the Arduino are available in all kinds and price classes. I distinguish three groups: LCD, OLED and TFT. Well known is the monochrome LCD display with a blue or green background, usually with two lines of 16 characters or 4 lines of 20 characters, with each ‘character’ created in its own 8×5 pixel matrix. These LCD displays are good for displaying short messages or numerical values while they lack graphical capabilities and colors. Special LCD displays are the 128×64 monochrome numerical/graphical LCD display whose library offers a few primitive graphics, and the Nokia 5110 84×48 LCD display with a PCD8544 controller. LCD displays do not offer colors other than background versus character.


Figure 1: 1.8 inch 160×128 color TFT display with SPI interface on a breakout board (ST7735 compatible). Left: simple sketch showing text mode; right: graphics test mode.

A special kind of LCD is the OLED display. This family includes small, programmable graphical displays (64×32 or 128×32 pixels) in monochrome or full color.
More versatile than the LCD displays, as well as larger, are TFT displays (fig 1). These are capable of graphics and a spectrum of colors (65,536 up to 256,000 colors) to the degree that they support realistic display of color pictures. TFT displays can be bought in a dazzling array of sizes, resolution, interfaces and prices.

TFT displays for the Arduino microcontroller boards can be accessed via an 8-bit parallel data interface – fast but consuming at least 8 pins of the Arduino. An alternative is the serial SPI interface which needs only five pins.

 

Wiring the 1.8 inch color TFT breakout display
See the Table below, and Figure 2. Here, an Arduino Nano is used whose pin layout is identical to that of an Arduino Uno. Figure 2 shows the details of the wiring.

Connectivity Table

pin on TFT breakout board Alternative pin designation Connect with Arduino pin nr
VCC VCC 3.3V
GND GND GND
CS CS 10
Reset RST 8
A0 DC 9
SDA MOSI 11
SCK SCLK 13
LED Wiper of a 10 kΩ pot meter

 

Figure 2: Wiring of the 160×128 SPI 1.8 inch color TFT display. Note that more expensive displays have a voltage level shifter on board. This makes it possible to connect VCC with 5V instead of 3.3V as in this clone situation.

Note that this particular display operates at 3.3V. The pot meter that supplies background contrast (pin marked LED) can be connected to GND and 5V.

Libraries
Necessary libraries are: Adafruit_GFX.h, Adafruit_ST7735.h and SPI.h. These libraries are available at various sites on the internet, e.g. github.

Sketch:
Here is a no-frills sketch that does what is needed; display some message on the display, with some color and two graphic element (one visible: the frame rectangles and one invisible: the rectangles filled with the same color as the background used to wipe out text).

// SPI Adafruit ST7735 compatible
// TFT_160x128_ST7735
//
// 1.8″ 160×128 TFT Color Display
//
// Floris Wouterlood
// public domain August 2, 2017
// this is a bare sketch
// purpose: connect and start working

#define sclk 13
#define mosi 11
#define cs 10
#define dc 9
#define rst 8

#include <Adafruit_GFX.h> // core graphics library
#include <Adafruit_ST7735.h> // hardware-specific library
#include <SPI.h>

 

// Option 1: use any pins but a little slower
Adafruit_ST7735 tft = Adafruit_ST7735 (cs, dc, rst);

void setup() {

Serial.begin (9600); // serial monitor stuff
Serial.println (“TFT ST7735 display test”);
Serial.println ();

tft.initR (INITR_BLACKTAB); // initialize a ST7735S chip, black tab
Serial.println (“TFT initialized”);

// prepare the TFT
tft.setTextColor (ST7735_WHITE);
tft.fillScreen (ST7735_RED);

tft.drawRect (5,5,119,60,ST7735_YELLOW); // upper rectangle
tft.drawRect (5,70,119,84,ST7735_YELLOW); // lower reactangle

tft.setCursor (30, 15); // put text in upper rectangle
tft.setTextSize (2); // select text size
tft.println (“ST7735”);
tft.setCursor (30, 30);
tft.println (“======”);
tft.setTextSize (1); // select text size
tft.setCursor (22, 45);
tft.println (“160×128 pixels”);
tft.setTextSize(2); // set text size back to original

}

void loop() {

tft.setTextColor(ST7735_YELLOW);
tft.setCursor (37, 90);
tft.print (“Ha, die”);
delay (500);
tft.fillRect (37, 90, 60, 20, ST7735_RED); // clear “Hello”
tft.setCursor (37, 120);
tft.print (“Henk”
delay(500);
tft.fillRect (37, 120, 60, 20, ST7735_RED); // clear “World”

}

Discussion

ST7735 controller based TFT displays are very handy displays for use in Arduino applications. One typical application is a standalone weather station built around an Arduino platform and decorated with temperature, humidity and barometric pressure sensors. The ST7735 is less sophisticated as the bigger parallel TFT screens but displays based on this chip form a nice intermediate between the ‘big’ TFTs and the basic LCD displays.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s