2.8″ TFT Color Touchscreen Display with Arduino

1,241 views

Introduction

The world of electronics and technology is ever-evolving, and with each passing day, new advancements are made. The 2.8-inch TFT color touchscreen display with Arduino is one such innovation that has revolutionized the way we interact with devices. This compact and powerful display is easy to use and comes with a host of features that make it a favorite among hobbyists and professionals alike.

In this article, we will explore how to use a “2.8″ TFT display with Arduino” and show you how to integrate it into your exciting projects

2.8″ TFT Color Touchscreen Display

The 2.8″ TFT (Thin Film Transistor) color touchscreen display is a compact and versatile display module that allows users to interact with devices in a more intuitive and user-friendly way. The display module typically includes a high-resolution color LCD screen, a touch-sensitive interface, and a microcontroller or driver board that can be connected to other devices, such as an Arduino microcontroller.

The display module offers a range of features such as adjustable brightness, easy-to-use touch input, and fast refresh rates. It is commonly used in a variety of applications, including home automation, portable devices, and industrial control systems.

Hardware Components

To interface the 2.8″ TFT Color Touchscreen Display with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
TFT Color Display LCD2.8″1
Jumper Wires1

2.8″ TFT Color Touchscreen Display Pinout

2.8-inch TFT Color Display Touchscreen Display Pinout
2.8-inch TFT Color Display Touchscreen Display Pinout

2.8″ TFT LCD Display Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoTFT Display
VINVCC
GNDGND
D10CS
D9C/S
D11MOSI
D13SCK
D12MISO
A5SCL
A4SDA

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Program Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <Adafruit_GFX.h>    // Core graphics library
#include <SPI.h>       // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h>      // this is needed for FT6206
#include <Adafruit_FT6206.h>
 
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
 
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
 
// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
 
void setup(void) {
  while (!Serial);     // used for leonardo debugging
 
  Serial.begin(115200);
  Serial.println(F("Cap Touch Paint!"));
 
  tft.begin();
 
  if (! ctp.begin(40)) {  // pass in 'sensitivity' coefficient
    Serial.println("Couldn't start FT6206 touchscreen controller");
    while (1);
  }
 
  Serial.println("Capacitive touchscreen started");
 
  tft.fillScreen(ILI9341_BLACK);
 
  // make the color selection boxes
  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
 
  // select the current color 'red'
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
  currentcolor = ILI9341_RED;
}
 
void loop() {
  // Wait for a touch
  if (! ctp.touched()) {
    return;
  }
 
  // Retrieve a point  
  TS_Point p = ctp.getPoint();
 
 /*
  // Print out raw data from screen touch controller
  Serial.print("X = "); Serial.print(p.x);
  Serial.print("\tY = "); Serial.print(p.y);
  Serial.print(" -> ");
 */
 
  // flip it around to match the screen.
  p.x = map(p.x, 0, 240, 240, 0);
  p.y = map(p.y, 0, 320, 320, 0);
 
  // Print out the remapped (rotated) coordinates
  Serial.print("("); Serial.print(p.x);
  Serial.print(", "); Serial.print(p.y);
  Serial.println(")");
 
 
  if (p.y < BOXSIZE) {
     oldcolor = currentcolor;
 
     if (p.x < BOXSIZE) {
       currentcolor = ILI9341_RED;
       tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*2) {
       currentcolor = ILI9341_YELLOW;
       tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*3) {
       currentcolor = ILI9341_GREEN;
       tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*4) {
       currentcolor = ILI9341_CYAN;
       tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*5) {
       currentcolor = ILI9341_BLUE;
       tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x <= BOXSIZE*6) {
       currentcolor = ILI9341_MAGENTA;
       tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     }
 
     if (oldcolor != currentcolor) {
        if (oldcolor == ILI9341_RED)
          tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
        if (oldcolor == ILI9341_YELLOW)
          tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
        if (oldcolor == ILI9341_GREEN)
          tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
        if (oldcolor == ILI9341_CYAN)
          tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
        if (oldcolor == ILI9341_BLUE)
          tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
        if (oldcolor == ILI9341_MAGENTA)
          tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
     }
  }
  if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
    tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
  }
}

Code Explanation

This Arduino code is for a simple painting program using a 2.8″ TFT color touchscreen display and a capacitive touchscreen. It includes libraries for graphics and touch input. The program waits for touch input and then maps the coordinates of the touch point to the screen, flips them to match the orientation of the screen, and prints the coordinates to the serial monitor. It also allows the user to select different colors for drawing by touching color boxes at the top of the screen and changing the color of the box to indicate the currently selected color.

Applications

Here are some applications for a 2.8″ TFT color touchscreen display:

  • Portable gaming devices
  • Smart home automation systems
  • Wearable fitness trackers
  • Industrial control systems
  • Handheld medical devices
  • Digital cameras and camcorders
  • Automotive infotainment systems
  • Home security systems
  • Audio and video players
  • GPS navigation devices

These are just a few examples. The versatility of a 2.8″ TFT color touchscreen display makes it suitable for a wide range of applications

Conclusion.

The “2.8-inch TFT color touchscreen display” with Arduino is a remarkable piece of technology that has made it easier than ever before to create interactive displays and user interfaces. Its high-resolution screen, touch-sensitive interface, and compatibility with the Arduino platform make it an ideal choice for a wide range of projects, from home automation to industrial control systems.