Overview
This 2 inch LCD display offers a SPI interface and resolution of 320 x 240, based on a built-in ST7789V controller, providing Raspberry Pi C, Python and Arduino demo codes. It can draw points, lines, rectangles, circles and display pictures and characters in Chinese and English.
Specifications
RESOLUTION | 320 x 240 RGB |
DRIVING | ST7789V |
DISPLAY SIZE | 43mm x 30mm |
LCD TYPE | IPS |
OPERATING TEMPERATURE | -20℃ - 70℃ |
OPERATING VOLTAGE | 3.3V/5V |
INTERFACE | 4-wire SPI |
Dimensions | 50mm(Length) x 37mm(Width) |
Usage
Since the bookworm system no longer supports the wiringpi library, the example program for this system uses the lgpio library, and for the bullseye system, the wiringpi library version of the example program can be used.
Instructions of Hard Interface Configuration
Raspberry Pi Hardware Connection
The demo codes of Raspberry Pi motherboard use the pin definition of wiringPi number, and the bookworm system uses the pin definition of the BCM number. The definition of connecting to the Raspberry Pi motherboard is according to the following table:
LCD Interface | BCM | wiringPi | BOARD |
---|---|---|---|
VCC | 3.3V | 3.3V | 3.3V |
GND | GND | GND | GND |
DIN | MOSI | 12 | 19 |
CLK | SCLK | 14 | 23 |
CS | CE0 | 10 | 24 |
RST | 22 | 3 | 15 |
DC | 25 | 6 | 22 |
BL | 24 | 5 | 18 |
The wiring diagram of connections between the Raspberry Pi and LCD display is shown below.
Arduino Hardware Connection
LCD and Arduino Connection Pin Correspondences are shown in the following table:
LCD Display | Arduino UNO |
---|---|
VCC | 5V |
GND | GND |
DIN | D11 |
SCK | D13 |
CS | D10 |
RST | D9 |
DC | D8 |
BL | D7 |
Usage of Demo Codes
Wiring pi Libraries Installation
sudo apt-get install wiringpi
wget https://project-downloads.drogon.net/wiringpi-latest.deb # Version 4B upgrade of Raspberry Pi
sudo dpkg -i wiringpi-latest.deb
gpio -v # If version 2.52 appears, the installation is successful
#For the Bullseye branch system, use the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
gpio -v
#Running gpio - v will result in version 2.70. If it does not appear, it indicates an installation error
If the error prompt "ImportError: No module named 'wiringpi'" appears when running the python version of the sample program, run the following command
#For Python 2. x version
pip install wiringpi
#For Python version 3. X
pip3 install wiringpi
Note: If the installation fails, you can try the following compilation and installation:
git clone --recursive http://github.com/WitingPi/WiringPi-Python.git
Note: The -- recursive option can automatically pull the submodule, otherwise you need to download it manually.
Enter the WiringPi Python folder you just downloaded, enter the following command, compile and install:
#For Python 2. x version
sudo python setup.py install
#For Python version 3. X
sudo python3 setup.py install
If the following error occurs:
At this time, enter the command "sudo apt install swig" to install swig. After that, compile and install sudo python3 setup.py install. If a message similar to the following appears, the installation is successful.
lgpio library installation
For the bookworm system, the sample program uses the lgpio library. The following is the installation command for the library:
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
make
sudo make install
Enable SPI Interface
sudo raspi-config
Enable the SPI Interface:
Interfacing Options -> SPI -> Yes
Check the enabled SPI devices:
ls /dev/spi*
# at this time it will print:"/dev/spidev0.0"and"/dev/spidev0.1"
Python Libraries Installation
The demo codes are working under the python3 environment, and running the demo codes of python requires the installation of the pil, numpy, and spidev libraries. Please run the following commands to install:
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo apt-get install python3-pip
sudo pip3 install spidev
C Demo Codes
Access 2inch_lcd/c directory
sudo make clean
sudo make
sudo ./main
Python Demo Codes
Access 2inch_lcd/python directory
python3 2inch_lcd.py
Instructions of Demo Codes
C
The structure of demo codes is divided into the underlying layer and the application layer. The underlying file is lcd_2inch.c and lcd_2inch.h, the underlying code implements the initialization of the Raspberry Pi motherboard control pin and the LCD screen. The application layer file is lcd_gui.c and lcd_gui.h, which mainly makes the painting of points, lines, rectangles, circles and the display functions of pictures and characters in Chinese and English come true. The files starting with "font" in the file name are related to the font library. The ".c" suffix corresponds to the font library's data source file, and the data structure of multiple font library data source files is defined in the "fonts.h" file. The file with the suffix ".bmp" in the demo codes of the Raspberry Pi Motherboard is a picture source file used for display, and the number in the file name indicates the number of pixel bits (bpp, bit-per-pixel) of color. For example, fruits24.bmp represents a picture file in 24bpp true color format. The demo codes of Arduino UNO motherboard do not have these ".bmp" files, because the available memory in the Arduino UNO motherboard is relatively less , and the source data of the pictures is stored in the image.cpp file in the form of an array.
Python
The Python demo codes are only provided for the Raspberry Pi platform. Because the Python platform can reference the PIL image processing library, many application-layer API functions can be provided directly by the library, greatly reducing the amount of codes in the demo codes.
Resources
Demo codes for bullseye system
Demo codes for bookworm system
Data Sheet
Related Links
Image Libraries of Python
If users need to get other more functions, they can learn on the official website as shown:
https://pillow.readthedocs.io/en/latest/handbook/index.html