2.4inch LCD Module

From Waveshare Wiki
Jump to: navigation, search
2.4inch LCD Module
2.4inch LCD Module
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Primary Attribute
Category: OLEDs / LCDs,
{{{userDefinedInfo}}}: {{{userdefinedvalue}}}
Brand: Waveshare
Website
English: Waveshare Website
Chinese: 官方中文站点
Onboard Interfaces
Related Products

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
  • 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

2inch LCD Module manual 1.png

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

Connect to Raspberry Pi
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 color of actual cable may be different with the figure here, please connect them according to the pins instead of color.

2.4inch LCD Module 002.jpg

Enable SPI interface

  • Open terminal, use command to enter the configuration page
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes  to enable SPI interface

RPI open spi.png
Reboot Raspberry Pi:

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

LCD rpi python examples.png
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

Hardware Coonnection

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.

Connect to STM32F103RBT6
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
2.4inch LCD Module 006.jpg

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
LCD STM32 CODE1.png

Open main.c file, you can configure the types for actual displays, recompile the project and download it to your board.
LCD STM32 CODE2.png

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

Connecte to Arduino UNO
LCD UNO
VCC 3.3V
GND GND
DIN D11
CLK D13
CS D10
DC D7
RST D8
BL D9

Run the dem ocodes

Download the demo codes and unzip it. The Arduino project is located in ~/Arduino/…
LCD arduino cede1.png

Run the project according to the actual display type
LCD arduino cede2.png
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
LCD arduino cede3.png
Select the COM Port according to your Device Manager
LCD arduino cede4.png
Compile and download it to your board
LCD arduino cede5.png

Docuemnts

Demo codes

Question:
The LCD is blank when using with Raspberry Pi?
Answer:

a)Make sure that you have enabled the SPI interface
b)Check the output of BL pin, if it doesn't have any value, please try to disconnect it.


Question:
How to change the display orientation
Answer:

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.
If you use Python codes, you can use the rotate(Rotate) function to change the orientation in any angle.


Question:
Python Image libraries

If you get libraries error when running the python example, please try to install the PIL libraries by command: sudo apt-get install python-imaging

Answer:



Please contact us by Email/Skype/WeChat for technology support.Our response may be delay, you can just leave your questions, we will reply to you as soon as possible in working time.

Service email.png [email protected]
Service skype.png [email protected]
Service wechat.png Webchat Linzeru.png
Service time.png 09:00 - 18:00 (UTC+8 Monday to Staturday)