Difference between revisions of "2.13inch Touch e-Paper HAT"

From Waveshare Wiki
Jump to: navigation, search
Line 40: Line 40:
 
*Power consumption: The power consumption data is experimental test data. The actual power consumption will have a certain deviation due to the existence of the driver board and the actual usage. Please refer to the actual refresh power consumption.
 
*Power consumption: The power consumption data is experimental test data. The actual power consumption will have a certain deviation due to the existence of the driver board and the actual usage. Please refer to the actual refresh power consumption.
  
==SPI Communication Timing==
+
===SPI Communication Timing===
 
[[File:1.54inch-e-paper-manual-1.png|400px]]
 
[[File:1.54inch-e-paper-manual-1.png|400px]]
  

Revision as of 01:43, 18 May 2022

2.13inch Touch e-Paper HAT
2in13 Touch e-Paper HAT info1.jpg

2.13inch Touch EPD HAT For Raspberry Pi, 250×122 Pixels, Black / White, SPI Interface
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

2.13inch Touch e-Paper HAT

Feature

  • Size: 2.13inch
  • Outline dimensions(Module): 69.15 × 38.90mm
  • Outline dimensions(Driver Board): 59.51mm × 34.00mm
  • Display area: 48.55mm × 23.71mm
  • Operating Voltage: 3.3V (V1.1 support 5V)
  • Communication interface: SPI
  • Dot pitch: 0.194 × 0.194mm
  • Resolution: 250×122 pixels
  • Display color: black, white
  • Greyscale: 2
  • Partial refresh time: 0.3s
  • Full refresh time: 2s
  • Refresh power: 26.4mW(typ.)
  • Touchpoints: 5 (MAX)
  • Touch type: Capacitive touch
  • Touch interfaced: I2C
  • Touch panel: Toughened Glass

【Note】

  • Refresh time: The refresh time is experimental test data, there will have some deviation from the actual refresh time, so please refer to the actual refresh time. The e-paper will flicker during the full refresh process, this is a normal phenomenon.
  • Power consumption: The power consumption data is experimental test data. The actual power consumption will have a certain deviation due to the existence of the driver board and the actual usage. Please refer to the actual refresh power consumption.

SPI Communication Timing

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

Since the ink screen only needs to be displayed, the data cable (MISO) sent from the machine and received by the host is hidden here.

  • CS: Slave chip select, when CS is low, the chip is enabled
  • DC: data/command control pin, write command when DC=0; write data when DC=1
  • SCLK: SPI communication clock
  • SDIN: SPI communication master sends, slave receives
  • Timing: CPHL=0, CPOL=0 (SPI0)

[Remarks] For specific information about SPI, you can search for information online.

Working protocoal

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 displays 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)

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 the 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.

Precautions

  1. For the screen that supports partial update, please note that you cannot refresh the screen with the partial mode all the time. After several partial updating, you need to fully refresh the screen once. Otherwise, the screen display effect will be abnormal, which cannot be repaired!
  2. Because of the different batches, some of them have aberrations. Store the e-Paper right side up will reduce it. And if the e-Paper didn't be refreshed for a long time, it will become more and more reddish/yellowish. Please use the demo code to refresh the e-paper several times in this case.
  3. Note that the screen cannot be powered on for a long time. When the screen is not refreshed, please set the screen to sleep mode, or power off the e-Paper. Otherwise, the screen will remain in a high voltage state for a long time, which will damage the e-Paper and cannot be repaired!
  4. When using the e-Paper, it is recommended that the refresh interval be at least 180s, and refresh at least once every 24 hours. If the e-Paper is not used for a long time, the ink screen should be brushed and stored. (Refer to the datasheet for specific storage environment requirements)
  5. After the screen enters sleep mode, the sent image data will be ignored, and it can be refreshed normally only after initializing again.
  6. Control the 0x3C or 0x50 (refer to the datasheet for details) register to adjust the border color. In the routine, you can adjust the Border Waveform Control register or VCOM AND DATA INTERVAL SETTING to set the border.
  7. If you find that the created image data is displayed incorrectly on the screen, it is recommended to check whether the image size setting is correct, change the width and height settings of the image and try again.
  8. The working voltage of the e-Paper is 3.3V. If you buy the raw panel and you need to add a level convert circuit for compatibility with 5V voltage. The new version of the driver board (V2.1 and subsequent versions) has added a level processing circuit, which can support both 3.3V and 5V working environments. The old version can only support a 3.3V working environment. You can confirm the version before using it. (The one with the 20-pin chip on the PCB is generally the new version)
  9. The FPC cable of the screen is relatively fragile, pay attention to bending the cable along the horizontal direction of the screen when using it, and do not bend the cable along the vertical direction of the screen
  10. The screen of e-Paper is relatively fragile, please try to avoid dropping, bumping, and pressing hard.
  11. We recommend that customers use the sample program provided by us to test with the corresponding development board after they get the screen.

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

The program is divided into Hardware Interface, EPD driver and Touch driver, and Application function.

API

C

Hardware Interface

Because of multiple hardware platforms, we package the bottom, for details of how it realizes, you can find in the related directory for certain codes definition in file DEV_Config.c(.h):

For Raspberry Pi, the files are located in Touch_e-Paper_Code\c\lib\Config

The C demo uses 3 methods to drive the e-paper, they are bcm2835, wiringPi, and the IO file. We use the bcm2835 libraries by default, if you need to switch to another library, please open Touch_e-Paper_Code\c\Makefile and modify lines 14-16 as below:

Touch ePaper HAT makefile.jpg

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

Note:

1. The functions are used to set GPIP before and after driving the e-Paper.

2. After entering DEV_Module_Exit(), the whole module will be in low-power mode. According to our test, the power consumption is basically 0.

  • GPIO Read/Write:
UBYTE DEV_Digital_Read(UWORD Pin); void DEV_Digital_Write(UWORD Pin, UBYTE Value);
  • SPI Write data
void DEV_SPI_WriteByte(UBYTE Value); 
void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len);
  • I2C Read/Write:
UBYTE I2C_Read_Byte(UWORD Reg, char *Data, UBYTE len); 
UBYTE I2C_Write_Byte(UWORD Reg, char *Data, UBYTE len);

EPD Driver

For the Raspberry Pi demo, epd driver file is saved in Touch_e-Paper_Code\c\lib\e-paper.

Open the .h file you can see the following function.

  • Initialization: It should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
void EPD_xxx_Init(void);

The xxx is the type of e-paper, for example, if you are using 2.13_V2, then the xxx should be EPD_2IN13_V2_Init().

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

The xxx is the type of e-paper, for example, if you are using 2.13_V2, then the xxx should be EPD_2IN13_V2_Clear().

  • Transmit a frame of image and display.
//Black/White e-Paper
void EPD_xxx_Display(UBYTE *Image);
//Three colors e-Paper
void EPD_xxx_Display(const UBYTE *blackimage, const UBYTE *ryimage);


//Because controller of 2.13inch e-Paper V2 were updated, you need to use EPD_xxx_DisplayPartBaseImage to display static image and then 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, if you are using 2.13_V2, then the xxx should be EPD_2IN13_V2_Sleep().

Touch Driver

For the Raspberry Pi demo, the Touch driver file is saved in Touch_e-Paper_Code\c\lib\Driver

Open .h file you can see the following function. (Take GT1151 as an example.)

  • Touch initialization and related functions:
//initialization
void GT_Init(void); 
//Reset
void GT_Reset(void);
//Read the version information
void GT_ReadVersion(void);

The Reset function and ReadVersion information are called during the initialization.

  • Touch Read/Write:
void GT_Read(UWORD Reg, char *Data, UBYTE len); 
void GT_Write(UWORD Reg, char *Data, UBYTE len); 

Reg is the registered address, Data is the address of the data buffer, and len is the length to be read and written.

  • Scan touch signal
UBYTE GT_Scan(void);

The returned data is stored in the structure GT1151_Dev.

Application Function

Basic drawing functions are provided here. You can find them in: Touch_e-Paper_Code\c\lib\GUI\GUI_Paint.c(.h)
E-paper Driver HAT GUI.png
The fonts are saved in the directory:
Touch_e-Paper_Code\c\lib\Fonts
E-paper Driver HAT Fonts.png

  • Create a new image buffer: This function is used to create a new image with width, height, rotation degree, and color.
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
Parameters:
 	image: The buffer of the image, this is a pointer of the 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 buffers with the last function, and then select the buffer for every image.
void Paint_SelectImage(UBYTE *image)
Parameters:
 	image: The name of the image buffer, it is a pointer of the buffer address;
  • Set display orientation: This function is used to set the rotation degree, it is generally used after Paint_SelectImage(). You can set the rotation degree to 0, 90, 180, or 270 degrees.
void Paint_SetRotate(UWORD Rotate)
Parameters:
 	Rotate: Rotate degree, you can choose ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270 which stands for 0, 90, 180, and 270 degrees repetitively.
Note: Three figures below show the display effect in different degrees. (0°, 90°, 180°, 270°)
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 images.
void Paint_SetMirroring(UBYTE mirror)
Parameters:
 	mirror: You can set it to MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN

The four parameters correspond to no mirroring, horizontal mirroring, vertical mirroring, and image center mirroring.

  • 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)
Parameters:
 	Xpoint: X-axes in the buffer;
 	Ypoint: Y-axes in the buffer;
 	Color: point color
  • Clear: This function is used to clear the screen to a certain color.
void Paint_Clear(UWORD Color)
Parameter:
 	Color: painting 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)
Parameters:
 	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: filling color
  • Draw point: Draw a point on the position (Xpoint, Ypoint)in the 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: the color of point;
 	Dot_Pixel: the size of the 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 the 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 color
 	Line_width: the width of the line, 8 sizes 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;
 	 Line_Style: Style of the line;
 	 	typedef enum {
 	 	 	 LINE_STYLE_SOLID = 0,
 	 	 	 LINE_STYLE_DOTTED,
 	 	} LINE_STYLE;
  • Draw a rectangle: Draw a rectangle from (Xstart, Ystart) to (Xend, Yend). You can choose the color, the width of the line, and whether to fill the inside of the rectangle.
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 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: the rectangle color 
 	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 the center, and draw a circle with a radius of Radius, you can choose the color, the width of the line, and whether to fill the inside of the circle.
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 the center
 	Y_Center: Y coordinate of the center
 	Radius: Radius of circle
 	Color: the color of the circle
 	Line_width: width of the circle, 8 sizes 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: style of circle
 	 	typedef enum {
 	 	 	 DRAW_FILL_EMPTY = 0,
 	 	 	 DRAW_FILL_FULL,
 	 	} DRAW_FILL;
  • Draw character (ASCII): Set(Xstart Ystart) as left-top point, draw a ASCII character. You can choose the Ascii code font library, font foreground color, and font background color.
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 the character;
 	Ystart: Y coordinate of the left-top pixel of the 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: the color of the character;
 	Color_Background: the color of the background;
  • Draw String: Set point (Xstart Ystart) as the left-top pixel, and draw a string. You can choose the Ascii code font library, font foreground color, and font background color.
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
Parameters:
 	Xstart: X coordinate of the left-top pixel of characters;
 	Ystart: Y coordinate of the 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: the color of the string
 	Color_Background: the 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)
Parameter:
 	Xstart: Coordinate of the left-top pixel of characters;
 	Ystart: Coordinate of the 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: the color of string
 	Color_Background: the color of the background
  • Draw number: Draw a string of numbers, (Xstart, Ystart) in 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 a left-top pixel;
 	Ystart: Y coordinate of a 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: the color of the font;
 	Color_Background: the color of the background;
  • Display time: Display time, (Xstart, Ystart) is the left-top pixel. This function is used for e-Paper which supports partial refresh. Because the time required for partial refresh is 0.3S, and the overall display is less than 1S plus data transmission, it can be refreshed once in 1S.
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground)
Parameter:
 	Xstart: X coordinate of the left-top pixel of character;
 	Ystart: Y coordinate of the 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: the color of the fonts
 	Color_Background: the color of the background
  • Draw image: send image data of BMP file to buffer
void Paint_DrawBitMap(const unsigned char* image_buffer)
Parameter:
 	image_buffer: address of image data in the buffer
  • Read local bmp picture and write it to buffer

Linux platforms like Jetson Nano and Raspberry Pi support 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)
Parameter:
	path: The path of BMP pictures
 	Xstart: X coordination of left-top of the picture, default 0;
 	Ystart: Y coordination of left-top of the picture, default 0;

Testing Demo

In the above part, we describe the tree structures of Linux codes, here we talk about the testing code for the user. The test demo is in the Touch_e-Paper_Code\c\examples. This sample demo shows the function of the drawing board and photo album. Users can replace the pictures according to the name and size of the existing pictures to carry out secondary development on the basis of the demo.

Python (Used for Raspberry Pi)

Supports python2.7 and python3.
Python is easy to use than c codes.
Library files are in Touch_e-Paper_Code\python\lib\TP_lib\

epdconfig.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 the e-Paper.

2. The module enters ultra-low power 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 writes data:
def spi_writebyte(data)
  • I2C Read/Write:
def i2c_readbyte(reg, len)
def i2c_write(reg)
def i2c_writebyte(reg, value)

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

If you are using a 2.13-inch V2 e-paper, then xxx should epd2in13_V2.py.

  • Initialization: It should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
def init(self)
  • Clear display: This function is used to clear the e-paper to white.
def Clear(self)
  • Convert the picture to an array.
def getbuffer(self, image)
  • Transmit a frame of image and display.
def display(self, image)
  • 2.13-inch e-Paper V2 was updated, you need to use displayPartBaseImage() to display static image and then use displayPart() to dymatic display when partially refreshing.
displayPart()
def displayPartBaseImage(self, image)
def displayPart(self, image)
  • Enter sleep mode.
def sleep(self)

main.py

The test demo shows the function of the drawing board and photo album. Users can replace the pictures according to the name and size of the existing pictures to carry out secondary development on the basis of the demo.

Orientation

To rotate the display, you can use transpose function:

blackimage = blackimage.transpose(Image.ROTATE_270) 
redimage = redimage.transpose(Image.ROTATE_270)
#Supports OTATE_90, ROTATE_180, ROTATE_270
【Note】Three figures below shows the display effect in different degree. (0°, 90°, 180°, 270°)
SPI-epaper-Python-0.pngSPI-epaper-Python-90.pngSPI-epaper-Python-180.pngSPI-epaper-Python-270.png

Drawing GUI

Python has an image library pil official library link that is very useful. By using this library, you don't need to write code from the logic layer like C. You can directly reference the image library for image processing.

Here we take the 1.54-inch e-paper as an example to briefly explain the program.

  • Install the library:
sudo apt-get install python3-pil
  • Import the library:
from PIL import Image,ImageDraw,ImageFont

Among them, Image is the basic library, ImageDraw is the drawing function library, and ImageFont is the font library.

  • Define an image buffer to facilitate drawing, writing, and other functions on the image.
image = Image.new('1', (epd.width, epd.height), 255)   # 255: clear the frame

The first parameter defines the color depth of the image, defined as 1 means it is a 2-bit image; The second parameter is a Tuple that defines the width and height of the image; The third parameter defines the default color of the buffer, 0 is black, 255 is white.

  • Create a drawing object based on the previous image buffer, all drawing operations are performed on this object.
draw = ImageDraw.Draw(image)
  • Draw a rectangle:
draw.rectangle((0, 10, 200, 34), fill = 0)

The first parameter is a Tuple of 4 elements, (0, 10) is the coordinate value of the upper left corner of the rectangle, (200, 34) is the coordinate value of the lower right corner of the rectangle, fill=0 means that the interior is filled with black

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

The first parameter is a tuple of 4 elements, with (16, 60) as the starting point and (200, 34) as the ending point, draw a straight line, fill=0 means the line is black.

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

Draw an inscribed circle in the square, the first parameter is a tuple of 4 elements, with (90, 60) as the upper left vertex of the square, and (150, 120) as the lower right vertex of the square; Then we stipulate that the horizontal median line of the rectangular box is 0 degrees, and the angle becomes larger clockwise; The second parameter indicates the starting angle, and the third parameter indicates the ending angle. The fill=0 line is black.
If you are not using the square, what you draw will be an ellipse, which is a drawing of an arc.

And you can use chord to draw solid circles:

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

The first parameter specifies the circumscribed rectangle of the chord. The second and third parameters are the start and end angles of the chord respectively. The fourth parameter is the fill color. Connect the chords from 0 degrees to 360 degrees and fill them. It has become a filled circle.

  • Draw character:

Import the ImageFont module:

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

The font files used here are in the Windows directory, but the demo can support other font files which the file name ending with ttc.

You can use them to write English characters directly. For Chinese characters, you need to add an u in front since the encoding is GB2312.

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 2 elements, with (8, 12) as the left vertex, font as font, and fill as the font color.

  • Read the local picture
image = Image.open(os.path.join(picdir, '1in54.bmp'))

The parameter is the image path.

  • Other functions:

If you need to achieve other functions, you can learn to the official website http://effbot.org/imagingbook pil

FAQ

 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.


Support

Support

If you require technical support, please go to the Support page and open a ticket.