3.2-inch ILI9341 Color Touchscreen
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a230r.1.14.18.3a686fa6qABOu4&id=38842179442&ns=1&abbucket=7
Baidu Netdisk Download Link:
http://www.lcdwiki.com/zh/3.2inch_SPI_Module_ILI9341_SKU:MSP3218
Specifications
Operating Voltage:3.3V-5V
Operating Current:90mA
Module Dimensions:50.0(H) x 86(V) MM
Pixel Resolution:320(H) x 240(V)RGB
Driver Chip:ILI9341
Communication Protocol:SPI
Hardware Connection
- VCC: Connect to the 5V of the development board.
- GND: Connect to the GND of the development board.
- CS: Chip select, connect to digital pin 10 of the development board.
- RESET: Reset, connect to digital pin 9 of the development board.
- DC (or RS): Data/command control, connect to digital pin 8 of the development board.
- SDI/MOSI (or TFT_MOSI): Master output, slave input, connect to digital pin 11 of the development board.
- SCK (or TFT_SCK): Clock, connect to digital pin 13 of the development board. LED: Backlight control, can be directly connected to A3 or 3.3V or 5V of the development board, through a resistor for current limiting, or connected to a PWM output to control brightness.
- SDO/MISO (or TFT_MISO): Master input, slave output. If you need to read data from the TFT, this line should be connected to digital pin 12 of the development board. This pin is not used in this example and has no function.
- T_CLK: Touchscreen clock, connect to digital pin 13 of the development board.
- T_CS: Touchscreen chip select, connect to digital pin 4 of the development board.
- T_DIN: Touchscreen data input, connect to digital pin 11 of the development board.
- T_DO: Touchscreen data output, connect to digital pin 12 of the development board.
- T_IRQ: Touchscreen interrupt, do not connect.
Usage Method
If you use the ATMEGA328P to control this screen, you need to use a level shifter module or modify a pair of solder pads on the screen. In our actual tests, we found that when we connected the display directly without using a level shifter module, it either did not work at all or only displayed half the screen with garbled output. This is because the screen's pins can only accept a high level of 3.3V, while the development board outputs a high level of 5V.
Since we did not have a level shifter module, we used the method provided by the screen manufacturer: the shorting method. This shorting method is simple to operate, involves short wiring, and does not require external devices.The downside is that the module generates a lot of heat during operation.
The shorting method involves shorting the J1 component position (as shown in the figure below) and soldering on the back of the module. After shorting, the module's VCC pin must be connected to a 5V power supply (not connected to a 3.3V power supply).
Installing Library Files
To control this screen using the Arduino IDE, you need to install libraries that support the ILI9341 and XPT2046. Commonly used libraries include the Adafruit_ILI9341 and Adafruit_GFX libraries for graphical display operations, as well as libraries specifically designed for the XPT2046 touch screen, such as the Utouch or XPT2046_Touchscreen libraries.
- Open the Arduino IDE.
- Go to “Tools” > “Manage Libraries…”.
- Search and install “
Adafruit ILI9341
”, “Adafruit GFX
” and“XPT2046_Touchscreen
”library.These libraries provide you with the basic methods for display and touch functionality.
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 8, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <XPT2046_Touchscreen.h>
// 为显示屏和触摸屏定义引脚
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TOUCH_CS 4
// 初始化ILI9341
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC,TFT_RST);
// 初始化XPT2046触摸屏
XPT2046_Touchscreen touch(TOUCH_CS);
void setup() {
Serial.begin(9600);
// 初始化显示屏
tft.begin();
// 触摸屏初始化
touch.begin();
touch.setRotation(1);
// 设置文字大小
tft.setTextSize(2);
// 设置文字颜色, ILI9341_BLUE为白色背景,ILI9341_BLACK为黑色文字
tft.setTextColor(ILI9341_BLACK, ILI9341_BLUE);
// 清屏为白色
tft.fillScreen(ILI9341_BLUE);
//设置显示位置的x,y坐标
tft.setCursor(240/2-(7*16), 320/2);
// 显示文字
tft.println("Hello, ILI9341!");
}
void loop() {
// 触摸屏检测等相关代码可以放在这里
if (touch.touched()) {
TS_Point p = touch.getPoint();
//设置显示位置
tft.setCursor(5, 5);
//显示触摸位置的X坐标
tft.print("X = ");
tft.print(p.x);
tft.println(" ");
//显示触摸位置的Y坐标
tft.print("Y = ");
tft.print(p.y);
tft.println(" ");
// 可以根据需要添加更多的触摸相关操作
}
delay(5);
}
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