Working with Raspberry Pi
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 Pin | Raspberry Pi (BCM) |
|---|---|
| VCC | NC |
| 3V3 | 3V3 |
| GND | GND |
| MISO | GPIO 9 |
| MOSI | GPIO 10 |
| SCLK | GPIO 11 |
| LCD_CS | GPIO 8 |
| SD_CS | NC |
| LCD_DC | GPIO 25 |
| LCD_RST | GPIO 27 |
| LCD_BL | GPIO 18 |
| TP_SDA | GPIO 2 |
| TP_SCL | GPIO 3 |
| TP_INT | GPIO 4 |
| TP_RST | GPIO 17 |
Enable the SPI and I2C Interfaces
-
Run the configuration tool in the terminal:
sudo raspi-configSelect "Interface Options" in the configuration interface:

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

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

The menu names may differ slightly across different Raspberry Pi OS versions.
-
Reboot the Raspberry Pi:
sudo reboot -
Check the configuration after rebooting:
more /boot/config.txtNormally, you should see
dtparam=spi=onanddtparam=i2c_arm=on:
/dev/spidev0.0and/dev/spidev0.1indicate that the SPI device nodes have been generated:
Python Example
-
Install the runtime environment:
sudo apt updatesudo apt install -y python3-pip python3-pil python3-numpy python3-spidev unzip -
Download and extract the example programs:
cd ~wget https://files.waveshare.com/wiki/2inch-Capacitive-Touch-LCD/2inch_Capacitive_Touch_LCD_Demo_Pi.zipunzip 2inch_Capacitive_Touch_LCD_Demo_Pi.zip -d 2inch_Capacitive_Touch_LCD -
Run the example:
cd ~/2inch_Capacitive_Touch_LCD/Pythonpython3 2inch_Capacitive_Touch_LCD.py
The program displays 3 images in sequence, then enters the touch drawing board interface.
C Example
-
Install WiringPi:
git clone https://github.com/WiringPi/WiringPicd WiringPi./buildgpio -v -
If you have not yet downloaded the example programs, please follow the download steps in the Python Example to obtain the package.
-
Compile and run the example:
cd ~/2inch_Capacitive_Touch_LCD/Csudo make cleansudo make -jsudo ./main
The program performs an RGB color cycling test, then enters the touch drawing board interface.