Difference between revisions of "Raspberry Pi guides for SPI e-Paper"

From Waveshare Wiki
Jump to: navigation, search
(Created page with "==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. *1.54inch e-Pape...")
 
(Download demo codes)
Line 98: Line 98:
 
<pre>
 
<pre>
 
sudo git clone https://github.com/waveshare/e-Paper
 
sudo git clone https://github.com/waveshare/e-Paper
 +
</pre>
 +
==Examples==
 +
===C===
 +
*Enter the folder of C examples
 +
<pre>
 
cd ~/e-Paper/RaspberryPi\&JetsonNano/
 
cd ~/e-Paper/RaspberryPi\&JetsonNano/
 +
cd c
 +
</pre。
 +
*Modify the main.c file for corresponding e-Paper
 +
<pre>
 +
sudo nano examples/main.c
 +
</pre>
 +
: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.
 +
:[[File:E-paper_rpi_change_main.png|400px]]
 +
*Compile codes
 +
<pre>
 +
sudo make clean
 +
sudo make
 +
</pre>
 +
*Try to run the example
 +
<pre>
 +
sudo ./epd
 +
</pre>
 +
===Python===
 +
*Enter the folder of python code
 +
<pre>
 +
cd ~/e-Paper/RaspberryPi\&JetsonNano/
 +
cd python/examples
 +
</pre>
 +
*Check the folder, you can see that there are .py files for different e-Paper.
 +
<pre>
 +
ls -al
 +
</pre>
 +
:[[File:E-paper_rpi_change_python1.png|500px]]
 +
*Run the responding example, for example, if you want to update 1.54inch e-Paper V2/ 1.54inch e-Paper Module V2
 +
<pre>
 +
sudo python2.7 epd_1in54_V2_test.py
 +
</pre>
 +
or
 +
<pre>
 +
sudo python3 epd_1in54_V2_test.py
 +
</pre>
 +
==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.
 +
===C===
 +
;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:
 +
:[[File:E-paper_Driver_HAT_RPI_Makefile.png|400px]]
 +
*Data type
 +
<pre>
 +
#define UBYTE  uint8_t
 +
#define UWORD  uint16_t
 +
#define UDOUBLE uint32_t
 +
</pre>
 +
*Init and Exit
 +
<pre>
 +
void DEV_Module_Init(void);
 +
void DEV_Module_Exit(void);
 +
</pre>
 +
: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
 +
<pre>
 +
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
 +
UBYTE DEV_Digital_Read(UWORD Pin);
 +
</pre>
 +
*SPI transmit data
 +
<pre>
 +
void DEV_SPI_WriteByte(UBYTE Value);
 
</pre>
 
</pre>
 +
; EPD driver

Revision as of 07:32, 27 March 2020

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
GND GND GND
DIN MOSI 19
CLK SCLK 23
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

Examples

C

  • Enter the folder of C examples
cd ~/e-Paper/RaspberryPi\&JetsonNano/
cd c
</pre。
*Modify the main.c file for corresponding e-Paper
<pre>
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

Python

  • 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

or

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.

C

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