2.4inch LCD Module
| ||
Overview
This is a 2.4inch LCD display module, supports 65K RGB colors. The display has 240×320 resolution, SPI Interface.
Specification
- Operating voltage: 3.3V/5V (When using 5V power supply, the logic voltage is 5V; When using 3.3V power supply, the logic voltage is 3.3V)
- Interface: SPI
- LCD Type: TFT
- Controller: IL9341
- Resolution: 240(V) x 320(H)RGB
- Display Size: 36.72(H)x 48.96(V)mm
- Pixel Size: 0.153(H)x 0.153(V)mm
- Dimenstion: 70.5 x 43.3(mm)
Pinout
PIN | Description |
VCC | 3.3V |
GND | GND |
DIN | SPI data input (MOSI) |
CLK | SPI clock input (SCLK) |
CS | Chip selection (low active) |
DC | Data/Command control |
RST | Reset |
BL | Backlight |
Hardware Description
LCD & Controller
The controller of this display supports 12bits, 16bits and 18 bits color format, that are RGB44, RGN565 and RGB66. We use the RGB565 for color displying.
For faster communication and reduce the pins, this display use SPI interface.
Communication protocol
Note: It is not like the traditional SPI protocol, it only uses MOSI to send data from master to slave for the LCD display. For details please refer to Datasheet Page 105.
RESX: Reset, should be pull-down when power on, set to 1 other time.
CSX: Slave chip select. The chip is enabled only CS is set Low
D/CX: Data/Command selection; DC=0, write command; DC=1, write data
SDA: Data transmitted. (RGB data)
SCL: SPI clock
The SPI communication protocol of the data transmission uses control bits: clock phase (CPHA) and clock polarity (CPOL):
CPOL defines the level while the synchronization clock is idle. If CPOL=0, then it is LOW.
CPHA defines at whish clock’s tick the data transmission starts. CPHL=0 – at the first one, otherwise at the second one
This combination of two bits provides 4 modes of SPI data transmission. The commonly used is SPI0 mode, i.e. GPHL=0 and CPOL=0.
According to the figure above, data transmitting begins at the first falling edge, 8bit data are transmitted at one clock cycle. It is SPI0. MSB.
Hardware connection
Please connect the LCD to your Raspberry Pi by the 8PIN cable according to the table below
If you use the pin header or PH2.0 8PIN interface, you need to connect according to the following table
Raspberry Pi connection pin correspondence
LCD | Raspberry Pi | |
BCM2835 | Board | |
VCC | 5V | 5V |
GND | GND | GND |
DIN | MOSI | 19 |
CLK | SCLK | 23 |
CS | CE0 | 24 |
DC | 25 | 22 |
RST | 27 | 13 |
BL | 18 | 12 |
The 2.4inch LCD uses the PH2.0 8PIN interface, which can be connected to the Raspberry Pi according to the above table:The color of actual cable may be different with the figure here, please connect them according to the pins instead of color.
Enable SPI interface
- Open terminal, use command to enter the configuration page
sudo raspi-config Choose Interfacing Options -> SPI -> Yes to enable SPI interface
sudo reboot
Please make sure that SPI interface was not used by other devices
Install Libraries
- Install BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz tar zxvf bcm2835-1.60.tar.gz cd bcm2835-1.60/ sudo ./configure sudo make sudo make check sudo make install #For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
- Install wiringPi libraries
sudo apt-get install wiringpi #For Pi 4, you need to update it: cd /tmp wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v #You will get 2.52 information if you install it correctly
- Install Python libraries
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
Download Examples
Open Raspberry Pi terminal and run the following command
sudo apt-get install p7zip-full sudo wget https://www.waveshare.net/w/upload/a/a8/LCD_Module_RPI_code.7z 7z x LCD_Module_RPI_code.7z -O./LCD_Module_code cd LCD_Module_code/RaspberryPi/
Run the demo codes
Please go into the RaspberryPi directory (demo codes) first and run the commands in terminal
C codes
- Re-compile the demo codes
cd c sudo make clean sudo make -j 8
This examples are made for multi-dusplay, you can input the type of the LCD when using.
sudo ./main <<type of LCD>>
Use the command according to LCD::
sudo ./main 0.96 sudo ./main 1.14 sudo ./main 1.3 sudo ./main 1.54 sudo ./main 1.8 sudo ./main 2 sudo ./main 2.4
python
- Enter the python directory and run ls -al
cd python/examples ls -l
You can check all the files which are listed in type:
0inch96_LCD_test.py | 0.96inch LCD example |
1inch14_LCD_test.py | 1.14inch LCD example |
1inch3_LCD_test.py | 1.3inch LCD example |
1inch54_LCD_test.py | 1.54inchLCD example |
1inch8_LCD_test.py | 1.8inch LCD example |
2inch_LCD_test.py | 2inch LCD example |
2inch4_LCD_test.py | 2.4inch LCD example |
- Run the example
# python2 sudo python 0inch96_LCD_test.py sudo python 1inch14_LCD_test.py sudo python 1inch3_LCD_test.py sudo python 1inch54_LCD_test.py sudo python 1inch8_LCD_test.py sudo python 2inch_LCD_test.py sudo python 2inch4_LCD_test.py # python3 sudo python3 0inch96_LCD_test.py sudo python3 1inch14_LCD_test.py sudo python3 1inch3_LCD_test.py sudo python3 1inch54_LCD_test.py sudo python3 1inch8_LCD_test.py sudo python3 2inch_LCD_test.py sudo python3 2inch4_LCD_test.py
FBCP porting
Framebuffer uses a video output device to drive a video display device from a memory buffer containing complete frame data. Simply put, a memory area is used to store the display content, and the display content can be changed by changing the data in the memory.
There is an open source project on github: fbcp-ili9341. Compared with other fbcp projects, this project uses partial refresh and DMA to achieve a speed of up to 60fps
Download
sudo apt-get install cmake -y cd ~ wget https://www.waveshare.net/w/upload/1/18/Waveshare_fbcp.zip unzip Waveshare_fbcp.zip cd Waveshare_fbcp/ sudo chmod +x ./shell/*
Use script
Here we have written several scripts that allow users to quickly use fbcp and run corresponding commands according to their own screen
If you use a script, you can ignore the following if you don't need to modify it
Note: The script will replace the corresponding /boot/config.txt and /etc/rc.local and restart, if the user needs, please back up the relevant files in advance
#0.96inch LCD Module sudo ./shell/waveshare-0inch96 #1.14inch LCD Module sudo ./shell/waveshare-1inch14 #1.3inch LCD Module sudo ./shell/waveshare-1inch3 #1.44inch LCD Module sudo ./shell/waveshare-1inch44 #1.54inch LCD Module sudo ./shell/waveshare-1inch54 #1.8inch LCD Module sudo ./shell/waveshare-1inch8 #2inch LCD Module sudo ./shell/waveshare-2inch #2.4inch LCD Module sudo ./shell/waveshare-2inch4
Environment configuration
Raspberry Pi's vc4-kms-v3d will cause fbcp to fail, so we need to close vc4-kms-v3d before installing in fbcp
sudo nano /boot/config.txt
You can block the sentences corresponding to the following figure
Then you need to restart
sudo reboot
Compile and run
If you want to study how it works, we also provide source code and corresponding running instructions to help you get started quickly
mkdir build cd build sudo cmake [options] .. sudo make -j sudo ./fbcp
Replace it by yourself according to the LCD Module you use, above cmake [options] ..
#0.96inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_0INCH96_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.14inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH14_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.3inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH3_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.54inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH54_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #1.8inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_1INCH8_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #2inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. #2.4inch LCD Module sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH4_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
Set up to start automatically
sudo cp ~/waveshare_fbcp/build/fbcp /usr/local/bin/fbcp sudo nano /etc/rc.local
Add fbcp& before exit 0. Note that you must add "&" to run in the background, otherwise the system may not be able to start.
Set the Size of User Interface Display
Set the size of user interface display in the /boot/config.txt file.
sudo nano /boot/config.txt
Add configuration statements for resolution in the config.txt file.
hdmi_force_hotplug=1 hdmi_cvt=[options] hdmi_group=2 hdmi_mode=1 hdmi_mode=87 display_rotate=0
According to the LCD you use, replace the hdmi_cvt=[options] above by yourself
#2.4inchinch LCD Module & 2inchinch LCD Module hdmi_cvt=640 480 60 1 0 0 0 #1.8inch LCD Module hdmi_cvt=400 300 60 1 0 0 0 #1.3inch LCD Module & 1.54inch LCD Module hdmi_cvt=300 300 60 1 0 0 0 #1.14inch LCD Module hdmi_cvt=300 170 60 1 0 0 0 #0.96inch LCD Module hdmi_cvt=300 150 60 1 0 0 0
Note: For Pi4B, you also need to comment the [pi4] part of the statement in the file and modify it to:
[pi4] # Enable DRM VC4 V3D driver on top of the dispmanx display stack #dtoverlay=vc4-fkms-v3d #max_framebuffers=2
Then restart
sudo reboot
After starting the Raspberry Pi, you can find that the user interface has appeared on the screen.
Hardware Connection
The examples are based on STM32F103RBT6 as well as the connection table. If you want to use other MCU, you need to port the project and change the connection according to the actual hardware.
LCD | STM32 |
VCC | 3.3V/5V |
GND | GND |
DIN | PA7 |
CLK | PA5 |
CS | PB6 |
DC | PA8 |
RST | PA9 |
BL | PC7 |
Use Waveshare XNUCLEO-F103RB as examples
About the examples
The examples use HAL libraries.
Download demo codes, unzip, and find the STM32 projects. Open LCD_demo.uvprojx which is located in STM32\STM32F103RBT6\MDK-ARM directory by Keil project
Open main.c file, you can configure the types for actual displays, recompile the project and download it to your board.
LCD_0in96_test() | 0.96inch LCD example |
LCD_1in14_test() | 1.14inch LCD example |
LCD_1in3_test() | 1.3inch LCD example |
LCD_1in54_test() | 1.54inch LCD example |
LCD_1in8_test() | 1.8inch LCD example |
LCD_2in_test() | 2inchLCDexample |
The examples are all tested with Arduino UNO and the instruction are based on Arduino, if you use other types, please change the connection according to the actual boards.
Hardware Connection
LCD | UNO |
VCC | 5V |
GND | GND |
DIN | D11 |
CLK | D13 |
CS | D10 |
DC | D7 |
RST | D8 |
BL | D9 |
Run the demo codes
Download the demo codes and unzip it. The Arduino project is located in ~/Arduino/…
Run the project according to the actual display type
For examples: 1.54inch LCD Module. Enter the LCD_1inch54 directory and run the LCD_1inch54.ino file
Run the project and choose Arduino UNO as Board
Select the COM Port according to your Device Manager
Compile and download it to your board
a)Make sure that you have enabled the SPI interface
If you use the C codes, you can use Paint_SetRotate(Rotate) function to set the display orientation, only 0°, 90°, 180°, and the 270° are available.
When using an Arduino, please make sure it is plugged into a 5v power supply.
{{{5}}}