Template: Hardware/Software setting for touch e-paper HAT

From Waveshare Wiki
Jump to: navigation, search

Raspberry Pi

Hardware Connection

You can directly attach it to the 40PIN GPIO of Raspberry Pi. Or you can wire it to Raspberry Pi with a 12PIN cable, please refer to the PIN definition below:

Connect to Raspberry Pi
Touch e-Paper Raspberry Pi
BCM2835 Board
VCC 3.3V 3.3V
GND GND GND
DIN MOSI 19
CLK SCLK 23
CS CE0 24
DC 25 22
RST 17 11
BUSY 24 18
INT 27 13
SCL SCL1 5
SDA SDA1 3
TRST 22 15

Take the 2.13inch Touch e-Paper HAT as an example, just plug it into the Raspberry Pi:

Touch ePaper HAT con.jpg

Enable SPI Interface

  • Open the Raspberry Pi terminal and enter the following command in the config interface:
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes Enable SPI interface

RPI open spi.png
Then reboot your Raspberry Pi:

sudo reboot
  • Check /boot/config.txt, and you can see 'dtparam=spi=on' was written in.

Raspberry Pi Guides for 4.37 e-Paper.jpg

  • To make sure SPI is not occupied, it is recommended to close other drivers' coverage. You can use ls /dev/spi* to check whether SPI is occupied. If the terminal outputs /dev/spidev0.1 and /dev/spidev0.1, SPI is not occupied.

Raspberry Pi Guides for 4.37 e-Paper02.jpg

Enable I2C interface

  • Open the terminal, and use the command to enter the configuration page.
sudo raspi-config
Choose Interfacing Options -> I2C -> Yes to enable I2C interface.

RPI open i2c.png

And then reboot the system:

sudo reboot

Libraries Installation

  • Install lg library:
#Open the Raspberry Pi terminal and input the following commands: 
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
make
sudo make install
#For more details, you can refer to https://github.com/gpiozero/lg
  • Install gpiod library (optional):
#Open the Raspberry Pi terminal and input the following commands: 
sudo apt-get update
sudo apt install gpiod libgpiod-dev
  • Install BCM2835 libraries (optional):
#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/
  • Install wiringPi libraries (optional):
#Open the Raspberry Pi terminal and run the following command
cd
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
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear if there is no installation error

The #Bullseye branch system uses the following commands:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
gpio -v
# Run gpio -v and version 2.70 will appear if there is no installation error

Install Python Libraries

  • Install the function library:
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install spidev
  • Install the function library (python2):
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install spidev
  • Install gpiozero library (installed by default, if not, you can install it by following the commands below):
sudo apt-get update
# python3
sudo apt install python3-gpiozero
# python2
sudo apt install python-gpiozero

Download the Demo

  • Open the terminal of the Raspberry Pi and execute:

Method 1: It is recommended to download the demo from our official website:

cd ~
wget https://files.waveshare.com/upload/3/3e/Touch_e-Paper_Code.zip
unzip Touch_e-Paper_Code.zip -d Touch_e-Paper_Code

If you fail to unzip it, you can unzip it with 7z:
sudo apt-get install p7zip-full
7z x Touch_e-Paper_Code.zip -o./Touch_e-Paper_Code

Method 2: Download the demo from GitHub.

cd ~
git clone https://github.com/waveshare/Touch_e-Paper_HAT

Running the Demo

C

Enter the directory of the C demo:

cd ~/Touch_e-Paper_Code/c
  • (Optional) Modify the 14-16 lines of Makefile to switch the dependent library, BCM2835 is used by default, and it is the fastest. (If you have used BCM2835, you need to reboot it before using other libraries.)

Modify the comment as shown below:
Touch ePaper HAT makefile.jpg

  • Modify main.c file and select the corresponding test demo: just comment out the corresponding comment.
  • Recompile and run the demo, this process may take a few seconds.
Run the following command in the c directory:
sudo make clean
sudo make -j4
sudo ./main

python

Enter the directory of the Python demo:

cd ~/Touch_e-Paper_Code/python/examples

Enter the following commands, the demo can support python2/3.

The following uses the 2.13inch Touch e-Paper HAT as an example:

# python2
sudo python2 TP2in13_test.py
# python3
sudo python3 TP2in13_test.py