Skip to main content

3.5-RPi-LCD-CTP

1. Introduction

The 3.5-RPi-LCD-CTP is a touch display module that communicates via SPI and I2C interfaces. It features the ST7796S display driver and GT911 touch controller, offering a 320×480 resolution, IPS high-brightness display, and responsive capacitive touch. It combines stability with visual appeal.

2. Product Specifications

📋 Specification Table

ItemDescription
Model3.5-RPi-LCD-CTP
Cover Size61.00 (H) × 92.44 (V) mm
Display Area49.36 (H) × 73.84 (V) mm
Resolution320 (H) x 480 (V)
Panel TypeIPS
Touch TypeCapacitive
Viewing Angle170°
Color Gamut65% NTSC
Brightness200cd/m²
Contrast Ratio1000:1
Backlight ControlPWM imming
Refresh Rate60Hz
Power Consumption0.8W
Power Supply Voltage5V
Logic Voltage3.3V
InterfacesDisplay:SPI
Touch:I2C
Controller ICsDisplay:ST7796S
Touch:GT911

3. Pin Definition

Pin NumberLabelDescription
1NCNo connection
2, 45VPower supply (5V)
3TP_SDATouch I2C data pin
5TP_SCLTouch I2C clock pin
6, 9, 14, 20, 25GNDGround
7TP_INTTouch interrupt pin
11TP_RSTTouch reset pin (active low)
12LCD_PWMBacklight PWM control pin
13LCD_RSTDisplay reset pin (active low)
15LCD_DCData/Command control pin (high for data, low for command)
19MOSISPI Master Out / Slave In
21MISOSPI Master In / Slave Out
23SCLKSPI Clock
24CE0SPI Chip Select (active low)
16–18, 8, 10, 22, 26NCNo connection

4. Product Dimensions

5. Hardware Connection

  1. Align and connect the module's 26-pin female header to the Raspberry Pi's 40-pin GPIO header.
  2. It is recommended to use copper standoffs for secure mounting to prevent looseness.

6. Software Setup

6.1. Enable SPI and I2C Interfaces

Open the terminal and execute the following commands to enable the required interfaces:

sudo raspi-config nonint do_spi 0
sudo raspi-config nonint do_i2c 0

6.2 Install Dependencies

sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo apt-get install python3-spidev
sudo apt install python3-smbus2

6.3 Example Program

wget https://files.luckfox.com/wiki/Luckfox/Display/3inch5-RPi-LCD-CTP/3inch5-RPi-LCD-CTP-RPI-Demo.zip
unzip 3inch5-RPi-LCD-CTP-RPI-Demo.zip
cd 3inch5-RPi-LCD-CTP-RPI-Demo
sudo python ./main.py

7. Desktop Display Configuration for Bookworm System

wget https://files.luckfox.com/wiki/Luckfox/Display/3inch5-RPi-LCD-CTP/St7796s.zip
unzip St7796s.zip
sudo cp st7796s.bin /lib/firmware/

Edit config.txt:

sudo nano /boot/firmware/config.txt

Add the following lines at the end of the [all] section:

dtparam=spi=on
dtoverlay=mipi-dbi-spi,speed=48000000
dtparam=compatible=st7796s\0panel-mipi-dbi-spi
dtparam=width=320,height=480,width-mm=49,height-mm=79
dtparam=reset-gpio=27,dc-gpio=22,backlight-gpio=18
dtoverlay=goodix,addr=0x5d

To apply changes, reboot:

sudo reboot

Method 2: Install Kernel Module and DTBO Driver

📌 Note: Bookworm system requires the official kernel version 6.6.51 or higher.

Install Driver Module

  1. Check the current kernel version:
uname -a

Sample output (Raspberry Pi 5):

Linux raspberrypi 6.12.47+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.47-1+rpt1 (2025-09-16) aarch64 GNU/Linux

Explanation:

  • Kernel Version: 6.12.47+rpt-rpi-2712

  • Architecture: 64bit ARM(AArch64)

  1. Download and install the st7796 driver module:
# Download and unzip driver files
wget https://files.luckfox.com/wiki/Luckfox/Display/3inch5-RPi-LCD-CTP/Luckfox-st7796s.zip
unzip Luckfox-st7796s.zip
cd Luckfox-st7796s

# Enter the folder for the corresponding kernel version (as in the example)
cd 6.12.47/64/rpi-2712-RPi5

# Copy the kernel module
sudo cp st7796s.ko /lib/modules/$(uname -r)/kernel/drivers

# Add the module to auto-load on boot
sudo nano /etc/modules
# Add the following line at the end of the file:
st7796s

As shown below:

Resolve kernel module dependencies:

sudo depmod -a
  1. Configure the device tree overlay:
cd
wget https://files.luckfox.com/wiki/Luckfox/Display/3inch5-RPi-LCD-CTP/Luckfox35CTP.dtbo
sudo cp Luckfox35CTP.dtbo /boot/overlays/

For RPi4 & RPi5

  1. Follow the steps above to install the driver module
  2. Edit the config.txt file:
sudo nano /boot/firmware/config.txt

Comment out dual-screen related configurations.

Add the following lines at the end of the**[all]**section:

dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=50000
dtparam=spi=on
dtoverlay=Luckfox35CTP,fps=60,speed=48000000,rotate=90,ts_rotate_90
hdmi_force_hotplug=1
max_usb_current=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 480 320 60 6 0 0 0
hdmi_drive=2
  1. Create X11 Configuration File
sudo nano /etc/X11/xorg.conf.d/98-spi-screen.conf

Add the following content:

Section "Device"
Identifier "SPI Screen"
Driver "fbdev"
Option "fbdev" "/dev/fb0"
EndSection

🔧 After completing the entire process, if there is no display, try changing /dev/fb0 to /dev/fb1 and rebooting.

  1. Switch to the X11 Display System
sudo raspi-config nonint do_wayland W1
sudo reboot

For All Raspberry Pi Versions (Requires Bookworm Lite)

⚠️ Only applicable to the following versions:
64bit Lite
32bit Lite

  1. Edit the config.txt File
sudo nano /boot/firmware/config.txt

Comment out KMS and dual-display settings.

At the end of the [all] section, add the following lines:

dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=50000
dtparam=spi=on
dtoverlay=Luckfox35CTP,fps=60,speed=48000000,rotate=90,ts_rotate_90
hdmi_force_hotplug=1
max_usb_current=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 480 320 60 6 0 0 0
hdmi_drive=2
  1. Install Required Software
# X11 Services
sudo apt-get install --no-install-recommends xserver-xorg -y
sudo apt-get install --no-install-recommends xinit -y

# Desktop Manager and GUI
sudo apt install lightdm -y
sudo apt install raspberrypi-ui-mods -y

# Git and Browser (Optional)
sudo apt install git -y
sudo apt install chromium-browser -y

# VLC Media Player (Optional)
sudo apt install vlc -y
  1. Download and Run the Driver
sudo apt install libraspberrypi-dev -y
sudo apt-get install unzip -y
sudo apt-get install cmake -y

# Download and build fbcp
sudo wget https://files.luckfox.com/wiki/Luckfox/Display/3inch5-RPi-LCD-CTP/Rpi-fbcp.zip
sudo unzip ./Rpi-fbcp.zip
cd rpi-fbcp/
sudo rm -rf build
sudo mkdir -m 777 ./build
cd ./build
sudo cmake ..
sudo make -j4
sudo install fbcp /usr/local/bin/fbcp
  1. Configure Auto-Start for startx and fbcp
  • Edit the Bash Shell file:
sudo nano ~/.bashrc

Add the following to the end of the file:

if [ "$(cat /proc/device-tree/model | cut -d ' ' -f 3)" = "5" ]; then
# Configuration for RPi 5B
export FRAMEBUFFER=/dev/fb1
startx 2> /tmp/xorg_errors
else
# Configuration for non-RPi 5
export FRAMEBUFFER=/dev/fb0
startx 2> /tmp/xorg_errors
fi
  • Create fbcp systemd Service
sudo nano /etc/systemd/system/fbcp.service

Add the following content:

[Unit]
Description=Framebuffer Copy for Raspberry Pi
After=network.target

[Service]
ExecStartPre=/bin/sleep 20
ExecStart=/usr/local/bin/fbcp
Restart=always
User=root
Group=root

[Install]
WantedBy=multi-user.target

Then execute the following commands:

sudo systemctl daemon-reload
sudo systemctl enable fbcp.service
sudo systemctl start fbcp.service
  1. Enable CLI Auto-login
sudo raspi-config nonint do_boot_behaviour B2
sudo raspi-config nonint do_wayland W1
sudo reboot

Notes
⚠️ The username must be pi, otherwise auto-login will not work properly.
🚀 Each reboot will result in a longer startup time, and SSH availability will be delayed accordingly.

8. Screen Rotation Settings

GUI Rotation

  1. Open the Screen Configuration application

  2. Check "Touchscreen"

  3. Go to Orientation and select the desired rotation angle.

Command Line Rotation

💡 It is recommended to use this command in the Wayland environment. Applicable to Raspberry Pi OS Bookworm and above.

  1. Install the 'wlr-randr'' tool:
sudo apt install wlr-randr
  1. View available output names:
wlr-randr

Sample output (e.g., SPI-1):

  1. Execute the rotation command:
wlr-randr --output SPI-1 --transform 90

📝 Supported rotation parameters:
normal
90
180
270

9. Adjust the backlight

PWM dimming

  • Install WiringPi
cd ~
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
./build
gpio -v

A successful installation will output the gpio version as shown below:

  • Manually adjust the display PWM backlight
gpio -g mode 18 pwm # Occupied pins are PWM pins
gpio pwmc 100 # Set PWM clock divider
gpio -g pwm 18 0 # Darkest
gpio -g pwm 18 1023 # Brightest
gpio -g mode 18 out # Release as output

Pinctrl dimming

  • Set bright screen
sudo pinctrl set 18 op dh
  • Set the screen off
sudo pinctrl set 18 op dl

10. Resources

Downloads

Choose your preferred download source.

GitHubGoogle Drive
DownloadDownload

Available Resources

ResourceDirectoryDescription
📖 User ManualDocs/Product documentation and user guide.
💻 Demo CodeCode/Demo applications and source code for Raspberry Pi.
📑 SchematicSchematic/Hardware schematic in PDF format.
📄 DatasheetsDocs/datasheets/Datasheets for the display driver IC and touch controller.
📐 CAD DrawingsCAD/2D mechanical drawings in DXF/PDF format.
🧩 3D Models3D Models/STEP models for mechanical and enclosure design.