2inch LCD Module

From Diustou Wiki
2inch LCD Module
2inch-LCD-Module-6.jpg
Information

Categories: LCD/OLEDs/LCD

Brand: Waveshare

Description
Features

---

Interfaces

SPI

Related products

{{{related}}}

Instruction

This is a general LCD display Module, IPS screen, 2inch diagonal, 240×320 resolution, with embedded controller, communicating via SPI interface

Feature

  • SPI interface requires minimum GPIO for controlling
  • Comes with development resources and manual
  • The basic functions have been encapsulated on the demo, which can realize picture rotation, draw dots, lines, circles, rectangles, display English characters and Chinese characters, and display pictures.

Specifications

  • Operating voltage: 3.3V/5V
  • Interface: SPI
  • LCD type: IPS
  • Controller: ST7789V
  • Resolution: 240(V) x 320(H)RGB
  • Display size: 23.4(H)x 23.4(V)mm
  • Pixel size: 0.0975(H)x 0.0975(V)mm
  • Dimension: 58 x 35(mm)

Interface

SYMBOL Description
VCC Power (3.3V input)
GND Ground
DIN SPI data input
CLK SPI clock input
CS Chip selection, low active
DC Data/Command selection (high for data, low for command)
RST Reset, low active
BL Backlight

Hardware description

ST7789V supports RGB444, RGB565 and RGB666 three formats. This LCD uses RGB565. For most LCD controllers, the communication method of the controller can be configured, they are usually using 8080 parallel interface, 3-line SPI, 4-line SPI, and other communication methods. This LCD uses a 4-line SPI interface for reducing GPIO and fast speed.LCD

Communication protocol

2inch LCD Module manual 1.png

Note: It is not like the tradition SPI protocol, it only uses MOSI to send data from master to slave for 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. LCD RPI Connet.png

Enable SPI interfaces

  • 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.68.tar.gz tar zxvf bcm2835-1.68.tar.gz cd bcm2835-1.68/ sudo ./configure sudo make sudo make check sudo make install

  1. For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
  • Install wiringPi libraries
sudo apt-get install wiringpi

For the version of the Raspberry Pi system after May 2019 (the OS version earlier than this date doesn't need to be executed), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v

  1. You will get 2.52 information if you install it correctly
  • Install Python libraries
  1. 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

  1. 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 <> Use the command according to LCD:: sudo ./main 0.96 sudo ./main 1.14 sudo ./main 1.28 sudo ./main 1.3 sudo ./main 1.54 sudo ./main 1.8 sudo ./main 2

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 1inch28_LCD_test.py 1.28inch 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

  • Run the example
  1. python2

sudo python 0inch96_LCD_test.py sudo python 1inch14_LCD_test.py sudo python 1inch28_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

  1. python3

sudo python3 0inch96_LCD_test.py sudo python3 1inch14_LCD_test.py sudo python3 1inch28_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

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 XNUCLEO-F103RB-LCD-Connet.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_1in28_test() 1.28inch 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

Arduino

  • Download examples from wiki. Unzip it. The path of Arduino examples is ~/Arduino UNO/...
  • Copyt the folders in Arduino directory to 【Installation directory】/libraries/ (Generally the installation directory is C:\Program Files (x86)\Arduino\libraries)
  • Open Arduino IDE software, and click File -> Examples to check if LCD_2inch codes are there.
  • The development board used is Arduino UNO.

Hardware connection

2inch LCD UNO PLUS
VCC 5V
GND GND
DIN D11
CLK D12
CS D10
DC D7
RST D8
BL D9

Expected result

  1. The display is cleaned to white
  2. Display numbers and strings
  3. Draw a rectangle
  4. Draw a line
  5. Draw five circles
  6. Display a 70x70 image

The examples are tested in Arduino UNO, if you want to use other versions of the Arduino, you need to change the connection according to the actual boards.

Hardware Connection

Arduino UNO连接引脚对应关系
LCD UNO
VCC 5V/3.3V
GND GND
DIN D11
CLK D13
CS D10
DC D7
RST D8
BL D9

LCD driver hat to arduino connet.png

Run the example

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 1.28inch LCD Arduino.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

Resources

Document

Demo codes

3D Drawing

FAQ

Question:
1. The LCD keeps black when using it with Raspberry Pi?
Answer:
a) Please check that if you have enabled SPI interface

b)Check BL pin, if BL pin has no output value, you can try to disconnect BL pin and test it again.


Question:
2. The python codes has error?
Answer:
Please install image libraries and test it again. Run command: sudo apt-get install python-imaging to install it and test again.



Supports

Icon-mail.png Contact us

Working hours: 09:00-18:00 (UTC+8 Monday to Saturday)