Raspberry Pi guides for SPI e-Paper

From Waveshare Wiki
Jump to: navigation, search

Supports e-Paper

This is the common guide for all the e-Paper, if you want to get the run command by single e-Paper, please go to the related wiki page.

Hardware connection

If the e-Paper you have is the HAT version which has 40pin GPIO, you can directly attach the e-Paper HAT on Raspberry Pi, otherwise, you can connect your e-Paper to Raspberry Pi by 8pins cable provided.
To connect the e-Paper, you can following the table below
Connect to Raspberry Pi
e-Paper Raspberry Pi
BCM2835 Board
VCC 3.3V 3.3V
CS CE0 24
DC 25 22
RST 17 11
BUSY 24 18

Enable SPI interface

The communication interface of e-Paper is SPI, to use it, we should firstly enable SPI interface of SPI
Open terminal of Raspberry Pi, and open configuration by the following command
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes
RPI open spi.png
Restart Raspberry Pi
sudo reboot

Install libraries

Open terminal of Raspberry Pi and run the following commands to install corresponding libraries:

  • Install BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar zxvf bcm2835-1.60.tar.gz 
cd bcm2835-1.60/
sudo ./configure
sudo make
sudo make check
sudo make install
  • Install WiringPi libraries
sudo apt-get install wiringpi
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
  • Install Python2 libraries
sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-pil
sudo apt-get install python-numpy
sudo pip install RPi.GPIO
sudo pip install spidev
  • Install Python3 libraries
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 RPi.GPIO
sudo pip3 install spidev

Download demo codes

Open the terminal of Raspberry Pi and clone demo codes by the following commands:

sudo git clone https://github.com/waveshare/e-Paper



  • Enter the folder of C examples
cd ~/e-Paper/RaspberryPi\&JetsonNano/
cd c
*Modify the main.c file for corresponding e-Paper
sudo nano examples/main.c
For example, if you want to update 2.7inch e-Paper/2.7inch e-Paper HAT, you should modify the main.c file, uncomment the line EPD_2in7_test(), commnect others, and save.
E-paper rpi change main.png
  • Compile codes
sudo make clean
sudo make
  • Try to run the example
sudo ./epd


  • Enter the folder of python code
cd ~/e-Paper/RaspberryPi\&JetsonNano/
cd python/examples
  • Check the folder, you can see that there are .py files for different e-Paper.
ls -al
E-paper rpi change python1.png
  • Run the responding example, for example, if you want to update 1.54inch e-Paper V2/ 1.54inch e-Paper Module V2
sudo python2.7 epd_1in54_V2_test.py


sudo python3 epd_1in54_V2_test.py

Description of codes (API)

The libraries for Raspberry Pi and Jetson Nano are same. Examples contain three parts, hardware interface, EPD driver and the GUI functions.


Hardware interface
Two libraries are used by C example,WiringPi and BCM2835. The codes use wiringPi by default, if you want to use BCM2835, you can modify RaspberryPi&JetsonNano\c\Makefile file, modify lines 13 and 14. Change it as below:
E-paper Driver HAT RPI Makefile.png
  • Data type
#define UBYTE   uint8_t
#define UWORD   uint16_t
#define UDOUBLE uint32_t
  • Init and Exit
void DEV_Module_Init(void);
void DEV_Module_Exit(void);
Note: The Init() and Exit() function are used to configure GPIOs . EPD enter sleep mode after Exit() function is used, and the consumption of e-Paper should be 0 in sleep mode if the PCB is Rev2.1 version.
  • GPIO Read/Write
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE DEV_Digital_Read(UWORD Pin);
  • SPI transmit data
void DEV_SPI_WriteByte(UBYTE Value);
EPD driver
The driver file are saved under RaspberryPi&JetsonNano\c\lib\e-Paper
E-paper Driver HAT RPI epd.png
  • Initial EPD
For 1.54inch e-Paper, 1.54inch e-Paper V2, 2.13inch e-Paper, 2.13inch e-Paper V2, 2.13inch e-Paper (D), 2.9inch e-Paper and 2.9inch e-Paper (D), partial refresh is supported. You can set Mode = 0 for full refresh and Mode =1 for partial refresh
void EPD_xxx_Init(UBYTE Mode); 
For other e-Paper
void EPD_xxx_Init(void);
  • Trasmite one frame of e-Paper and display
For black/white e-Paper
void EPD_xxx_Display(UBYTE *Image);
For three-color e-Paper
void EPD_xxx_Display(const UBYTE *blackimage, const UBYTE *ryimage);
There are exception:
For 2.13inch e-Paper (D) and 2.13inch e-Paper (D), if you want to do partial refresh, you should use function
void EPD_2IN13D_DisplayPart(UBYTE *Image);
void EPD_2IN9D_DisplayPart(UBYTE *Image);
For 1.54inch e-Paper V2 and 2.13inch e-Paper V2. you should first display static background (base image) and then dynamicly display (display Part) when partial refresh.
void EPD_1IN54_V2_DisplayPartBaseImage(UBYTE *Image);
void EPD_1IN54_V2_DisplayPart(UBYTE *Image);
void EPD_2IN13_V2_DisplayPart(UBYTE *Image);
void EPD_2IN13_V2_DisplayPartBaseImage(UBYTE *Image);
  • Sleep mode
void EPD_xxx_Sleep(void);
To wake up module, you should set hardware reset (re power on it) or call the init function.

GUI functions

GUI files can be found in RaspberryPi&JetsonNano\c\lib\GUI\GUI_Paint.c(.h) directory

E-paper Driver HAT GUI.png

The fonts can be found in RaspberryPi&JetsonNano\c\lib\Fonts directory

E-paper Driver HAT Fonts.png
  • Create an image buffer
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
Image: the Image buffer
Width: width of the image
Height: Height of the image
Rotate: Rotate angle
Color: Color of the image
  • Select image buffer