Random Nerd Tutorials
Shares

Guide to 1.8 TFT Display with Arduino

Shares

In this guide we’re going to show you how you can use the 1.8 TFT display with the Arduino.  You’ll learn how to wire the display, write text, draw shapes and display images on the screen.

Introducing the 1.8 TFT Display

The 1.8 TFT is a colorful display with 128 x 160 color pixels. The display can load images from an SD card – it has an SD card slot at the back. The following figure shows the screen front and back view.

This module uses SPI communication – see the wiring below . To control the display we’ll use the TFT library, which is already included with Arduino IDE 1.0.5 and later.

Where to buy?

You can get the 1.8 TFT display for approximately $3 – check prices on Maker Advisor.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Pin wiring

The table below shows the 1.8 TFT wiring to Arduino UNO.

1.8 TFT Display Wiring to Arduino Uno
LED 3.3 V
SCK 13
SDA 11
A0 or DC 9
RESET 8
CS 10
GND GND
VCC 5 V

Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino official documentation.

Initializing the display

The TFT display communicates with the Arduino via SPI communication, so you need to include the SPI library on your code. We also use the TFT library to write and draw on the display.

#include <TFT.h> 
#include <SPI.h>

Then, you need to define the CS, A0 (or DC) and RST pins:

#define cs 10
#define dc 9
#define rst 8

Create an instance of the library called TFTscreen:

TFT TFTscreen = TFT(cs, dc, rst);

Finally, in the setup(), you need to initialize the library:

TFTscreen.begin();

Display text

To write text on the display, you can customize the screen background color, font size and color.

To set the background color, use:

TFTscreen.background(r, g, b);

In which, rg and b are the RGB values for a given color. To choose font color:

TFTscreen.stroke(r, g, b);

To set the font size:

TFTscreen.setTextSize(2);

You can increase or decrease the number given as argument, to increase or decrease font size.

Finally, to draw text on the display you use the following line:

TFTscreen.text("Hello, World!", x, y);

In which “Hello, World!” is the text you want to display and the (x, y) coordinate is the location where you want to start display text on the screen.

Code

The following example displays “Hello, World!” in the middle of the screen and changes the font color every 200 miliseconds.

Copy the following code to your Arduino IDE and upload it to your Arduino board.

Here’s your “Hello, World!” text on the 1.8 TFT display.

Display shapes

The TFT library provides useful functions to draw shapes on the display:

  • TFTscreen.point(x, y) – display a point at the (x, y) coordinate
  • TFTscreen.line(xStart, yStart, xEnd, yEnd) – draws a line that starts at (xStart, yStart) and ends at (xEnd, yEnd)
  • TFTscreen.rect(xStart, yStart, width, height) – draws a rectangle with the top left corner at (xStart, yStart) with the defined width and height
  • TFTscreen.circle(x, y, radius) – draws a circle with center at (x, y) with the specified radius

Code

The following example displays several shapes. Every time the code goes through the loop, the shapes change color.

Copy the following code to your Arduino IDE and upload it to your Arduino board.

Here’s the shapes on the display: 

Display images

The 1.8 TFT display can load images from the SD card. To read from the SD card you use the SD library, already included in the Arduino IDE software. Follow the next steps to display an image on the display:

1) Solder header pins for the SD card. There are four pins opposite to the display pins, as shown in figure below.

2) The display can load images bigger or smaller than the display size (160 x 128 px), but for better results, edit your image size to 160 x 128 px.

3) The image should be in .bmp format. To do that, you can use a photo editing software and save the image as .bmp format.

4) Copy the image to the SD card and insert it on the SD card slot at the back of the display.

5) Wire the SD card pins to the Arduino by following the table below:

SD card on TFT display Wiring to Arduino Uno
CS 4
MOSI 11
MISO 13
SCK 12

Both the display and the SD card work with SPI communication, so you’ll have pins on the Arduino with two connections.

6) In the Arduino IDE go to File > Examples > TFT > Arduino > TFTBitmaLogo.

7) Edit the code, so that it searches for your image. Replace the “arduino.bmp” with the name of your image:

// now that the SD card can be access, try to load the image file
logo = TFTscreen.loadImage("arduino.bmp");

8) Upload the code to your Arduino.

Note: some people find issues with this display when trying to read from the SD card. We don’t know why that happens. In fact, we tested a couple of times and it worked well, and then, when we were about to record to show you the final result, the display didn’t recognized the SD card anymore – we’re not sure if it’s a problem with the SD card holder that doesn’t establish a proper connection with the SD card. However, we are sure these instructions work, because we’ve tested them.

Wrapping up

In this guide we’ve shown you how to use the 1.8 TFT display with the Arduino: display text, draw shapes and display images. You can easily add a nice visual interface to your projects using this display.

Do you have any projects with the 1.8 TFT display? Let us know in the comments section below.

If you liked this post, you may also find useful:

 Thanks for reading.

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply