Secondary Menu

Arduino With Touch Screen Display

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.
More About Fernando Koyanagi »

Would you like to create more personalized menus and better human/machine interfaces? For such projects, you can use an Arduino and a Touch Screen Display. Does this idea sound enticing? If so, check out the video today, where I will show you an assembly with a Mega Arduino and a Touch Screen Display. You will see how to make the designs you want on the screen, and also how to determine the screen region to touch and activate a specific command. I emphasize that I chose to use the Arduino Mega due to its amount of pins.

So today, I'll introduce you to the Touch Screen display, its graphic functions, and how to grab the touch point on the screen. Let's also create an example containing all the elements, such as positioning, writing, designing shapes, colors, and touch.

Step 1: Arduino Mega 2560

Step 2: TFT LCD Shield 2.4"

This display that we use in our project has an interesting feature: it has an SD card. However, the writing and reading involved in this will be shown in another video, which I will soon produce. The objective of today’s lesson is to specifically address the graphic and touch screen features of this display.

Step 3: Libraries

Unzip the file and paste it into the libraries folder of the Arduino IDE.

C: / Program Files (x86) / Arduino / libraries

Note

Before we start our program, we need to address something important: the TOUCH calibration.

Using a simple program to get the touch points on the display, store the value of the points (x, y) at each end (highlighted in yellow in the figure below). These values are important for mapping the touch to the graphic points on the screen.

The setTextSize function is responsible for assigning a size to the text that will be written.

void setTextSize (uint8_t s);

17. setTextWrap

The setTextWrap function is responsible for breaking the line if it reaches the limit of the screen.

void setTextWrap (boolean w);

18. setRotation

The setRotation function is responsible for rotating the screen (landscape, portrait).

void setRotation (uint8_t r); // 0 (standard), 1,2,3

Step 5: Example

We will create a program in which we will use most of the resources that the display provides us.

Let's write some strings in different sizes, create three geometric figures, and pick up the touch event on them, each time we touch one of the figures, we will have the feedback of the figure name just below them.

Step 6: Libraries

First let's define the libraries that we will use.

#include <SWTFT.h> //responsável pela parte gráfica

#include <TouchScreen.h> //responsável por pegar os toques na tela

#include <SPI.h> //comunicação com o display

#include <Wire.h> //comunicação com o display

#include "math.h" //calcular potencia

Step 7: Defines

We will define some macros for the pins, and also the important values that we will use.