1.3inch TFT LCD Display for Raspberry Pi 240x240

Overview

This TFT LCD display is equipped with an onboard joystick, six buttons, with a resolution of 240x240, an internal ST7789 controller, designed based on the Raspberry Pi 40-pin GPIO header, compatible with Raspberry Pi Zero/Zero W/Zero WH/2B/3B/3B+/4B. It utilizes SPI interface communication and provides demo codes in C and Python for Raspberry Pi, capable of drawing points, lines, rectangles, circles, as well as displaying English characters and images.

Parameters

Resolution240 x 240
Display ColorsRGB,65K colors
Control chipST7789
Screen typeTFT
BacklightLED
Interface4 Line SPI
Supply Voltage3.3V
Operating Temp-20℃~+70℃
Storage Temp-30℃~+80℃
LCD display area23.4mm (W) x 23.4mm (H)
Dimensions65mm(L) x 30mm(W)
Weight13g

Usages

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.

Hardware interface configuration description

Wiring Instructions for Raspberry Pi

The demo codes in the Raspberry Pi motherboard uses the wiringPi number pin definitions, and the bookworm system uses the pin definition of the BCM number. The definition of the connection with the Raspberry Pi motherboard is shown in the following table:

LCD interfacePin functionBCM numberwiringPi number
VCC3.3V3.3V3.3V
GNDGNDGNDGND
SDAMOSI1012
SCKSCK1114
CSCE0810
D/CP6256
RESETP2272
BLP5245
K1P0170
K2P1181
K3P3223
K4P4234
RP282028
LP292129
LEFTP21521
DOWNP252625
RIGHTP241924
CENTP22622
UPP231323

Top view / bottom view

① User joystick(Five direction)

② 1.3 inch LCD display

③ User button K1~K4

④ User button L and R

⑤ Raspberry Pi 40pin GPIO Female Header

Demo Codes Usage

Wiringpi Library Installation

First, use the "gpio -v" command on the terminal to check whether the wiringpi library has been installed. If the information of 2.52 appears, it means that the installation has been successful. You can skip this part of the content, otherwise you need to install it as follows:

sudo apt-get install wiringpi

#For Raspberry Pi systems after May 2019 (earlier ones do not need to be executed), an upgrade may be required:

wget https://project-downloads.drogon.net/wiringpi-latest.deb

#Version 4B upgrade of Raspberry Pi,If your download fails or the #speed is very slow, you can download it at the following linkand then #and copy it to the Raspberry Pi mainboard:

#https://github.com/seengreat/wiringpi-library

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 'wiring pi'" appears when running the python version of the example program, run the following command:

# For Python 2. x version

 pip install wiringpi

# For Python 3.x version

pip3 install wiringpi

Note: If the installation fails, you can try the following compilation and installation:

git clone --recursive https://github.com/WiringPi/WiringPi-Python.git

Note: --recursive option can automatically pull submodules, otherwise you need to download them manually.

Go to the WiringPi-Python folder you just downloaded and enter the following command to compile and install:

#For Python 2.x version

sudo python setup.py install

# For Python 3.x version

sudo python3 setup.py install

If the following error occurs:

1.3Inch LCD Display

At this point, enter the command sudo apt install swig to install swig, and then perform sudo python3 setup.py install to compile and install it. If a message similar to the following appears, the installation is successful.

1.3Inch LCD Display

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

Turn on the SPI interface

sudo raspi-config

Enable the SPI interface:

Interfacing Options -> SPI -> Yes

To view the enabled SPI devices:

ls /dev/spi* #

prints: "/dev/spidev0.0" and "/dev/spidev0.1"

Installation of Python libraries

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 Version Demo Codes

Note: For Raspberry Pi 4B and versions after raspbian_lite-2019-06-20, the following settings are required, otherwise the keys cannot be entered normally.

sudo nano /boot/config.txt

Add the following:

gpio=17,22,18,13,26,5,19,6,20,21,23=pu

Then save to exit.

Go to the demo codes/c directory

sudo make clean
sudo make
sudo ./main

Python Version Demo Codes

Go to the demo codes/python directory

python3 gui_demo.py
python3 key_demo.py

Demo Codes Description

C language version

The Demo Codes structure is divided into the bottom layer and the application layer, the underlying file is lcd_1inch3.c and lcd_1inch3.h, the underlying code implements the initialization of the Raspberry Pi motherboard control pin and LCD screen, and the application layer file lcd_gui.c and lcd_gui.h, mainly realizing the drawing of points, lines, rectangles, circles and the display function of English characters and pictures.

The files whose file names begin with "font" are related to the font. The ". c" suffix corresponds to the data source files of the font. The data structures of multiple font data source files are defined in the "fonts. h" file. The file with the suffix ". bmp" in the Raspberry Pi motherboard example program is the picture source file used for display. The number in the file name represents the pixel number of color (bpp, bit per pixel), for example, 1.3inch_demo1.bmp represents the picture file in 24bpp true color format.

Python language version

The python language version of the example program is only provided for the Raspberry Pi platform. At the same time, because the python platform can reference the PIL image processing library, many application layer API functions can be directly provided by the library, which greatly reduces the amount of code in the example program. The python version of the demo code file has a gui_demo.py、key_demo.py、lcd_ inch3.py three files, gui_demo.py is mainly used to draw lines, rectangles and circles, and display English characters and key_demo.py is the function demonstration of on-board buttons, lcd_1inch3.py is the driver to realize the bottom layer of LCD, including SPI initialization, LCD screen reset, initialization, etc.

Resources

Schematic

Demo codes for bullseye system

Demo codes for bookworm system

Product

Data Sheet

ST7789

Technical Support

Technical Support and Product Notes