In this guide we will going to configure the TFT Touch Screen LCD Module in Arduino UNO, supported also working on Arduino 2560 MEGA MCU Board, These 2.4 inch TFT Touch Screen Module shield with Micro SD slot is specially designed suit for UNO and MEGA, driven by ILI9341 TFT LCD Single Chip Driver 240RGBx320 Resolution and 262K color.
The ILI9341 is 262,144 color single chip SOC driver for the TFT liquid crystal display with a resolution of 240RGB 320 Dots, comprising a 720 channel source driver, a 320 channel gate driver, 172800 bytes GRAM for graphic display data of 240 RGB x 320 dots, and power supply circuit. These ILI9341 Chip can operate in 1.65v to 3.3v I/O interface voltage and an incorporated voltage follower circuit to generate voltage levels for driving an LCD.
ILI9341 supports full color 8 color display mode and sleep mode for precise power control by software and these features make the ILI9341 an ideal LCD driver for prototyping projects or a small and medium size portable products such as digital cellular phones, MP3 Players, and PMP.
These shield uses Arduino digital pins 5-13 and analog 0-3 it means you can use digital 2,3 and analog 4 and 5, pin 12 is available if you will used the microSD slot.
This LCD Screen shield works on 3.3v ~ 5v logic, it has onboard 3.3v 300mA LDO Regulator, 8 bit digital interface, plus 4 control lines, 4 wire resistive touch screen, compatible on 328, Mega, note Leonardo not supported.
Using the example library
- Extract the LCD code libraries to Arduino/libraries directory
- Open the Arduino IDE
- Goto File/Example/Adafruit_LCD_TFT
Diagram & Pin-out
Source Code (For Drawing Sketch)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_TFTLCD.h> // Hardware-specific library #include <TouchScreen.h> #if defined(__SAM3X8E__) #undef __FlashStringHelper::F(string_literal) #define F(string_literal) string_literal #endif #ifndef USE_ADAFRUIT_SHIELD_PINOUT // #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file." #endif #define YP A2 // must be an analog pin, use "An" notation! #define XM A3 // must be an analog pin, use "An" notation! #define YM 8 // can be a digital pin #define XP 9 // can be a digital pin #ifdef __SAM3X8E__ #define TS_MINX 125 #define TS_MINY 170 #define TS_MAXX 880 #define TS_MAXY 940 #else #define TS_MINX 180 #define TS_MINY 160 #define TS_MAXX 880 #define TS_MAXY 920 #endif // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it // For the one we're using, its 300 ohms across the X plate TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 // Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Adafruit_TFTLCD tft; #define BOXSIZE 40 #define PENRADIUS 4 int oldcolor, currentcolor,swapxy; void setup(void) { Serial.begin(9600); Serial.println(F("Paint!")); tft.reset(); uint16_t identifier = 0x9341; if(identifier == 0x9325) { Serial.println(F("Found ILI9325 LCD driver")); } else if(identifier == 0x9341) { Serial.println(F("Found ILI9341 LCD driver")); } else if(identifier == 0x7575) { Serial.println(F("Found HX8347G LCD driver")); } else { Serial.print(F("Unknown LCD driver chip: ")); Serial.println(identifier, HEX); return; } tft.begin(identifier); tft.fillScreen(BLACK); tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); currentcolor = RED; pinMode(13, OUTPUT); } #define MINPRESSURE 10 #define MAXPRESSURE 1000 void loop() { digitalWrite(13, HIGH); TSPoint p = ts.getPoint(); digitalWrite(13, LOW); // if sharing pins, you'll need to fix the directions of the touchscreen pins //pinMode(XP, OUTPUT); pinMode(XM, OUTPUT); pinMode(YP, OUTPUT); //pinMode(YM, OUTPUT); // we have some minimum pressure we consider 'valid' // pressure of 0 means no pressing! if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { //need to reverse xy for some reason: swapxy=p.y; p.y=p.x; p.x=swapxy; Serial.print("X = "); Serial.print(p.x); Serial.print("\tY = "); Serial.print(p.y); Serial.print("\tPressure = "); Serial.println(p.z); if (p.y < (TS_MINY+15)) { Serial.println("erase"); // press the bottom of the screen to erase tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); } // scale from 0->1023 to tft.width p.x = map(p.x, TS_MINX, TS_MAXX,0, tft.width()); p.y = map(p.y, TS_MINY, TS_MAXY,0, tft.height()); Serial.print("("); Serial.print(p.x); Serial.print(", "); Serial.print(p.y); Serial.println(")"); //Code below to fix the bug of inverted coordinates // p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(),0 ); // p.y = map(p.y, TS_MAXY, TS_MINY, 0, tft.height() ); //p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); //Correct offset of touch. Manual calibration if (p.y < BOXSIZE) { oldcolor = currentcolor; if (p.x < BOXSIZE) { currentcolor = RED; tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*2) { currentcolor = YELLOW; tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*3) { currentcolor = GREEN; tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*4) { currentcolor = CYAN; tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*5) { currentcolor = BLUE; tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*6) { currentcolor = MAGENTA; tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); } if (oldcolor != currentcolor) { if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); } } if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); } } } |
Downloads / Schematics
Download TFT Touch LCD Screen Shield Code Libraries | Zip
Download ILI9341 Datasheet | PDF
Download Schematics Diagram | PDF
Thanks for the libraries, this will be really a big help
by the way, where can i find the reference for commands when writing program for TFT touchscreen? pls help
Code library…
http://www.14core.com/wp-content/uploads/2016/11/TouchScreen.rar
Touch interface test code…
http://www.14core.com/wp-content/uploads/2016/11/tftpaint.rar
hi. i just bought this TFT and i am trying to connect it to a ESP8266 on NodeMCU board, do you think it would be possible?
because all i found on the web is for the other version of the TFT.
cheers
@ Cladio,
See the link below.
Driven by NodeMCU SPI,
http://www.14core.com/wp-content/uploads/2017/03/TFT-Touch-LCD-With-SPI-NodeMCU.png
Hi
The ILI9341 screen is support by the ESP32 UNO D1 R32?
Thanks
yes!, some of the guys already made does implementations.
Check this code > https://github.com/majodi/ESP32-Smart-Alarm-Clock