2.13inch Touch e-Paper HAT

From Waveshare Wiki
Revision as of 09:25, 18 May 2022 by Eng52 (talk | contribs) (→‎FAQ)
Jump to: navigation, search
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 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 terminal, use command to enter the configuration page
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes  to enable SPI interface

RPI open spi.png
Reboot Raspberry Pi:

sudo reboot

Please make sure that SPI interface was not used by other devices

Enable I2C interface

  • Open terminal, use 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 BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
tar zxvf bcm2835-1.68.tar.gz 
cd bcm2835-1.68/
sudo ./configure && sudo make && sudo make check && sudo make install

For more details, please refer to http://www.airspayce.com/mikem/bcm2835/

  • Install wiringPi libraries
sudo apt-get install wiringpi

#For Pi 4, you need to update it:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
#You will get 2.52 information if you install it correctly
  • Install Python libraries
#python2
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
#python3
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 the demo

Open the terminal of the Raspberry Pi, execute command to download demo codes:

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/examples

【Note】You can switch dependent libraries by modifying lines 14-16 of the Makefile. The program uses BCM2835 by default, which runs the fastest.(If you have already used BCM2835, you need to reboot the system when you switch to another library so that the demo can run normally.)

As shown in the picture below, switch libraries by commenting the lines:

Touch ePaper HAT makefile.jpg

Using the following commands to run the demo:

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.9inch Touch e-paper HAT as an example:

# python2
sudo python2 TP2in9_test.py
# python3
sudo python3 TP2in9_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 the 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 e-Paper.

2.The module enters low-ultra mode after DEV_Module_Exit(). (as we test, the current is about 0 in this mode);

  • 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 Raspberry Pi demo, epd driver file is saved in:Touch_e-Paper_Code\c\lib\e-paper

Open .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 Raspberry Pi demo, Touch driver file is saved in: Touch_e-Paper_Code\c\lib\Driver

Open .h file you can see the following function.

  • 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 register address, Data is the address of the data buffer, 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, Rotate degree and its color.
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
Paratemeters:
 	image : The buffer of image, this is an 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)
Parameters:
 	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)
Parameters:
 	Rotate: Rotate degree, you can choose ROTATE_0、ROTATE_90、ROTATE_180、ROTATE_270 which stands for 0、90、180、270 degree repetitively.
【Note】Three figures below shows the display effect in differen degree. (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 image.
void Paint_SetMirroring(UBYTE mirror)
Paramters:
 	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 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)
Parameters:
 	Xstart: Start coordinate of X-axes of window;
 	Ystart: Start coordinate of Y-axes of window;
 	Xend: End coordinate of X-axes of window;
 	Yend: End coordinate of Y-axes of 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:  color of line
 	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). You can choose the color, the width of the line, 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 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, draw a circle with a radius of Radius, you can choose the color, the width of the line, 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 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. You can choose the Ascii code font library, font foreground color, 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 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. You can choose the Ascii code font library, font foreground color, 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 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: volor of 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 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
  • 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)
Parameter:
	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 demo

In the above part, we describe the tree structures of Linux codes, here we talk about the testing code for 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 e-Paper.

2.The 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)
  • 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 2.13inch 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.13inch e-Paper V2 were updated, you need to use displayPartBaseImage() to display static image and then use displayPart() to dymatic display when partial 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.54inch 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 it 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 base on the previous image buffer, all drawing operations are performed on this object.
draw = ImageDraw.Draw(image)
  • Draw 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 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 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, (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 actually 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 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 more functions, you can learn to the official website http://effbot.org/imagingbook pil

FAQ

Question about Software

 Answer:
*Our demo uses stm32f103zet6. If the customer modifies other models in MDK, such as stm32f103rbt6, the ram space becomes smaller, and the stack size and heap size in the startup file need to be modified on the original basis.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
*Install the imaging library using the command sudo apt-get install python-imaging
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
If it is a three-color screen, when you need to transmit B/W data, use Data Start Transmission 1, when transmitting RED data, use Data Start Transmission 2, because the 2.13inch e-Paper HAT (D) can only display black and white, Therefore, when working in KW mode Data Start Transmission 1, the last data is sent, that is, the so-called old, and 0x00 is directly sent in the program. When Data Start Transmission 2, the data that needs to be refreshed, the so-called "NEW" is sent. data.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The Chinese character library of our routine uses GB2312 encoding method, please change your xxx_test.c file to GB2312 encoding format, compile and download it, and it will display normally
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
You can adjust the value of Vcom in the program to change the display contrast, and the screen improvement effect with local brushing is particularly obvious.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The border display color can be set through the Border Waveform Control register or the VCOM AND DATA INTERVAL SETTING register.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
In this case, the customer needs to reduce the position of the round brush and clear the screen after 5 rounds of brushing (increasing the voltage of VCOM can improve the color, but it will increase the afterimage).
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The process of re-awakening the e-ink screen is actually the process of re-powering on the power. Therefore, when the EPD wakes up, it must first clear the screen, so as to avoid the afterimage phenomenon to the greatest extent.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
*It may be caused by the unsuccessful spi driver

1. First check whether the wiring is correct
2. Check whether the spi is turned on and whether the parameters are configured correctly (spi baud rate, spi mode and other parameters)

{{{3}}}
{{{4}}}

{{{5}}}


Question about Hardware

 Answer:
Yes, now there is a level conversion chip onboard, supporting 3.3V drive
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The rated input voltage of the ink screen is 2.3~3.6V. If it is a 5V system, level conversion is required. In addition, the voltage should not be lower than 2.5V, so as not to affect the display effect of the ink screen.

Device selection can use the model in the schematic diagram we provide or choose according to the data sheet.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Yes, pay attention to the correct timing
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Check if SPI communication is normal

Confirm whether the BUSY pin is normally initialized to input mode
It may be that there is no normal reset, try to shorten the duration of the low level during reset (because the power-off switch is added to the drive circuit, the reset low level is too long, which will cause the drive board to power off and cause the reset to fail) If the busy function sends the 0x71 command, you can try to comment it out

{{{3}}}
{{{4}}}

{{{5}}}


Question about Screen

 Answer:
*【Working conditions】Temperature range: 0~50°C; Humidity range: 35%~65%RH
  • 【Storage conditions】: Temperature range: below 30°C; Humidity range: below 55%RH; Maximum storage time: 6 months
  • 【Transportation conditions】: Temperature range: -25~70°C; Maximum transportation time: 10 days
  • 【After unpacking】: Temperature range: 20°C±5°C; Humidity range: 50±5%RH; Maximum storage time: Assemble within 72 hours
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
*refresh mode
    • Full brush: The electronic ink screen will flicker several times during the refresh process (the number of flickers depends on the refresh time), and the flicker is to remove the afterimage to achieve the best display effect
    • Bureau brush: The electronic ink screen has no flickering effect during the refresh process. Users who use the partial brushing function note that after refreshing several times, a full brush operation should be performed to remove the residual image, otherwise the residual image problem will become more and more serious, or even damage the screen (currently only some black and white e-ink screens support partial brushing, please refer to product page description)
    • refresh rate
    • During use, it is recommended that customers set the refresh interval of the e-ink screen to at least 180 seconds (except products that support the local brush function)
    • During the standby process (that is, after the refresh operation), it is recommended that the customer set the e-ink screen to sleep mode, or power off operation (the power supply part of the ink screen can be disconnected with an analog switch) to reduce power consumption and prolong the life of the e-ink screen. (If some e-ink screens are powered on for a long time, the screen will be damaged beyond repair.)
    • During the use of the three-color e-ink screen, it is recommended that customers update the display screen at least once every 24 hours (if the screen remains the same screen for a long time, the screen burn will be difficult to repair)
  • Application
    • The e-ink screen is recommended for indoor use. If it is used outdoors, it is necessary to avoid direct sunlight on the e-ink screen, and at the same time, take UV protection measures, because charged particles will dry out under strong light for a long time, resulting in loss of activity and failure to refresh. This situation is irreversible. When designing e-ink screen products, customers should pay attention to determine whether the use environment meets the requirements of e-ink screen
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Ideally, with normal use, it can be refreshed 1,000,000 times (1 million times)
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Power on the development board for a long time, after each refresh operation, it is recommended to set the screen to sleep mode or directly power off processing, otherwise the screen may burn out when the screen is in a high voltage state for a long time.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Yes, but you need to re-initialize the electronic paper with software.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Maybe the SPI rate is too high, resulting in data loss, try to reduce the SPI rate

Insufficient or unstable power supply leads to data loss
The data cable is too long to cause data loss, the extension cable should not exceed 20cm

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The display gray scale of electrophoretic electronic paper is determined by the spatial position of the particles in the microcapsule or microcup. The electrophoresis phenomenon occurs between black particles and white particles under the action of voltage. This voltage sequence that promotes the electrophoretic movement of the particles is the driving force of the electronic paper. waveform. The driving waveform is the core part of the electronic paper display, and the optimization of the driving waveform will directly affect the display effect of the display. The driving waveform file is used to describe the parameters formed by the voltage sequence that promotes the electrophoretic movement of the particles, and it needs to be called regularly when the electronic paper is refreshed.

Different batches of e-paper diaphragms and electrophoretic matrices require different voltage values ​​when driving the display due to materials, manufacturing processes, etc. The waveform of the e-ink screen is reflected in the relationship between grayscale, voltage and temperature. Generally speaking, after each batch of electrophoresis matrix is ​​generated, there will be a corresponding waveform file in the form of a .wbf file. The film manufacturer will provide the waveform file and electrophoresis matrix to the manufacturer of the electronic paper screen, and then the The manufacturer of electronic paper screen integrates the protection board, substrate and driver and then provides it to customers; if the waveform file does not correspond to the screen, it is likely that the display cannot be displayed or the display effect is unsatisfactory. Generally, the waveform file has OTP built into the driver IC of the ink screen when leaving the factory, and some programs we provide also call external waveform files to drive the e-ink screen.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
LUT is the abbreviation of LOOK UP TABLE, and OTP is the abbreviation of ONE TIME PROGRAM. The original intention of LUT is to load waveform files, and the waveform files are divided into OTP and REGISTER. Among them, OTP is the built-in waveform storage method, and REGISTER is the external waveform storage method.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
There are mainly two types of ink screens

One is to brush the background image first
The other is to alternately refresh old data and new data

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Simultaneous brushing in different locations needs to be operated in the program design, that is, first brushing the data of different locations into the electronic paper IC, and finally doing the Updata/TurnOnDisplay uniformly.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Yes, when e-Paper is batched, there will be some color difference, which is a normal phenomenon. Store the e-paper face up to reduce the reddish/yellowishness to a certain extent.
{{{3}}}
{{{4}}}

{{{5}}}


Others

 Answer:
with film
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
0.5mm pitch, 24Pin.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Cable socket 0.5-24pin rear flip type 2.0H (FPC connector)
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
At present, all screens have built-in temperature sensors, and external LM75 temperature sensors can also be used with IIC pins.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
The full brush initialization function needs to be added when the ink screen is switched from partial brush to full brush
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
It may be a demo based on the BCM2835 library that has run the C language before. At this time, you need to restart the Raspberry Pi and then run the python demo
{{{3}}}
{{{4}}}

{{{5}}}


Support