Skip to main content

Working with Raspberry Pi

Note

This tutorial uses the Raspberry Pi 4 as an example to introduce the hardware connection of the module, as well as how to run the Python and C examples.

Hardware Connection​

Use 15PIN jumper wires to connect the module to the Raspberry Pi according to the table below:

LCD PinRaspberry Pi (BCM)
VCCNC
3V33V3
GNDGND
MISOGPIO 9
MOSIGPIO 10
SCLKGPIO 11
LCD_CSGPIO 8
SD_CSNC
LCD_DCGPIO 25
LCD_RSTGPIO 27
LCD_BLGPIO 18
TP_SDAGPIO 2
TP_SCLGPIO 3
TP_INTGPIO 4
TP_RSTGPIO 17

Enable the SPI and I2C Interfaces​

  1. Run the configuration tool in the terminal:

    sudo raspi-config

    Select "Interface Options" in the configuration interface:

    Interface Options in the Raspberry Pi configuration interface

  2. Select "SPI", then select "Yes" to enable the SPI interface:

    SPI option in the Raspberry Pi configuration interface

    Confirm enabling the Raspberry Pi SPI interface

  3. Enter "Interface Options" again, select "I2C", then select "Yes" to enable the I2C interface:

    I2C option in the Raspberry Pi configuration interface

    Confirm enabling the Raspberry Pi I2C interface

    The menu names may differ slightly across different Raspberry Pi OS versions.

  4. Reboot the Raspberry Pi:

    sudo reboot
  5. Check the configuration after rebooting:

    more /boot/config.txt

    Normally, you should see dtparam=spi=on and dtparam=i2c_arm=on:

    Raspberry Pi SPI and I2C interface configuration check result

    /dev/spidev0.0 and /dev/spidev0.1 indicate that the SPI device nodes have been generated:

    Raspberry Pi SPI device node check result

Python Example​

  1. Install the runtime environment:

    sudo apt update
    sudo apt install -y python3-pip python3-pil python3-numpy python3-spidev unzip
  2. Download and extract the example programs:

    cd ~
    wget https://files.waveshare.com/wiki/2inch-Capacitive-Touch-LCD/2inch_Capacitive_Touch_LCD_Demo_Pi.zip
    unzip 2inch_Capacitive_Touch_LCD_Demo_Pi.zip -d 2inch_Capacitive_Touch_LCD
  3. Run the example:

    cd ~/2inch_Capacitive_Touch_LCD/Python
    python3 2inch_Capacitive_Touch_LCD.py

The program displays 3 images in sequence, then enters the touch drawing board interface.

C Example​

  1. Install WiringPi:

    git clone https://github.com/WiringPi/WiringPi
    cd WiringPi
    ./build
    gpio -v
  2. If you have not yet downloaded the example programs, please follow the download steps in the Python Example to obtain the package.

  3. Compile and run the example:

    cd ~/2inch_Capacitive_Touch_LCD/C
    sudo make clean
    sudo make -j
    sudo ./main

The program performs an RGB color cycling test, then enters the touch drawing board interface.