Absolute Beginners Guide To TFT LCD Displays by Ar
Absolute Beginners Guide To TFT LCD Displays by Ar
by Electropeak
In this article, you will learn how to use TFT LCDs by Arduino boards. From basic commands to professional
designs and technics are all explained here. At the end of this article, you can :
ElectroPeak 3.5 inch TFT Color Display Screen Modu Arduino DUE X1
le X1
Software apps and online services
ElectroPeak 2.4 inch TFT LCD Display Shield X1
Arduino IDE
Arduino UNO & Genuino UNO X1
In electronic’s projects, creating an interface between technology to improve image qualities such as
user and system is very important. This interface addressability and contrast. A TFT LCD is an active
could be created by displaying useful data, a menu, matrix LCD, in contrast to passive matrix LCDs or
and ease of access. A beautiful design is also very simple, direct-driven LCDs with a few segments. In
important. Arduino-based projects, the processor frequency is
low. So it is not possible to display complex, high
There are several components to achieve this. LEDs, definition images and high-speed motions. Therefore,
7-segments, Character and Graphic displays, and full-color TFT LCDs can only be used to display
full-color TFT LCDs. The right component for your simple data and commands. In this article, we have
projects depends on the amount of data to be used libraries and advanced technics to display data,
displayed, type of user interaction, and processor charts, menu, etc. with a professional design. This
capacity. TFT LCD is a variant of a liquid-crystal can move your project presentation to a higher level.
display (LCD) that uses thin-film-transistor (TFT)
Size of displays affects your project parameters. 220×176. After choosing the right display, It’s time to
Bigger Display is not always better. if you want to choose the right controller. If you want to display
display high-resolution images and signs, you should characters, tests, numbers and static images and the
choose a big size display with higher resolution. But it
speed of display is not important, the Atmega328
decreases the speed of your processing, needs more Arduino boards (such as Arduino UNO) are a proper
space and also needs more current to run. choice. If the size of your code is big, The UNO board
may not be enough. You can use Arduino Mega2560
So, First, you should check the resolution, speed of instead. And if you want to show high resolution
motion, details of color and size of your project’s images and motions with high speed, you should use
images, texts, and numbers. We suggest popular size the ARM core Arduino boards such as Arduino DUE.
of Arduino displays such as 3.5 inch 480×320, 2.8
inch 400×240, 2.4 inch 320×240 and 1.8 inch
In electronics/computer hardware a display driver is The display driver will typically accept commands and
usually a semiconductor integrated circuit (but may data using an industry-standard general-purpose
alternatively comprise a state machine made of serial or parallel interface, such as TTL, CMOS,
discrete logic and other components) which provides RS232, SPI, I2C, etc. and generate signals with
an interface function between a microprocessor, suitable voltage, current, timing and demultiplexing to
microcontroller, ASIC or general-purpose peripheral make the display show the desired text or image. The
interface and a particular type of display device, e.g. LCDs manufacturers use different drivers in their
LCD, LED, OLED, ePaper, CRT, Vacuum fluorescent products. Some of them are more popular and some
or Nixie. of them are very unknown. To run your display easily,
you should use Arduino LCDs libraries and add them MCUFRIEND_kbv.CPP. You can see the list of
to your code. Otherwise running the display may be drivers that are supported by MCUFRIEND library.
very difficult. There are many free libraries you can
find on the internet but the important point about the Open Example folder. There are several example
libraries is their compatibility with the LCD’s driver. codes that you can run by Arduino. Hook up the LCD
The driver of your LCD must be known by your and test some of the examples.
library. In this article, we use the Adafruit GFX library
and MCUFRIEND KBV library and example codes.
You can download them from the following links.
Unzip the MCUFRIEND KBV and open the
You must add the library and then upload the code. If it is the first time you run an Arduino board, don’t worry. Just
follow these steps:
Go to www.arduino.cc/en/Main/Software and download the software of your OS. Install the IDE
software as instructed.
Run the Arduino IDE and clear the text editor and copy the following code in the text editor.
Navigate to sketch and include the libraries. Now click add ZIP library and add the libraries
Choose the board in tools and boards, select your Arduino Board.
Connect the Arduino to your PC and set the COM port in tools and port.
Press the Upload (Arrow sign) button.
You are all set!
After uploading an example code, it’s time to learn how to create your images on the LCD.
Open a new Sketch, and the necessary codes as described in the following sections.
#include "bitmap_RGB.h" // when you want to display These libraries are not necessary for now, but you
a bitmap image from library can add them.
Class & Object The tft.readID function reads ID from the display and
put it in ID variable. Then tft.begin function gets ID
//(int CS=A3, int RS=A2, int WR=A1, int RD=A0, int and the LCD gets ready to work.
RST=A4)
.
MCUFRIEND_kbv tft(A3, A2, A1, A0, A4);
Resolution of the Display
This line makes an object named TFT from
MCUFRIEND_kbv class and provides an SPI tft.width(); //int16_t width(void);
communication between LCD and Arduino.
tft.height(); //int16_t height(void);
.
By these two functions, You can find out the
Running the LCD resolution of the display. Just add them to the code
and put the outputs in a uint16_t variable. Then read
uint16_t ID = tft.readID(); it from the Serial port by Serial.println();. First add
Serial.begin(9600); in setup().
tft.begin(ID);
.
#define LIGHTGREY 0xC618 This code rotates the screen. 0=0, 1=90, 2=180,
3=270.
#define DARKGREY 0x7BEF
.
#define BLUE 0x001F
Inverting Screen Colors
#define GREEN 0x07E0
tft.invertDisplay(i); //invertDisplay(boolean i)
#define CYAN 0x07FF
This code inverts the colors of the screen.
#define RED 0xF800
tft.color565(r,g,b); //uint16_t color565(uint8_t r, uint8_t
#define MAGENTA 0xF81F g, uint8_t b)
#define YELLOW 0xFFE0 This code give RGB code and get UTFT color code.
You can add these lines to the top of your code and delay(10);}
just use the name of the color in the functions.
This code Scroll your screen. The Maxroll is the
Reset
drawLine function draws a line that starts in xi and yi //fillRoundRect (int16_t x, int16_t y, int16_t w, int16_t
locationends is in xj and yj and the color is t. h, uint8_t R , uint16_t t)
. tft.drawRoundRect(x,y,w,h,r,t);
fillRoundRect function draws a filled Rectangle with r radius round corners in x and y location and w width
radius round corners in x and y location and w width and h height and t color.
and h height and t color.
//drawTriangle(int16_t x1, int16_t y1, int16_t x2, drawTriangle function draws a triangle with three
int16_t y2, int16_t x3, int16_t y3,// uint16_t t) corner location x, y and z, and t color.
tft.setCursor(x,y); //setCursor(int16_t x, int16_t y) void showmsgXY(int x, int y, int sz, const GFXfont *f,
const char *msg)
This code sets the cursor position to of x and y
{ uint16_t x1, y1;
.
uint16_t wid, ht;
tft.setTextColor(t); //setTextColor(uint16_t t)
tft.setFont(f);
tft.setTextColor(t,b); //setTextColor(uint16_t t, uint16_t
b) tft.setCursor(x, y);
The first line sets the color of the text. Next line sets tft.setTextColor(0x0000);
the color of text and its background.
tft.setTextSize(sz);
.
tft.print(msg);
tft.setTextSize(s); //setTextSize(uint8_t s)
}
This code sets the size of text by s. s is a number
between 1 and 5. This function changes the font of the text. You should
add this function and font libraries.
.
.
tft.write(c); //write(uint8_t c)
for (int j = 0; j < 20; j++) {
This code displays a character.
tft.setCursor(145, 290);
tft.println("www.Electropeak.com");
int color = tft.color565(r -= 12, g -= 12, b -= 12);
tft.print("www.Electropeak.com");
tft.setTextColor(color);
The first function displays a string and moves the
cursor to the next line. tft.print("www.Electropeak.com");
. }
showmsgXY(x,y,sz,&FreeSans9pt7b,"www.Electrope This function can fade your text. You should add it to
ak.com"); your code.
First you should convert your image to hex code. tft.drawRGBBitmap(x, y, name, sx, sy);
Download the software from the following link. if you
don’t want to change the settings of the software, you First, you should convert your image to code.Use this
must invert the color of the image and make the link to convert the image:
image horizontally mirrored and rotate it 90 degrees http://www.rinkydinkelectronics.com/t_imageconvert...
counterclockwise. Now add it to the software and
convert it. Open the exported file and copy the hex Upload your image and download the converted file
code to Arduino IDE. x and y are locations of the that the UTFT libraries can process. Now copy the
image. sx and sy are sizes of image. you can change hex code to Arduino IDE. x and y are locations of the
the color of the image in the last input. image. sx and sy are size of the image.
In this template, We just used a string and 8 filled circles that change their colors in order. To draw circles around a
static point, You can use sin(); and cos(); functions. you should define the PI number. To change colors, you can
use color565(); function and replace your RGB code.
Download
https://www.instructables.com/ORIG/FNN/8XNC/JPCY7D22/FNN8XNCJPCY7D22.ino
…
In this template, We converted a.jpg image to.c file and added to the code, wrote a string and used the fade code
to display. Then we used scroll code to move the screen left. Download the.h file and add it to the folder of the
Arduino sketch.
Download
https://www.instructables.com/ORIG/FCA/I520/JPCY7DDL/FCAI520JPCY7DDL.ino
…
In this template, We used draw lines, filled circles, and string display functions.
In this template, We added a converted image to code and then used two black and white arcs to create the
pointer of volumes. Download the .h file and add it to the folder of the Arduino sketch.
You can find more animated templates (Like the following GIFs) by clicking on this link
In this template, We just display some images by RGB bitmap and bitmap functions. Just make a code for
touchscreen and use this template. Download the.h file and add it to the folder of the Arduino sketch.
Download
https://www.instructables.com/ORIG/FMM/60KI/JPCY7HQB/FMM60KIJPCY7HQB.ino
…
The speed of playing all the GIF files are edited and we made them faster or slower for better
understanding. The speed of motions depends on the speed of your processor or type of code or
size and thickness of elements in the code.
You can add the image code in the main page but it fills all the main page. So you can make a.h file
and add in the folder of the sketch.
In this article, We just discussed about displaying elements on LCD. Follow our next tutorials to
learn using touch screens and SD Cards.
If you have the problem with including the Libraries, change the "" sign to <>.
× SPECIAL OFFER (VALID UNTIL NOVEMBER 1ST 2018): If you order the 3.5² LCD from ElectroPeak, our
technical staff will design your desired template for free! Just send an email to [email protected] containing
your order number and requirements ;)
https://electropeak.com/learn/guides/absolute-begi...
Which Arduino do you use? For larger codes, you need Arduino Mega or Due