Difference between revisions of "3.7inch e-Paper HAT"

From Waveshare Wiki
Jump to: navigation, search
(SPI timing)
Line 280: Line 280:
 
{{Commom Instruction of SPI e-paper}}
 
{{Commom Instruction of SPI e-paper}}
  
*[https://www.waveshare.com/w/upload/8/87/E-Paper-Driver-HAT-Schematic.pdf Driver board Schematic]
+
*[https://www.waveshare.com/w/upload/8/8e/3.7inch_e-Paper_Schematic.pdf 3.7inch e-Paper HAT Schematic]
*[https://www.waveshare.com/w/upload/2/27/7inch_HD_e-Paper_Specification.pdf 7.5inch HD e-Paper Specification]
+
*[https://www.waveshare.com/w/upload/7/71/3.7inch_e-Paper_Specification.pdf 3.7inch e-Paper Specification]
 
===Demo code===
 
===Demo code===
 
*[https://github.com/waveshare/e-Paper Github]
 
*[https://github.com/waveshare/e-Paper Github]

Revision as of 10:26, 5 September 2020

3.7inch e-Paper
3.7inch-e-Paper-1.jpg

480x280, 3.7inch E-Ink raw panel without driver board
3.7inch e-paper HAT
3.7inch-e-Paper-HAT-1.jpg

480x280, 3.7inch E-Ink display HAT for Raspberry Pi, SPI interface
{{{name3}}}

{{{name4}}}

{{{name5}}}

Primary Attribute
Category: OLEDs / LCDs, LCD e-Paper
{{{userDefinedInfo}}}: {{{userdefinedvalue}}}
Brand: Waveshare
Website
English: Waveshare website
Chinese: 官方中文站点
Onboard Interfaces
SPI
Related Products

Contents

Introduction

Note: The raw panel requires a driver board, If you are the first time use this e-Paper, we recommend you to buy the HAT version or buy more one driver hat for easy use, otherwise you need to make the driver board yourself. And this instruction is based on the HAT version.

480x280, 3.7inch E-Ink display HAT for Raspberry Pi, SPI interface

More

Interfaces

VCC 3.3V
GND GND
DIN SPI MOSI
CLK SPI SCK
CS SPI chip select (Low active)
DC Data/Command control pin (High for data, and low for command)
RST External reset pin (Low for reset)
BUSY Busy state output pin (Low for busy)

SPI timing

This product is an E-paper device adopting the image display technology of Microencapsulated Electrophoretic Display, MED. The initial approach is to create tiny spheres, in which the charged color pigments are suspending in the transparent oil and would move depending on the electronic charge. The E-paper screen display patterns by reflecting the ambient light, so it has no background light requirement. Under ambient light, the E-paper screen still has high visibility with a wide viewing angle of 180 degrees. It is the ideal choice for E-reading. (Note that the e-Paper cannot support updating directly under sunlight)

Communication protocol

1.54inch-e-paper-manual-1.png

Note: Different from the traditional SPI protocol, the data line from the slave to the master is hidden since the device only has a display requirement.

  • CS is the slave chip select. When CS is low, the chip is enabled.
  • DC is data/command control pin, when DC = 0, write command, when DC = 1, write data.
  • SCLK is the SPI communication clock.
  • SDIN is the data line from the master to the slave in SPI communication.

SPI communication has data transfer timing, which is combined with CPHA and CPOL.

  1. CPOL determines the level of the serial synchronous clock at idle state. When CPOL = 0, the level is Low. However, CPOL has little effect to the transmission.
  2. CPHA determines data is collected at the first clock edge or at the second clock edge of the serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.
  • There are 4 SPI communication modes. SPI0 is commonly used, in which CPHL = 0, CPOL = 0.

As you can see from the figure above, data transmission starts at the first falling edge of SCLK, and 8 bits of data are transferred in one clock cycle. Here, SPI0 is in used, and data is transferred by bits, MSB first.

Working protocoal

Pixel & Byte

We define the pixels in a monochrome picture, 0 is black and 1 is white.
White:□,Bit 1
Black:■:Bit 0

  • The dot in the figure is called a pixel. As we know, 1 and 0 are used to define the color, therefore we can use one bit to define the color of one pixel, and 1 byte = 8pixels
  • For example, If we set first 8 pixels to black and the last 8 pixels to white, we show it by codes, they will be 16 bit as below:

E-paper hardware work 1.png
For computer, the data is saved in MSB format:
E-paper hardware work 2.png
So we can use two bytes for 16 pixels.

  • In addition to bicolor displaying, the 3.7inch e-Paper also supports four grayscale.
To display grey pixels, we need to define data for gray
  • Black: 00b
  • Dark Grey: 10b
  • Light Grey: 01b
  • White: 11b
Pixel 1 2 3 4 5 6 7 8
Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Data 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1
Color Black Black Dark Grey Dark Grey Light Grey Light Grey White White
Byte 0x0A 0x5F

The display divides a four-grayscale picture into two pictures. The pixels in the same position of pictures are combined into one pixel.

Register White Light Grey Dark Grey Black
0x24 0x01 0x00 0x01 0x00
0x26 0x01 0x01 0x00 0x00

With the tables above, you can define the data which can be used to display grayscale pixels in the 3.7inch e-Paper

Pixel 1 2 3 4 5 6 7 8
Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Data 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1
Color Black Black Dark Grey Dark Grey Light Grey Light Grey White White
Byte 0x0A 0x5F
Bit in 0x24 register 0 0 1 1 0 0 1 1
Bit in 0x26 register 0 0 0 0 1 1 1 1
Data sent to 0x24 register 0x33
Data sent to 0x26 register 0x0F

We provide several examples for testing, you can test the e-Paper by following the guides. If your developing board is different, you need to write your codes yourself by following the resources.

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
  • Modify the main.c file for corresponding e-Paper
sudo nano examples/main.c
For example, if you want to update a 2.7inch e-Paper/2.7inch e-Paper HAT, you should modify the main.c file, uncomment the line EPD_2in7_test(), comment others, and save.
E-paper rpi change main.png
  • Compile codes
sudo make clean
sudo make
  • Try to run the example
sudo ./epd

Supports type

1.02inch(128×80):

EPD_1in02d_test():Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

EPD_1in54_test(): Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
EPD_1in54_V2_test():Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
EPD_1in54b_test(): Example for 1.54inch e-paper B(Black/White/Red);
EPD_1in54c_test(): Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

EPD_2in7_test(): Example for 2.7inch e-paper(Black/White);
EPD_2in7b_test(): Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

EPD_2in9_test(): Example for 2.9inch e-paper(Black/White);
EPD_2in9bc_test(): Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
EPD_2in9d_test(): Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

EPD_2in13_test(): Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
EPD_2in13_V2_test():Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
EPD_2in13bc_test():Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
EPD_2in13d_test(): Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

EPD_4in2_test(): Example for 4.2inch e-paper(Black/White);
EPD_4in2bc_test(): Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

EPD_5in65f_test(): Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

EPD_5in83_test(): Example for 5.83inch e-paper(Black/White);
EPD_5in83bc_test(): Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

EPD_7in5_test(): Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
EPD_7in5bc_test(): Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
EPD_7in5_V2_test(): Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
EPD_7in5bc_V2_test():Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

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.
sudo python epd_5in65f_test.py

or

sudo python3 epd_5in65f_test.py

Supports type

1.02inch(128×80):

epd_1in02_test.py:Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

epd_1in54_test.py: Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
epd_1in54_V2_test.py:Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
epd_1in54b_test.py: Example for 1.54inch e-paper B(Black/White/Red);
epd_1in54c_test.py: Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

epd_2in7_test.py: Example for 2.7inch e-paper(Black/White);
epd_2in7b_test.py: Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

epd_2in9_test.py: Example for 2.9inch e-paper(Black/White);
epd_2in9bc_test.py: Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
epd_2in9d_test.py: Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

epd_2in13_test.py: Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
epd_2in13_V2_test.py:Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
epd_2in13bc_test.py:Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
epd_2in13d_test.py: Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

epd_4in2_test.py: Example for 4.2inch e-paper(Black/White);
epd_4in2bc_test.py: Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

epd_5in65f_test.py: Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

epd_5in83_test.py: Example for 5.83inch e-paper(Black/White);
epd_5in83bc_test.py: Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

epd_7in5_test.py: Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
epd_7in5bc_test.py: Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
epd_7in5_V2_test.py: Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
epd_7in5bc_V2_test.py:Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

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
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
void Paint_SelectImage(UBYTE *image)
  • The image buffer, it is a pointer of image buffer's first address
Rotate image
This function should be used after Paint_SelectImage()
void Paint_SetRotate(UWORD Rotate)
  • Rotate: The angle rotated. It should be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270
  • Note: For different orientation, the position of the first pixel is different, here we take 1.54inch as example

SPI-epaper-C-0.pngSPI-epaper-C-90.pngSPI-epaper-C-180.pngSPI-epaper-C-270.png

Mirroring
void Paint_SetMirroring(UBYTE mirror)
  • mirror: The type of mirroring. (MIRROR_NONE, MIRROR_HORIZONTAL、MIRROR_VERTICAL、MIRROR_ORIGIN)
Set Pixel
This function is used to set the position and types of the pixel
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  • Xpoint: The x-axis coordination of pixel
  • Ypoint: The y-axis coordination of pixel
  • Color: The color of the pixel
Clear
This function is used to clear the e-Paper
void Paint_Clear(UWORD Color)
  • Color: The color of the display
Clear window
This function is used to clear a partial area
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  • Xstart: The x-axis coordination of the start point
  • Ystart: The y-axis coordination of the start point
  • Xend: The x-axis coordination of the end point
  • Yend: The y-axis coordination of the end point
  • Color: The color of the windows
Draw point

This function is used to draw point.

void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  • Xpoint: The x-axis coordination of point
  • Ypoint: The y-axis coordination of point
  • Dot_Pixel: The size of the point
 	 	 typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  , 	 	// 3 X 3
 	 	 	 DOT_PIXEL_4X4  , 	 	// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
  • Dot_Style: The style of the point
 	 	typedef enum {
 	 	   DOT_FILL_AROUND  = 1,		
 	 	   DOT_FILL_RIGHTUP,
 	 	} DOT_STYLE;
Drawn Line
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style)

This function is used to draw a line

  • Xstart: The start x-axis coordination of the line
  • Ystart: The start y-axis coordination of the line
  • Xend: The end x-axis coordination of the line
  • Yend: The end y-axis coordination of the line
  • Line_width: The width of the line
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
  • Line_style: The style of the line
 	 	typedef enum {
 	 	 	 LINE_STYLE_SOLID = 0,
 	 	 	 LINE_STYLE_DOTTED,
 	 	} LINE_STYLE;
Draw rectangle

Draw a rectangle from (Xstart, Ystart) to (Xend, Yend).

void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  • Xstart: Start coordinate of X-axes of the rectangle
  • Ystart: Start coordinate of Y-axes of the rectangle
  • Xend: End coordinate of X-end of the rectangle
  • Yend: End coordinate of Y-end of the rectangle
  • Color: color of the rectangle
  • Line_width: The width of edges, 8 sides are available;
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	

  • Draw_Fill: set the rectangle full or empty.
typedef enum {
 	DRAW_FILL_EMPTY = 0,
 	DRAW_FILL_FULL,
} DRAW_FILL;
Draw character (ASCII)

Set(Xstart Ystart) as letf-top point, draw a ASCII character.

void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameter:

  • Xstart: X coordinate of the left-top pixel of character;
  • Ystart: Y coordinate of the left-top pixel of character;
  • Ascii_Char:Ascii character;
  • Font: 5 fonts are available;
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of character;
  • Color_Background: color of background;
Draw String

Set point (Xstart Ystart) as the left-top pixel, draw a string.

void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameters:

  • Xstart: X coordinate of left-top pixel of characters;
  • Ystart: Y coordinate of left-top pixel of characters;
  • pString:Pointer of string
  • Font: 5 fonts are available:
    font8:5*8
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of string
  • Color_Background: color of the background
Draw Chinese characters

this function is used to draw Chinese fonts based ON GB2312 fonts.

void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background)

Parameters:

  • Xstart: Coordinate of left-top pixel of characters;
  • Ystart: Coordinate of left-top pixel of characters;
  • pString:Pointer of string;
  • Font: GB2312 fonts:
    font12CN:11*21(ascii),16*21 (Chinese)
    font24CN:24*41(ascii),32*41 (Chinese)
  • Color_Foreground: color of string
  • Color_Background: color of the background
Draw number

Draw a string of numbers, (Xstart, Ystart) is the left-top pixel.

void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameter:

  • Xstart: X coordinate of left-top pixel;
  • Ystart: Y coordicate of left-to pixel;
  • Nummber: the numbers displayed. the numbers are saved in int format, the maximum is 2147483647;
  • Font: 5 fonts are available:
    font8:5*8
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of font;
  • Color_Background: color of background;
Draw image

Send image data of BMP file to buffer

void Paint_DrawBitMap(const unsigned char* image_buffer)

Parameters:

  • image_buffer: adrress of image data in buffer
Read local bmp picture and write it to buffer

Linux platform like Jetson Nano and Raspberry Pi support to directly operate bmp pictures Raspberry Pi & Jetson Nano:RaspberryPi&JetsonNano\c\lib\GUI\GUI_BMPfile.c(.h)

UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart)

Parameters:

  • path:The path of BMP pictures
  • Xstart: X coordination of left-top of picture, default 0;
  • Ystart: Y coordination of left-top of picture, default 0;

Testing Code

In the above part, we describe the tree structures of Linux codes, here we talk about the testing code for user. Raspberry Pi & Jetson Nano: RaspberryPi&JetsonNano\c\examples. The codes in examples are testing code, you can modify the definition in main.c file for different types of e-Paper. For example, if you want to test 2.13inch e-paper, you need to delete the "//" symbol on line 32. Use 5.65inch e-Paper as example, you need to change the line:

//EPD_5in65f_test();

to

EPD_5in65f_test();

Then compile it again and run

make clean
make
sudo ./epd

Python (Can be used for Jetson nano and Raspberry Pi)

It is compatible with python2.7 and python3
python is easy to use than c codes
Raspberry Pi and Jetson Nano:RaspberryPi&JetsonNano\python\lib\

epdconfigu.py

  • Initialize module and exit handle:
def module_init()
def module_exit()

Note:
1. The functions are used to set GPIP before and after driving e-Paper
2. If the board you have is printed with Rev2.1, module enter low-ultra mode after Module_Exit(). (as we test, the current is about 0 in this mode);

  • GPIO Read/Write:
def  digital_write(pin, value)
def  digital_read(pin)
  • SPI Write data:
def spi_writebyte(data)

epdxxx.py(xxx is the type of e-Paper)

  • Initailize e-paper: this function should be used at the begining. It can also be used to wake up e-Paper from Sleep mode.
#For 2.13inch e-Paper、2.9inch e-Paper
def init(self, update) #  Choose lut_full_update or lut_partial_update
#Other type
def init(self)
  • Clear e-paper: This function is used to clear e-Paper to white;
def Clear(self)
def Clear(self, color) # Some types of e-Paper should use this function to clear screen
  • Convert image to arrays
def getbuffer(self, image)
  • Transmit one frame of image data and display
#For two-color e-paper
def display(self, image)

#Because that controllers of 2.13inch e-paper are updated, when partial refresh, they should first use displayPartBaseImage() to display static background, then use displayPart() to dynamaticlly display.
def displayPartBaseImage(self, image)
def displayPart(self, image)
  • Enter sleep mode
def sleep(self)

epd_xxx_test.py(xxx is type of e-paper)

python examples are saved in directory:
Raspberry Pi和Jetson Nano:RaspberryPi&JetsonNano\python\examples\
If the python installed in your OS is python2, you should run examples like below:

sudo python epd_2in13_V2_test.py

If it is python3, the commands should be:

sudo python3 epd_2in13-V2_test.py

Orientation

To rotate the display, you can use transpose function like blackimage = blackimage.transpose(Image.ROTATE_270):

blackimage = blackimage.transpose(Image.ROTATE_270) 
redimage = redimage.transpose(Image.ROTATE_270)
#Support ROTATE_90, ROTATE_180, ROTATE_270

GUI

Python has a powerful PIL library, which can be used directly to drawing figures. Here we use it for drawing

  • Install the library firstly
sudo apt-get install python3-pil 

Import the library

from PIL import Image,ImageDraw,ImageFont

Image: library; ImageDraw: drawing function; ImageFont: fonts

  • Set image buffer for drawing.
image = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame

The first parameter is the depth of color, 1 means 2 grayscale. The second parameter is a tuple of image size. The third parameter is color of the image, 0 is black and 255 is white.

  • Create an image object.
draw = ImageDraw.Draw(image)
  • Draw rectangle
draw.rectangle((0, 10, 200, 34), fill = 0)

The first parameter is a tuple of coordination. 0, 10 is the top-left point of rectangle, 200, 34) is the right-bottom point. fille = 0 set the filled color to black.

  • Draw line
draw.line((16, 60, 56, 60), fill = 0)

The first parameter is a type of coordination, 16, 60 is the begin point, 200, 34 is the end point. fill=0 set the line to black

  • Draw circle
draw.arc((90, 60, 150, 120), 0, 360, fill = 0)

This function is used to draw a encircle of a square. The first parameter is a tuple of coordination of the square. the degree of the circle is 0 to 360 °, fille=0 set the circle to black.
If the figure is not square according to the coordination, you will get an ellipse.。

Besides the arc function, you can also use the chord function for drawing solid circle.

draw.chord((90, 130, 150, 190), 0, 360, fill = 0)

The first parameter is the coordination of the enclosing rectangle. The second and third parameters are the beginning and end degrees of the circle. The fourth parameter is the fill color of the circle.

  • Character

You can directkt import ImageFont model for drawing characters:

font = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)

You can use the fonts of Windows or other fonts which is in ttc format.

To draw English character, you can directly use the fonts; for Chinese character, you need to add a symbol u:

draw.text((8, 12), 'hello world', font = font, fill = 255)
draw.text((8, 36), u'电子墨水屏', font = font, fill = 0)

The first parameter is a tuple of coordination of character, the second parameter is the font and las one is set the color.

  • Read local picture
image = Image.open(os.path.join(picdir, '2in13-v2.bmp'))

The parameter is the path of picture.

  • Other functions.

For more information about the PIL library, please refer to http://effbot.org/imagingbook.

Hardware connection

Because the 40PIN GPIO of Jetson Nano are compatible with Raspberry Pi's and the Jetson.GPIO libraries are compatible with RPi.GPIO, therefore we use the same connection as Raspberry Pi
To connect the e-Paper, you can following the table below
Jetson Nano Connection
e-Paper Jetson Nano Developer Kit
BCM2835 Board
VCC 3.3V 3.3V
GND GND GND
DIN 10(SPI0_MOSI) 19
CLK 11(SPI0_SCK 23
CS 8(SPI0_CS0) 24
DC 25 22
RST 17 11
BUSY 24 18

Install libraries

Open terminal of Jetson Nano and run the following commands to install corresponding libraries:

sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install Jetson.GPIO
sudo groupadd -f -r gpio
sudo usermod -a -G gpio your_user_name
sudo cp /opt/nvidia/jetson-gpio/etc/99-gpio.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger
  • Install I2C libraries
sudo apt-get install python-smbus
  • Install PIL libraries
sudo apt-get install python3-pil
sudo apt-get install python3-numpy

Download demo codes

Open the terminal of Jetson Nano 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
  • Modify the main.c file for corresponding e-Paper
sudo nano examples/main.c
For example, if you want to update a 2.7inch e-Paper/2.7inch e-Paper HAT, you should modify the main.c file, uncomment the line EPD_2in7_test(), comment others, and save.
E-paper rpi change main.png
  • Compile codes
sudo make clean
sudo make
  • Try to run the example
sudo ./epd

Supports type

1.02inch(128×80):

EPD_1in02d_test():Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

EPD_1in54_test(): Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
EPD_1in54_V2_test():Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
EPD_1in54b_test(): Example for 1.54inch e-paper B(Black/White/Red);
EPD_1in54c_test(): Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

EPD_2in7_test(): Example for 2.7inch e-paper(Black/White);
EPD_2in7b_test(): Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

EPD_2in9_test(): Example for 2.9inch e-paper(Black/White);
EPD_2in9bc_test(): Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
EPD_2in9d_test(): Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

EPD_2in13_test(): Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
EPD_2in13_V2_test():Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
EPD_2in13bc_test():Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
EPD_2in13d_test(): Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

EPD_4in2_test(): Example for 4.2inch e-paper(Black/White);
EPD_4in2bc_test(): Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

EPD_5in65f_test(): Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

EPD_5in83_test(): Example for 5.83inch e-paper(Black/White);
EPD_5in83bc_test(): Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

EPD_7in5_test(): Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
EPD_7in5bc_test(): Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
EPD_7in5_V2_test(): Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
EPD_7in5bc_V2_test():Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

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.
sudo python epd_5in65f_test.py

or

sudo python3 epd_5in65f_test.py

Supports type

1.02inch(128×80):

epd_1in02_test.py:Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

epd_1in54_test.py: Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
epd_1in54_V2_test.py:Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
epd_1in54b_test.py: Example for 1.54inch e-paper B(Black/White/Red);
epd_1in54c_test.py: Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

epd_2in7_test.py: Example for 2.7inch e-paper(Black/White);
epd_2in7b_test.py: Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

epd_2in9_test.py: Example for 2.9inch e-paper(Black/White);
epd_2in9bc_test.py: Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
epd_2in9d_test.py: Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

epd_2in13_test.py: Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
epd_2in13_V2_test.py:Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
epd_2in13bc_test.py:Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
epd_2in13d_test.py: Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

epd_4in2_test.py: Example for 4.2inch e-paper(Black/White);
epd_4in2bc_test.py: Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

epd_5in65f_test.py: Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

epd_5in83_test.py: Example for 5.83inch e-paper(Black/White);
epd_5in83bc_test.py: Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

epd_7in5_test.py: Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
epd_7in5bc_test.py: Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
epd_7in5_V2_test.py: Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
epd_7in5bc_V2_test.py:Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

Description of codes (API)

The libraries for Raspberry Pi and Jetson Nano are the 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
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
void Paint_SelectImage(UBYTE *image)
  • The image buffer, it is a pointer of image buffer's first address
Rotate image
This function should be used after Paint_SelectImage()
void Paint_SetRotate(UWORD Rotate)
  • Rotate: The angle rotated. It should be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270
  • Note: For different orientation, the position of the first pixel is different, here we take 1.54inch as example

SPI-epaper-C-0.pngSPI-epaper-C-90.pngSPI-epaper-C-180.pngSPI-epaper-C-270.png

Mirroring
void Paint_SetMirroring(UBYTE mirror)
  • mirror: The type of mirroring. (MIRROR_NONE, MIRROR_HORIZONTAL、MIRROR_VERTICAL、MIRROR_ORIGIN)
Set Pixel
This function is used to set the position and types of the pixel
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  • Xpoint: The x-axis coordination of pixel
  • Ypoint: The y-axis coordination of pixel
  • Color: The color of the pixel
Clear
This function is used to clear the e-Paper
void Paint_Clear(UWORD Color)
  • Color: The color of the display
Clear window
This function is used to clear a partial area
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  • Xstart: The x-axis coordination of the start point
  • Ystart: The y-axis coordination of the start point
  • Xend: The x-axis coordination of the end point
  • Yend: The y-axis coordination of the end point
  • Color: The color of the windows
Draw point

This function is used to draw point.

void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  • Xpoint: The x-axis coordination of point
  • Ypoint: The y-axis coordination of point
  • Dot_Pixel: The size of the point
 	 	 typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  , 	 	// 3 X 3
 	 	 	 DOT_PIXEL_4X4  , 	 	// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
  • Dot_Style: The style of the point
 	 	typedef enum {
 	 	   DOT_FILL_AROUND  = 1,		
 	 	   DOT_FILL_RIGHTUP,
 	 	} DOT_STYLE;
Drawn Line
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style)

This function is used to draw a line

  • Xstart: The start x-axis coordination of the line
  • Ystart: The start y-axis coordination of the line
  • Xend: The end x-axis coordination of the line
  • Yend: The end y-axis coordination of the line
  • Line_width: The width of the line
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
  • Line_style: The style of the line
 	 	typedef enum {
 	 	 	 LINE_STYLE_SOLID = 0,
 	 	 	 LINE_STYLE_DOTTED,
 	 	} LINE_STYLE;
Draw rectangle

Draw a rectangle from (Xstart, Ystart) to (Xend, Yend).

void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  • Xstart: Start coordinate of X-axes of the rectangle
  • Ystart: Start coordinate of Y-axes of the rectangle
  • Xend: End coordinate of X-end of the rectangle
  • Yend: End coordinate of Y-end of the rectangle
  • Color: color of the rectangle
  • Line_width: The width of edges, 8 sides are available;
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	

  • Draw_Fill: set the rectangle full or empty.
typedef enum {
 	DRAW_FILL_EMPTY = 0,
 	DRAW_FILL_FULL,
} DRAW_FILL;
Draw character (ASCII)

Set(Xstart Ystart) as letf-top point, draw a ASCII character.

void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameter:

  • Xstart: X coordinate of the left-top pixel of character;
  • Ystart: Y coordinate of the left-top pixel of character;
  • Ascii_Char:Ascii character;
  • Font: 5 fonts are available;
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of character;
  • Color_Background: color of background;
Draw String

Set point (Xstart Ystart) as the left-top pixel, draw a string.

void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameters:

  • Xstart: X coordinate of left-top pixel of characters;
  • Ystart: Y coordinate of left-top pixel of characters;
  • pString:Pointer of string
  • Font: 5 fonts are available:
    font8:5*8
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of string
  • Color_Background: color of the background
Draw Chinese characters

this function is used to draw Chinese fonts based ON GB2312 fonts.

void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background)

Parameters:

  • Xstart: Coordinate of left-top pixel of characters;
  • Ystart: Coordinate of left-top pixel of characters;
  • pString:Pointer of string;
  • Font: GB2312 fonts:
    font12CN:11*21(ascii),16*21 (Chinese)
    font24CN:24*41(ascii),32*41 (Chinese)
  • Color_Foreground: color of string
  • Color_Background: color of the background
Draw number

Draw a string of numbers, (Xstart, Ystart) is the left-top pixel.

void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)

Parameter:

  • Xstart: X coordinate of left-top pixel;
  • Ystart: Y coordicate of left-to pixel;
  • Nummber: the numbers displayed. the numbers are saved in int format, the maximum is 2147483647;
  • Font: 5 fonts are available:
    font8:5*8
    font12:7*12
    font16:11*16
    font20:14*20
    font24:17*24
  • Color_Foreground: color of font;
  • Color_Background: color of background;
Draw image

Send image data of BMP file to buffer

void Paint_DrawBitMap(const unsigned char* image_buffer)

Parameters:

  • image_buffer: adrress of image data in buffer
Read local bmp picture and write it to buffer

Linux platform like Jetson Nano and Raspberry Pi support to directly operate bmp pictures Raspberry Pi & Jetson Nano:RaspberryPi&JetsonNano\c\lib\GUI\GUI_BMPfile.c(.h)

UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart)

Parameters:

  • path:The path of BMP pictures
  • Xstart: X coordination of left-top of picture, default 0;
  • Ystart: Y coordination of left-top of picture, default 0;

Testing Code

In the above part, we describe the tree structures of Linux codes, here we talk about the testing code for user. Raspberry Pi & Jetson Nano: RaspberryPi&JetsonNano\c\examples. The codes in examples are testing code, you can modify the definition in main.c file for different types of e-Paper. For example, if you want to test 2.13inch e-paper, you need to delete the "//" symbol on line 32. Use 5.65inch e-Paper as example, you need to change the line:

//EPD_5in65f_test();

to

EPD_5in65f_test();

Then compile it again and run

make clean
make
sudo ./epd

Python (Can be used for Jetson nano and Raspberry Pi)

It is compatible with python2.7 and python3
python is easy to use than c codes
Raspberry Pi and Jetson Nano:RaspberryPi&JetsonNano\python\lib\

epdconfigu.py

  • Initialize module and exit handle:
def module_init()
def module_exit()

Note:
1. The functions are used to set GPIP before and after driving e-Paper
2. If the board you have is printed with Rev2.1, module enter low-ultra mode after Module_Exit(). (as we test, the current is about 0 in this mode);

  • GPIO Read/Write:
def  digital_write(pin, value)
def  digital_read(pin)
  • SPI Write data:
def spi_writebyte(data)

epdxxx.py(xxx is the type of e-Paper)

  • Initailize e-paper: this function should be used at the begining. It can also be used to wake up e-Paper from Sleep mode.
#For 2.13inch e-Paper、2.9inch e-Paper
def init(self, update) #  Choose lut_full_update or lut_partial_update
#Other type
def init(self)
  • Clear e-paper: This function is used to clear e-Paper to white;
def Clear(self)
def Clear(self, color) # Some types of e-Paper should use this function to clear screen
  • Convert image to arrays
def getbuffer(self, image)
  • Transmit one frame of image data and display
#For two-color e-paper
def display(self, image)

#Because that controllers of 2.13inch e-paper are updated, when partial refresh, they should first use displayPartBaseImage() to display static background, then use displayPart() to dynamaticlly display.
def displayPartBaseImage(self, image)
def displayPart(self, image)
  • Enter sleep mode
def sleep(self)

epd_xxx_test.py(xxx is type of e-paper)

python examples are saved in directory:
Raspberry Pi and Jetson Nano:RaspberryPi&JetsonNano\python\examples\
If the python installed in your OS is python2, you should run examples like below:

sudo python epd_2in13_V2_test.py

If it is python3, the commands should be:

sudo python3 epd_2in13-V2_test.py

Orientation

To rotate the display, you can use transpose function like blackimage = blackimage.transpose(Image.ROTATE_270):

blackimage = blackimage.transpose(Image.ROTATE_270) 
redimage = redimage.transpose(Image.ROTATE_270)
#Support ROTATE_90, ROTATE_180, ROTATE_270

GUI

Python has a powerful PIL library, which can be used directly to drawing figures. Here we use it for drawing

  • Install the library firstly
sudo apt-get install python3-pil 

Import the library

from PIL import Image,ImageDraw,ImageFont

Image: library; ImageDraw: drawing function; ImageFont: fonts

  • Set image buffer for drawing.
image = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame

The first parameter is the depth of color, 1 means 2 grayscale. The second parameter is a tuple of image size. The third parameter is color of the image, 0 is black and 255 is white.

  • Create an image object.
draw = ImageDraw.Draw(image)
  • Draw rectangle
draw.rectangle((0, 10, 200, 34), fill = 0)

The first parameter is a tuple of coordination. 0, 10 is the top-left point of rectangle, 200, 34) is the right-bottom point. fille = 0 set the filled color to black.

  • Draw line
draw.line((16, 60, 56, 60), fill = 0)

The first parameter is a type of coordination, 16, 60 is the begin point, 200, 34 is the end point. fill=0 set the line to black

  • Draw circle
draw.arc((90, 60, 150, 120), 0, 360, fill = 0)

This function is used to draw a encircle of a square. The first parameter is a tuple of coordination of the square. the degree of the circle is 0 to 360 °, fille=0 set the circle to black.
If the figure is not square according to the coordination, you will get an ellipse.。

Besides the arc function, you can also use the chord function for drawing solid circle.

draw.chord((90, 130, 150, 190), 0, 360, fill = 0)

The first parameter is the coordination of the enclosing rectangle. The second and third parameters are the beginning and end degrees of the circle. The fourth parameter is the fill color of the circle.

  • Character

You can directkt import ImageFont model for drawing characters:

font = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)

You can use the fonts of Windows or other fonts which is in ttc format.

To draw English character, you can directly use the fonts; for Chinese character, you need to add a symbol u:

draw.text((8, 12), 'hello world', font = font, fill = 255)
draw.text((8, 36), u'电子墨水屏', font = font, fill = 0)

The first parameter is a tuple of coordination of character, the second parameter is the font and las one is set the color.

  • Read local picture
image = Image.open(os.path.join(picdir, '2in13-v2.bmp'))

The parameter is the path of picture.

  • Other functions.

For more information about the PIL library, please refer to http://effbot.org/imagingbook.

Hardware connection

The demo codes we provide are based on STM32F103ZET6, the connection table is also based on STM32F103ZET6, if you want to use other chip, you need to port the codes yourself and change the connection according to actual situation.

Connect to STM32F103ZET
e-Paper STM32
Vcc 3.3V
GND GND
DIN PA7
CLK PA5
CS PA4
DC PA2
RST PA1
BUSY PA3
E-paper driver hat to stm32 connet.png

If the STM32 board you have is STM32F103RB, you can refer to the guides of E-Paper Shield

Softawre settings

The codes are based on HAL library. Download the codes and the project files are saved under the STM32\STM32-F103ZET6\MDK-ARM directory.
E-paper stm32 code1.png

Modify main.c, define the line according to the e-paper type and re-compile project and download.
E-paper stm32 code2.png

Supports type

1.02inch(128×80):

EPD_1in02d_test():Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

EPD_1in54_test(): Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
EPD_1in54_V2_test():Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
EPD_1in54b_test(): Example for 1.54inch e-paper B(Black/White/Red);
EPD_1in54c_test(): Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

EPD_2in7_test(): Example for 2.7inch e-paper(Black/White);
EPD_2in7b_test(): Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

EPD_2in9_test(): Example for 2.9inch e-paper(Black/White);
EPD_2in9bc_test(): Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
EPD_2in9d_test(): Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

EPD_2in13_test(): Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
EPD_2in13_V2_test():Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
EPD_2in13bc_test():Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
EPD_2in13d_test(): Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

EPD_4in2_test(): Example for 4.2inch e-paper(Black/White);
EPD_4in2bc_test(): Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

EPD_5in65f_test(): Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

EPD_5in83_test(): Example for 5.83inch e-paper(Black/White);
EPD_5in83bc_test(): Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

EPD_7in5_test(): Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
EPD_7in5bc_test(): Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
EPD_7in5_V2_test(): Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
EPD_7in5bc_V2_test():Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

Codes description

Bottom hardware interface

We package the bottom for different hardware platforms.
You can check the DEV_Config.c(.h) file which is located in \STM32\STM32-F103ZET6\User\Config

  • Data type:
#define UBYTE   uint8_t
#define UWORD   uint16_t
#define UDOUBLE uint32_t
  • Module initialized and exit:
void DEV_Module_Init(void);
void DEV_Module_Exit(void);

Note: 1.The functions are used to set GPIP before and after driving e-Paper.
2..If the board you have is printed with Rev2.1, module enter low-ultra mode after DEV_Module_Exit(). (as we test, the current is about 0 in this mode);

  • GPIO Read/Write:
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE DEV_Digital_Read(UWORD Pin);
  • SPI Write data
void DEV_SPI_WriteByte(UBYTE Value);

Middle EPD driver

The epd driver are saved in: STM32\STM32-F103ZET6\User\e-Paper
Open .h file, functions are declarated here

  • Initialization: It should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
//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、2.9inch e-Paper (D)
void EPD_xxx_Init(UBYTE Mode); //ode = 0 Initialize full refresh; Mode = 1 Initilize partial refresh 
//Other type
void EPD_xxx_Init(void);

xxx is the type of e-paper

  • Clear display: This function is used to clear the e-paper to white
void EPD_xxx_Clear(void); 

xxx is the type of e-Paper.

  • Transmit a frame of image and display
//Black/White e-Paper
void EPD_xxx_Display(UBYTE *Image);
Because controllers of 1.54inch e-paper V2 and 2.13inch e-paper V2 were updated, you need to use EPD_xxx_DisplayPartBaseImage to display static image and ten use EPD_xxx_displayPart() to dymatic display when partial refreshing.
void EPD_2IN13_V2_DisplayPart(UBYTE *Image);
void EPD_2IN13_V2_DisplayPartBaseImage(UBYTE *Image);
  • Enter sleep mode
void EPD_xxx_Sleep(void);

Note, You should hardware reset or use initialize function to wake up e-Paper from sleep mode
xxx is the type of e-Paper

Application function

Basic drawing functions are provided here. You can find they in:\STM32\STM32-F103ZET6\User\GUI\GUI_Paint.c(.h)

The fonts are saved in the directory:\STM32\STM32-F103ZET6\User\Fonts

  • Create a new image buffer: This function is used to create a new image with width, height, Rotate degree and its color.
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
Parameter:
 	image: The buffer of the image, this is a pointer of buffer address;
 	Width: width of the image;
 	Height: Height of the image;
 	Rotate: Rotate degree;
 	Color: Initial color of the image;
  • Select image buffer: this function is used to select the image buffer. You can create multiple image buffer with last function, then select the buffer for every image.
void Paint_SelectImage(UBYTE *image)
Parameter:
 	image: The name of image buffer, it is a pointer of buffer address;
  • Set display orientation: This function is used to set the rotate degree, it is generally be used after Paint_SelectImage(). You can set the rotate degree to 0、90、180、270 degree.
void Paint_SetRotate(UWORD Rotate)
Parameter:
 	Rotate: Rotate degree, you can choose ROTATE_0、ROTATE_90、ROTATE_180、ROTATE_270 which stands for 0、90、180、270 degree repetitively.
SPI-epaper-C-0.pngSPI-epaper-C-90.pngSPI-epaper-C-180.pngSPI-epaper-C-270.png
  • Image mirroring: This function is used to mirror image.
void Paint_SetMirroring(UBYTE mirror)
Parameter:
 	mirror: You can set it to MIRROR_NONE、MIRROR_HORIZONTAL、MIRROR_VERTICAL、MIRROR_ORIGIN
  • Set pixel: this function is used to set the position and color of pixels in the buffer. This is the basic function of GUI.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
Parameter:
 	Xpoint: X-axes in the buffer;
 	Ypoint: Y-axes in buffer;
 	Color: color
  • Clear: This function is used to clear the screen to certain color.
void Paint_Clear(UWORD Color)
Parameter:
 	Color: 
  • Clear windows: this function is used to clear a window. It is generally used for time display.
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
Parameter:
 	Xstart: Start coordinate of X-axes of the window;
 	Ystart: Start coordinate of Y-axes of the window;
 	Xend: End coordinate of X-axes of the window;
 	Yend: End coordinate of Y-axes of the window;
 	Color:
  • Draw point: Draw a point on the position (Xpoint, Ypoint)in buffer
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
Parameter:
 	Xpoint: X coordinate of point;
 	Ypoint: Y coordinate of point;
 	Color: color of point;
 	Dot_Pixel: the size of point, there are 8 sizes available;
 	 	 typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  , 	 	// 3 X 3
 	 	 	 DOT_PIXEL_4X4  , 	 	// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	Dot_Style: style of point. 
 	 	typedef enum {
 	 	   DOT_FILL_AROUND  = 1,		
 	 	   DOT_FILL_RIGHTUP,
 	 	} DOT_STYLE;
  • Draw line: draw a line for (Xstart, Ystart) to (Xend, Yend)
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style)
Parameter:
 	Xstart: Start coordinate of X-axes of line;
 	Ystart: Start coordinate of Y-axes of line;
 	Xend: End coordinate of X-axes of line;
 	Yend: End coordinate of Y-axes of line
 	Color:
 	Line_width: the width of line, 8 sizes are avalilable;
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	 Line_Style: Style of the line;
 	 	typedef enum {
 	 	 	 LINE_STYLE_SOLID = 0,
 	 	 	 LINE_STYLE_DOTTED,
 	 	} LINE_STYLE;
  • Draw rectangle: Draw a rectangle from (Xstart, Ystart) to (Xend, Yend).
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
Parameter:
 	Xstart: Start coordinate of X-axes of rectangle
 	Ystart: Start coordinate of Y-axes of rectangle
 	Xend: End coordinate of X-end of rectangle
 	Yend: End coordinate of Y-end of rectangle
 	Color: color of rectangle
 	Line_width: The width of edges, 8 sides are available;
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	Draw_Fill: set the rectangle full or empty.
 	 	typedef enum {
 	 	 	 DRAW_FILL_EMPTY = 0,
 	 	 	 DRAW_FILL_FULL,
 	 	} DRAW_FILL;
  • Draw circle:Draw a circle, use (X_Center Y_Center) as center;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
Parameter:
 	X_Center: X coordinate of center
 	Y_Center: Y coordinate of center
 	Radius:Radius of circle
 	Color: color of circle
 	Line_width: width of circle, 8 sizes are avalilable
 	 	typedef enum {
 	 	 	 DOT_PIXEL_1X1  = 1,	// 1 x 1
 	 	 	 DOT_PIXEL_2X2  , 		// 2 X 2
 	 	 	 DOT_PIXEL_3X3  ,		// 3 X 3
 	 	 	 DOT_PIXEL_4X4  ,		// 4 X 4
 	 	 	 DOT_PIXEL_5X5  , 		// 5 X 5
 	 	 	 DOT_PIXEL_6X6  , 		// 6 X 6
 	 	 	 DOT_PIXEL_7X7  , 		// 7 X 7
 	 	 	 DOT_PIXEL_8X8  , 		// 8 X 8
 	 	} DOT_PIXEL;
 	Draw_Fill: style of circle
 	 	typedef enum {
 	 	 	 DRAW_FILL_EMPTY = 0,
 	 	 	 DRAW_FILL_FULL,
 	 	} DRAW_FILL;
  • Draw character (ASCII): Set(Xstart Ystart) as letf-top point, draw a ASCII character.
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
Parameter:
 	Xstart: X coordinate of left-top pixel of character;
 	Ystart: Y coordinate of left-top pixel of character;
 	Ascii_Char:Ascii character;
 	Font: 5 fonts are available;
 	 	font8:5*8
 	 	font12:7*12
 	 	font16:11*16
 	 	font20:14*20
 	 	font24:17*24
 	Color_Foreground: color of character;
 	Color_Background: color of background;
  • Draw String: Set point (Xstart Ystart) as the left-top pixel, draw a string.
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
Parameter:
 	Xstart: X coordinate of left-top pixel of characters;
 	Ystart: Y coordinate of left-top pixel of characters;
 	pString:Pointer of string
 	Font: 5 fonts are available:
 	 	font8:5*8
 	 	font12:7*12
 	 	font16:11*16
 	 	font20:14*20
 	 	font24:17*24
 	Color_Foreground: color of string
 	Color_Background: color of background
  • Draw Chinese charactgers: this function is used to draw Chinese fonts based ON GB2312 fonts.
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background)
Parameter:
 	Xstart: Coordinate of left-top pixel of characters;
 	Ystart: Coordinate of left-top pixel of characters;
 	pString:Pointer of string
 	Font: GB2312 fonts
 	 	font12CN:11*21(ascii),16*21 (Chinese)
 	 	font24CN:24*41(ascii),32*41 (Chinese)
 	Color_Foreground: color of string
 	Color_Background: color of background
  • Draw number: Draw a string of numbers, (Xstart, Ystart) is the left-top pixel.
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
Parameter:
 	Xstart: X coordinate of left-top pixel;
 	Ystart: Y coordicate of left-to pixel;
 	Nummber:the numbers displayed. the numbers are saved in int format, the maximum is 2147483647;
 	Font: 5 fonts are available:
 	 	font8:5*8
 	 	font12:7*12
 	 	font16:11*16
 	 	font20:14*20
 	 	font24:17*24
 	Color_Foreground: color of font;
 	Color_Background: color of background;
  • Display time:Display time, (Xstart, Ystart) is the left-top pixel. This function is used for e-Paper which supports partial refresh
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground)
Parameter:
 	Xstart: X coordinate of left-top pixel of character;
 	Ystart: Y coordinate of left-top pixel of character;
 	pTime:Pointer of time displayed;
 	Font: 5 fonts are available;
 	 	font8:5*8
 	 	font12:7*12
 	 	font16:11*16
 	 	font20:14*20
 	 	font24:17*24
 	Color_Foreground: color of fonts
 	Color_Background: color of background
  • Draw image:send image data of bmp file to buffer
void Paint_DrawBitMap(const unsigned char* image_buffer)
Parameter:
 	image_buffer: adrress of image data in buffer

Hardware connection

The demo code provide are bassed on Arduino UNO. If you want to use other Arduino board, you may need to change the connection even porting the codes yourself.
The RAM of Arduino UNO is too small to realize drawing function of e-Paper. In this case, for most of e-Paper, we only make the image display function and save the image to flash. We recommend you to use E-Paper Shield if you use Arduino UNO.

Connect to Arduino UNO
e-Paper Arduino
Vcc 5V
GND GND
DIN D11
CLK D13
CS D10
DC D9
RST D8
BUSY D7
E-paper driver hat to arduino connet.png

Install Arduino IDE

  • Go to Arduino IDE, and download the IDE
  • Install it according to the guide of Arduino website.
  • Open the IDE software after installing.

Run examples

  • Download the deme codes and unzip it. Open the Arduino examples (~/Arduino/…)
  • Open 2.13inch project
  • Open the project and set the board to Arduino UNO
  • Select the correct COM port
  • Build and upload the codes to board

【Note】Because the flash of Arduino UNO is small, we recommend you use MEGA2560 if you use the big size e-Paper

Supports type

1.02inch(128×80):

epd1in02d:Example for 1.02inch e-Paper/1.02inch e-Paper Module

1.54inch(1.54inch e-paper c:152×152,others:200×200):

epd_1in54: Example for 1.54inch e-paper V1(Balck/White): This version is stop production which can be bought before 2019-11-22;
epd_1in54_V2:Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be buy now (2020-07-29). The e-Paper has V2 sticker on the backside.
epd_1in54b: Example for 1.54inch e-paper B(Black/White/Red);
epd_1in54c: Example for 1.54inch e-paper C(Black/White/Red);br />

2.7inch(264×176):

epd_2in7: Example for 2.7inch e-paper(Black/White);
epd_2in7b: Example for 2.7inch e-paper B(Black.White/Red);<be />

2.9inch(296×128):

epd_2in9: Example for 2.9inch e-paper(Black/White);
epd_2in9: Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
epd_2in9: Example for 2.9inch e-paper D(Black/White);

2.13inch(2.13inch e-Paper:250×122,others:212×104):

epd_2in13: Example for 2.13inch e-paper V1(Black/White), this version is stop production and it can be bought before 019-05-15;
epd_2in13_V2:Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);
epd_2in13bc:Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
epd_2in13d: Example for 2.13inch e-paper D(Black/White);

4.2inch(400×300)

epd_4in2: Example for 4.2inch e-paper(Black/White);
epd_4in2bc: Example for 4.2inch e-paper B(Black/White/Red);

5.65inch (600x448)

epd_5in65f: Example for for 5.65inch e-Paper F (Seven-color);

5.83inch(600×448):

epd_5in83: Example for 5.83inch e-paper(Black/White);
epd_5in83bc: Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);

7.5inch(V1:640×384,V2:800×480):

epd_7in5: Example for 7.5inch e-paper(Black/White), this version is stop production and it can be bought before 2019-12-07;
epd_7in5bc: Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stop production and it can be bought before 2019-12-07;
epd_7in5_V2: Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)
epd_7in5bc:Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);

Code Description

Files

Use 2.13inch e-Paper as example, open the folder of epd2in13 v2
E-paper arduino ide codeDescription1.png
epd2in13.ino:The project file
epd2in13.cpp(.h):EPD driver of e-Paper
epdif.cpp(.h): Hardware interface, functions for GPIO and SPI ;
font8.cpp、font12.cpp、font16.cpp、font20.cpp、font24.cpp、fonts.h:为不同大小字符的模;
imagedata.cpp(.h):Image data, which is pre-coverted data for display directly.
The codes are include three parts: Bottom hardware interface, middle EPD driver and application functions.程;

Bottom hardware interface

hardware interfaces are defined in epdif.cpp(.h) file

Write GPIO
void DigitalWrite(int pin, int value)

The first parameter is GPIO, and second parameter is level

Read GPIO
int DigitalRead(int pin)

The parameter is GPIO, and return value is level

Delay
DelayMs(unsigned int delaytime)

Delay time, unit is ms

SPI transmit data
SpiTransfer(unsigned char data)

Type of parameter is char

Hardware initailze
int IfInit(void)

The initialize function of SPI, input/ouptu are packaged here。

Middle EPD driver

Instantiate e-Paper class

The Arduino codes is based on C++, should instantiate e-Paper class is necessary.

Epd epd;
Initialize e-Paper, it should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
  • 2.13inch e-Paper,2.9inch e-Paper
epd.Init(lut_full_update); //Fully update
epd.Init(lut_partial_update); //Partial update
  • 4.2inch e-Paper
epd.Init();
Clear, clear the e-Paper to white
epd.clear();

In some of project, the operation is divided to two part, they work in the same way

epd.ClearFrameMemory(0xFF); 
epd.DisplayFrame();//Display it
Transmit one frame of image and display
void Display(const unsigned char* frame_buffer);
void DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_red); //Three color e-Paper
Sleep
epd.Sleep();

Set the e-Paper enter sleep mode. The consumption of the e-Paper will be reduced. However, you still need to update the display periodically to avoid ghost problem.

Application functions

The drawing functions are defined in this part.
The coordination of the image buffer:
E-paper arduino pic1.png

The functions are defined in epdpaint.h file
E-paper arduino ide codeDescription2.png

Initailze image buffer
Paint(unsigned char* image, int width, int height);

The first parameter is image buffer, the second one is the width of the picture, and the third one is the height.

Paint paint(image, 0, 0);    // width should be the multiple of 8

The second and third parameters are set to 0, you can re-configure them with functions below:

Set the width, height, rotate degree.
int  GetWidth(void); //Get the width
void SetWidth(int width);//Set the width
int  GetHeight(void);//Get the height
void SetHeight(int height);//Set the height
int  GetRotate(void);//Get the degree
void SetRotate(int rotate);//Set the rotate degree
Get the image data
unsigned char* GetImage(void);
Draw circle
void DrawPixel(int x, int y, int colored);

Coordination(x,y)

Draw characater
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);

Set(x,y)as the start point, draw characters ascii_char, set the fonts as font, color is colored.

Draw string
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);

Set(x,y)as the start point, draw the string text, font is font,color is colored

Draw line
void DrawLine(int x0, int y0, int x1, int y1, int colored);

Use (x0,y0)as start point, (x1,y1) as end point;

Draw cross line
void DrawHorizontalLine(int x, int y, int width, int colored);

Set(x0,y0)as start points,draw a line, the widht is width, and color is colored</ br>

Draw a vertical line
void DrawVerticalLine(int x, int y, int height, int colored);

Use(x0,y0) as start point, draw a vertical line, width is height and color is colored./ br>

Draw a empty rectangle
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);

User(x0,y0) as start point,(x1,y1)is end point, draw a rectangel, color of edges are colored.

Draw a full rectangle
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);

Use(x0,y0)as start point, (x1,y1) is end point, draw a rectange, filled it with color: colored

Draw an empty circle
void DrawCircle(int x, int y, int radius, int colored);

Use (x,y)as center,draw a empty circle with radius, color is colored

Draw a full circle
void DrawFilledCircle(int x, int y, int radius, int colored);

Use (x,y)as center, draw a circle, radius is radius, filled with color: colored

Hardware connection

...

Hardware connection

...

Resources

Documentation

Demo code

Related Resources

This is a post in Arduino Form about our SPI e-Paper thanks to ZinggJM, maybe you want to refer to it.

Related applications (shared by user)

FAQ

Question:
Working requirements of e-Paper?
Answer:
  • Two-color B/W e-paper
    • 【Working】Temperature: 0~50°C; Humidity: 35%~65%RH
    • 【Storage】Temperature: ≤30°C; Humidity: ≤55%RH; Max storage time: 6 months
    • 【Transport】Temperature: -25~70°C; Max transport time: 10 days
    • 【Unpack】Temperature: 20°C±5°C; Humidity: 50%RH±5%RH; Max storage time: Should be assembled in 72h
  • Three-Color e-Paper
    • 【Working】Temperature: 0~40°C; Humidity: 35%~65%RH
    • 【Storage】Temperature: ≤30°C; Humidity: ≤55%RH; Max storage time: 3 months
    • 【Transport】Temperature: -25~60°C; Max transport time: 10 days
    • 【Unpack】Temperature: 20°C±5°C; Humidity: 50%RH±5%RH; Max storage time: Should be assembled in 72h

When store three-color e-Paper, please refresh it to white, and keep the screen upward. Note that you need to update it at least every three months.


Question:
What do you need to note about e-Paper refreshing?
Answer:
  • Refresh mode
    • Full refresh: e-Paper flicker when full refreshing to remove ghost image for best display.
    • Partial refresh: It don't flicker if you use partial refresh (only some of the two-color e-paper support partial refresh). Note that you cannot use Partial refresh all the time, you should full refresh e-paper regularly, otherwise, ghost problem will get worse even damage.
  • Refresh rate
    • When using, you should set the update interval at least 180s.(except Partial supportable types)
    • Please set the e-Paper to sleep mode or power off it directly, otherwise, the e-Paper is damaged because of working in high voltage for long time.
    • You need to update the content of three-color e-Paper at least one time every 24h to avoid from burn-in problem.
  • Working place
  • We recommend you to use the e-Paper indoor. If you need to set the e-paper outdoor, Please place the e-paper in shadow and protect it from UV. When you designed you e-paper product, you should take care about the working situation like temperature, humidity, etc.


Question:
How much could the flexible e-paper be bended
Answer:
  • The IC part of e-Paper cannot be bended, you can bend the display area in degree larger than 60°C


Question:
Why the e-Paper cant work with Arduino?
Answer:

The I/O level of Arduino is 5V, and the e-Paper should be driven with 3V3. If your Arduino cant drive the e-Paper successfully, please try to convert the level to 3.3V

You can also try to connect the Vcc pin to the 5V of Arduino to see whether the e-Paper works, but we recommend you not to use 5V for a long time.


Question:
Why does the color of e-Paper look a little black or grey?
Answer:

You can try to change the value of Vcom on demo codes.


Question:
Three-color e-paper looks more red/yellow than the picture on website?
Answer:

Because of different batch, some of them have aberration. Store the e-Paper right side up will reduce it. And if the e-Paper didn't be refreshed for long time, it will become more and more red/yellow. Please use the demo code to refresh the e-paper for several times in this case.


Question:
Why my e-paper has ghosting problem after working for some days
Answer:

Please set the e-paper to sleep mode or disconnect it if you needn't refresh the e-paper but need to power on your development board or Raspberry Pi for long time.Otherwise, the voltage of panel keeps high and it will damage the panel



Question:
Why the FPC of the e-Paper is broken after using for some times?
Answer:
Please make sure you have used it in correct way.

E-Paper FAQ FPC.jpg


Support

Please contact us by Email/Skype/WeChat for technology support.Our response may be delay, you can just leave your questions, we will reply to you as soon as possible in working time.

Service email.png [email protected]
Service skype.png [email protected]
Service wechat.png Webchat Linzeru.png
Service time.png 09:00 - 18:00 (UTC+8 Monday to Staturday)