Vi Nguyen's Dev Notes
  • 📓Dev Notes
    • Buy me a coffee
  • Deployment & Operation
    • Docker Container
      • Add User to Docker Group
      • Clean up unused docker images
      • Backup Container
      • Truncate docker log
    • Git
    • Ansible
      • Ansible - Setup fresh new ubuntu server
      • Run Ansible Playbook on MacOS
    • Linux
      • Zip file with Gzip
      • Linux - add user to sudo group
      • Rsync - copy file on remote server to local
      • Tunnel all docker ports on remote server to localhost
      • Create linux Swapfile
      • Rename a file to folder name
      • Copy and keep permission on linux
    • Database
      • Check if database is reachable with nc
      • PostgreSQL
        • PostgreSQL - Create a new primary key auto-increment column
        • Generate uuid for all records in a table PostgreSQL
        • Backup & Import all database PostgreSQL Inside Docker Container
        • Backup & Import single database PostgreSQL Inside Docker Container
        • PostgreSQL - Create user & grant permission on a database
        • PostgeSQL - Backup database via remote ssh server
      • Mysql
        • Mysql - Create user & grant permission on a database
        • Dump & import Mysql database inside container
        • Mysql - Dump all Mysql database from Mysql
    • Ngnix
      • Nginx - 504 Gateway Timeout error using Nginx as Proxy
      • Download file from server via nginx docker
  • Docker-compose samples
    • docker-compose - n8n
    • docker-compose - PostgreSQL
    • docker-compose caddy as reverse proxy
  • Homelab
    • Rasberry Pi 4B - Bookworm HDMI config
    • Waveshare 3.5" display on Pi 4 -Bookworm 64 Bit
  • Development
    • Development Notes
  • My Resources
    • Blog
    • Geek Tools
    • Dev Note Github Repo
Powered by GitBook
On this page
  1. Homelab

Waveshare 3.5" display on Pi 4 -Bookworm 64 Bit

Last updated 9 months ago

Source:

For Raspberry Pi 4 & Raspberry Pi 5

Download and Compile fbcp

Open the Raspberry Pi terminal and execute:

sudo apt install libraspberrypi-dev -y
sudo apt-get install unzip -y
sudo apt-get install cmake -y
sudo wget https://files.waveshare.com/upload/1/1e/Waveshare35c.zip
sudo unzip ./Waveshare35c.zip
sudo cp waveshare35c.dtbo /boot/overlays/
sudo wget https://files.waveshare.com/upload/1/1e/Rpi-fbcp.zip
sudo unzip ./Rpi-fbcp.zip
cd rpi-fbcp/
sudo rm -rf build
sudo mkdir build
cd build
sudo cmake ..
sudo make -j4
sudo install fbcp /usr/local/bin/fbcp

Edit "config.txt" file:

sudo nano /boot/firmware/config.txt

Blocking the following sentence:

Add the following code at the end of config.txt:

dtparam=spi=on
dtoverlay=waveshare35c
hdmi_force_hotplug=1
max_usb_current=1
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 480 320 60 6 0 0 0
hdmi_drive=2
display_rotate=0

Set Auto-start startx and fbcp

  • Open ".bash_profile". If there is no ".bash_profile" file, you can create one:

sudo nano ~/.bash_profile

Add the following code at the bottom of the ".bash_profile" file:

if [ "$(cat /proc/device-tree/model | cut -d ' ' -f 3)" = "5" ]; then
    # rpi 5B configuration
    export FRAMEBUFFER=/dev/fb1
    startx  2> /tmp/xorg_errors
else
    # Non-pi5 configuration
    export FRAMEBUFFER=/dev/fb0
    fbcp &
    startx  2> /tmp/xorg_errors
fi
  • Open the "99-fbturbo.~" file, if it exists, you need to check fb is "fb0":

sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.~

Add the following code in the "99-fbturbo.~" file:

Section "Device"
        Identifier      "Allwinner A10/A13 FBDEV"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb0"

        Option          "SwapbuffersWait" "true"
EndSection

Set CLI Auto-login

sudo raspi-config nonint do_boot_behaviour B2
sudo raspi-config nonint do_wayland W1
sudo reboot

After rebooting, the main screen can normally display. Note 1: Please ensure the username of the Raspberry Pi is "pi", otherwise, it cannot automatically log in. Note 2: After setting the above configuration, it may take a while to reboot the system and load SSH.

Configure Touch

  • Install calibrator software:

sudo apt-get install xserver-xorg-input-evdev 
sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf
sudo apt-get install xinput-calibrator
  • Edit 99-calibration.conf configuration file:

sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf

Add the following content to the "99-calibration.conf" configuration file:

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "Calibration"   "3932 300 294 3801"
        Option  "SwapAxes"      "1"
        Option "EmulateThirdButton" "1"
        Option "EmulateThirdButtonTimeout" "1000"
        Option "EmulateThirdButtonMoveThreshold" "300"
EndSection

Reboot to take effect.

sudo reboot

https://www.waveshare.com/wiki/3.5inch_RPi_LCD_(C)_Manual_Configuration#For_Bookworm_System