Difference between revisions of "Template:Pico e-Paper Guide"
m (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/") |
|||
(36 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
=RPi Pico= | =RPi Pico= | ||
− | + | ==Hardware Connection== | |
− | + | Please take care of the direction when connecting Pico. A logo of the USB port is printed to indicate the directory, you can also check the pins.<br /> | |
− | Please take care of the direction when connecting Pico. A logo of USB port is printed to indicate the directory, you can | + | If you want to connect the board by an 8-pin cable, you can refer to the table below:<br /> |
− | If you want to connect the board by | ||
{|border=1; style="width:100%; max-width:700px;" align="center" | {|border=1; style="width:100%; max-width:700px;" align="center" | ||
− | |-style="background: | + | |-style="background:green; color:white;" align="center" |
|e-Paper || Pico || Description | |e-Paper || Pico || Description | ||
|-align="center" | |-align="center" | ||
|VCC || VSYS || Power input | |VCC || VSYS || Power input | ||
|-align="center" | |-align="center" | ||
− | |GND || GND || | + | |GND || GND || Ground |
|-align="center" | |-align="center" | ||
|DIN || GP11 || MOSI pin of SPI interface, data transmitted from Master to Slave. | |DIN || GP11 || MOSI pin of SPI interface, data transmitted from Master to Slave. | ||
Line 16: | Line 15: | ||
|CLK || GP10 || SCK pin of SPI interface, clock input | |CLK || GP10 || SCK pin of SPI interface, clock input | ||
|-align="center" | |-align="center" | ||
− | |CS || GP9 || Chip select pin of SPI interface, Low | + | |CS || GP9 || Chip select pin of SPI interface, Low Active |
|-align="center" | |-align="center" | ||
|DC || GP8 || Data/Command control pin (High: Data; Low: Command) | |DC || GP8 || Data/Command control pin (High: Data; Low: Command) | ||
Line 22: | Line 21: | ||
|RST || GP12 || Reset pin, low active | |RST || GP12 || Reset pin, low active | ||
|-align="center" | |-align="center" | ||
− | |BUSY || GP13 || Busy pin | + | |BUSY || GP13 || Busy output pin |
+ | |-align="center" | ||
+ | |KEY0||GP2||User key 0 | ||
+ | |-align="center" | ||
+ | |KEY1||GP3||User key 1 | ||
+ | |-align="center" | ||
+ | |RUN||RUN||Reset | ||
|} | |} | ||
− | You can just attach the board to Pico like the Pico-ePaper- | + | You can just attach the board to Pico like the Pico-ePaper-7.5.<br/> |
− | [[File:Pico-ePaper- | + | [[File: Pico-ePaper-connect020.jpg|600px]] |
===Setup Environment=== | ===Setup Environment=== | ||
− | You can refer to the guides | + | You can refer to the guides for Raspberry Pi: https://www.raspberrypi.org/documentation/pico/getting-started/ <br/> |
===Download Demo codes=== | ===Download Demo codes=== | ||
Open a terminal of Pi and run the following command:<br /> | Open a terminal of Pi and run the following command:<br /> | ||
<pre> | <pre> | ||
− | |||
cd ~ | cd ~ | ||
− | sudo wget https:// | + | sudo wget https://files.waveshare.com/upload/2/27/Pico_ePaper_Code.zip |
unzip Pico_ePaper_Code.zip -d Pico_ePaper_Code | unzip Pico_ePaper_Code.zip -d Pico_ePaper_Code | ||
cd ~/Pico_ePaper_Code | cd ~/Pico_ePaper_Code | ||
</pre> | </pre> | ||
− | You can also clone the codes from | + | You can also clone the codes from Github. |
<pre> | <pre> | ||
− | git https://github.com/waveshare/Pico_ePaper_Code | + | cd ~ |
− | cd | + | git clone https://github.com/waveshare/Pico_ePaper_Code.git |
+ | cd ~/Pico_ePaper_Code | ||
</pre> | </pre> | ||
Line 49: | Line 54: | ||
The guides are based on Raspberry Pi. | The guides are based on Raspberry Pi. | ||
====='''C codes'''===== | ====='''C codes'''===== | ||
− | The example provided is compatible | + | The example provided is compatible with several types, you need to modify the main.c file, uncomment the definition according to the actual type of display you get.<br/> |
− | For example, if you have the Pico-ePaper-2.13, please modify the main.c file, uncomment line 18(or maybe it is line | + | For example, if you have the Pico-ePaper-2.13, please modify the main.c file, uncomment line 18 (or maybe it is line 19).<br/> |
− | [[File:E-paper_for_Pico_use_1.png|300px]]<br/> | + | [[File:E-paper_for_Pico_use_1.png|thumb|300px|right]]<br/> |
− | + | Set the project: | |
<pre> | <pre> | ||
cd ~/Pico_ePaper_Code/c | cd ~/Pico_ePaper_Code/c | ||
</pre> | </pre> | ||
− | Create build folder and add the SDK. ../../pico-sdk is the default path of the SDK, if you save the SDK to other | + | Create build folder and add the SDK. ../../pico-sdk is the default path of the SDK, if you save the SDK to other directories, please change it to the actual path. |
<pre> | <pre> | ||
mkdir build | mkdir build | ||
Line 67: | Line 72: | ||
cmake .. | cmake .. | ||
</pre> | </pre> | ||
− | Run the | + | Run the command make to compile the codes. |
<pre> | <pre> | ||
make -j9 | make -j9 | ||
</pre> | </pre> | ||
− | *After compiling, the epd.uf2 file is generated. Next, press and hold the BOOTSEL button on the Pico board, connect the Pico to the Raspberry Pi using the Micro USB cable, and release the button. At this point, the device will recognize a removable disk (RPI-RP2)<br/> | + | *After compiling, the epd.uf2 file is generated. Next, press and hold the BOOTSEL button on the Pico board, connect the Pico to the Raspberry Pi using the Micro USB cable, and release the button. At this point, the device will recognize a removable disk (RPI-RP2).<br/> |
− | *Copy the epd.uf2 file just generated to the newly recognized removable disk (RPI-RP2), Pico will automatically restart the running program<br/> | + | *Copy the epd.uf2 file just generated to the newly recognized removable disk (RPI-RP2), Pico will automatically restart the running program.<br/> |
===='''Python'''==== | ===='''Python'''==== | ||
− | *First press and hold the BOOTSEL button on the Pico board, use the Micro USB cable to connect the Pico to the Raspberry Pi, then release the button. At this point, the device will recognize a removable disk (RPI-RP2)<br/> | + | *First press and hold the BOOTSEL button on the Pico board, use the Micro USB cable to connect the Pico to the Raspberry Pi, then release the button. At this point, the device will recognize a removable disk (RPI-RP2).<br/> |
− | *Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the removable disk (RPI-RP2) just identified<br/> | + | *Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the removable disk (RPI-RP2) just identified.<br/> |
− | *Update Thonny IDE | + | *Update Thonny IDE. |
sudo apt upgrade thonny | sudo apt upgrade thonny | ||
*Open Thonny IDE (click on the Raspberry logo -> Programming -> Thonny Python IDE ), and select the interpreter:<br/> | *Open Thonny IDE (click on the Raspberry logo -> Programming -> Thonny Python IDE ), and select the interpreter:<br/> | ||
− | **Select Tools -> Options... -> Interpreter<br/> | + | **Select Tools -> Options... -> Interpreter.<br/> |
− | **Select MicroPython (Raspberry Pi Pico and ttyACM0 port<br/> | + | **Select MicroPython (Raspberry Pi Pico and ttyACM0 port).<br/> |
− | *Open the Pico_ePaper-xxx.py file in Thonny IDE, then run the current script (click the green triangle)<br/> | + | *Open the Pico_ePaper-xxx.py file in Thonny IDE, then run the current script (click the green triangle).<br/> |
===C Code Analysis=== | ===C Code Analysis=== | ||
===='''Bottom Hardware Interface'''==== | ===='''Bottom Hardware Interface'''==== | ||
We package the hardware layer for easily porting to the different hardware platforms.<br /> | We package the hardware layer for easily porting to the different hardware platforms.<br /> | ||
− | DEV_Config.c(.h) in the directory:Pico_ePaper_Code\c\lib\Config<br /> | + | DEV_Config.c(.h) in the directory: Pico_ePaper_Code\c\lib\Config.<br /> |
− | *Data | + | *Data type: |
#define UBYTE uint8_t | #define UBYTE uint8_t | ||
#define UWORD uint16_t | #define UWORD uint16_t | ||
Line 96: | Line 101: | ||
void DEV_Module_Exit(void); | void DEV_Module_Exit(void); | ||
Note: | Note: | ||
− | 1.The functions above are used to initialize the display or exit handle. | + | 1. The functions above are used to initialize the display or exit handle. |
− | *GPIO Write/ | + | *GPIO Write/Read: |
void DEV_Digital_Write(UWORD Pin, UBYTE Value); | void DEV_Digital_Write(UWORD Pin, UBYTE Value); | ||
UBYTE DEV_Digital_Read(UWORD Pin); | UBYTE DEV_Digital_Read(UWORD Pin); | ||
− | *SPI | + | *SPI transmits data: |
void DEV_SPI_WriteByte(UBYTE Value); | void DEV_SPI_WriteByte(UBYTE Value); | ||
===='''EPD driver'''==== | ===='''EPD driver'''==== | ||
− | The driver codes of EPD | + | The driver codes of EPD are saved in the directory: Pico_ePaper_Code\c\lib\e-Paper<br /> |
Open the .h header file, you can check all the functions defined.<br /> | Open the .h header file, you can check all the functions defined.<br /> | ||
*Initialize e-Paper, this function is always used at the beginning and after waking up the display. | *Initialize e-Paper, this function is always used at the beginning and after waking up the display. | ||
− | '''//2.13inch e- | + | '''//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); // Mode = 0 fully update, Mode = 1 partial update | void EPD_xxx_Init(UBYTE Mode); // Mode = 0 fully update, Mode = 1 partial update | ||
'''//Other types | '''//Other types | ||
void EPD_xxx_Init(void); | void EPD_xxx_Init(void); | ||
− | xxx should be changed by the type of e-Paper, For example, if you use 2.13inch e-Paper (D), to fully update, | + | xxx should be changed by the type of e-Paper, For example, if you use 2.13inch e-Paper (D), to fully update, it should be EPD_2IN13D_Init(0) and EPD_2IN13D_Init(1) for the partial update; |
*Clear: this function is used to clear the display to white. | *Clear: this function is used to clear the display to white. | ||
Line 123: | Line 128: | ||
void EPD_xxx_Display(const UBYTE *blackimage, const UBYTE *ryimage); | void EPD_xxx_Display(const UBYTE *blackimage, const UBYTE *ryimage); | ||
− | '''There are several types which are different from others<br /> | + | ''' There are several types which are different from others<br /> |
− | '''// | + | '''//Partial update for 2.13inch e-paper (D), 2.9inch e-paper (D) |
void EPD_2IN13D_DisplayPart(UBYTE *Image); | void EPD_2IN13D_DisplayPart(UBYTE *Image); | ||
void EPD_2IN9D_DisplayPart(UBYTE *Image); | void EPD_2IN9D_DisplayPart(UBYTE *Image); | ||
Line 135: | Line 140: | ||
void EPD_xxx_Sleep(void); | void EPD_xxx_Sleep(void); | ||
Note, You should only hardware reset or use initialize function to wake up e-Paper from sleep mode<br /> | Note, You should only hardware reset or use initialize function to wake up e-Paper from sleep mode<br /> | ||
− | xxx is the type of e-Paper, for example, if you use 2.13inch e-Paper D, it should be EPD_2IN13D_Sleep() | + | xxx is the type of e-Paper, for example, if you use 2.13inch e-Paper D, it should be EPD_2IN13D_Sleep().<br /> |
===='''Application Programming Interface'''==== | ===='''Application Programming Interface'''==== | ||
− | We provide basic GUI functions for testing, like draw point, line, string, and so on. The GUI function can be found in the directory: RaspberryPi_JetsonNano\c\lib\GUI\GUI_Paint.c(.h)<br /> | + | We provide basic GUI functions for testing, like draw point, line, string, and so on. The GUI function can be found in the directory: RaspberryPi_JetsonNano\c\lib\GUI\GUI_Paint.c(.h).<br /> |
[[file:e-paper_Driver_HAT_GUI.png|700px]]<br /> | [[file:e-paper_Driver_HAT_GUI.png|700px]]<br /> | ||
− | The fonts used can be found in directory: RaspberryPi_JetsonNano\c\lib\Fonts<br /> | + | The fonts used can be found in the directory: RaspberryPi_JetsonNano\c\lib\Fonts.<br /> |
[[file:e-paper_Driver_HAT_Fonts.png|700px]]<br /> | [[file:e-paper_Driver_HAT_Fonts.png|700px]]<br /> | ||
− | *Create a new image, you can set the image name, width, height, rotate angle and color. | + | *Create a new image, you can set the image name, width, height, rotate angle, and color. |
<pre> | <pre> | ||
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) | void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) | ||
Parameters: | Parameters: | ||
− | image : Name of the image buffer, this is a pointer; | + | image: Name of the image buffer, this is a pointer; |
− | Width : Width of the image; | + | Width: Width of the image; |
Height: Height of the image; | Height: Height of the image; | ||
− | Rotate: Rotate angle of the Image; | + | Rotate: Rotate the angle of the Image; |
− | Color : The initial color of the image; | + | Color: The initial color of the image; |
</pre> | </pre> | ||
− | *Select image buffer: You can create multiple image buffers at the same time and select the certain one and | + | *Select image buffer: You can create multiple image buffers at the same time and select the certain one and draw by this function. |
<pre>void Paint_SelectImage(UBYTE *image) | <pre>void Paint_SelectImage(UBYTE *image) | ||
Parameters: | Parameters: | ||
Line 159: | Line 164: | ||
</pre> | </pre> | ||
− | *Rotate image: You need to set the | + | *Rotate image: You need to set the rotation angle of the image, this function should be used after Paint_SelectImage(). The angle can be 0, 90, 180, or 270. |
<pre>void Paint_SetRotate(UWORD Rotate) | <pre>void Paint_SetRotate(UWORD Rotate) | ||
Parameters: | Parameters: | ||
− | Rotate: Rotate angle of the image, the parameter can be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270. | + | Rotate: Rotate the angle of the image, the parameter can be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270. |
</pre> | </pre> | ||
− | : | + | :【Note】After rotating, the place of the first pixel is different, we take a 1.54-inch e-paper as an example. |
:[[File:SPI-epaper-C-0.png|200px]] [[File:SPI-epaper-C-90.png|200px]] [[File:SPI-epaper-C-180.png|200px]][[File:SPI-epaper-C-270.png|200px]] | :[[File:SPI-epaper-C-0.png|200px]] [[File:SPI-epaper-C-90.png|200px]] [[File:SPI-epaper-C-180.png|200px]][[File:SPI-epaper-C-270.png|200px]] | ||
Line 170: | Line 175: | ||
<pre>void Paint_SetMirroring(UBYTE mirror) | <pre>void Paint_SetMirroring(UBYTE mirror) | ||
Parameters: | Parameters: | ||
− | mirror: Mirror type if the image, the parameter can be | + | mirror: Mirror type if the image, the parameter can be MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN. |
</pre> | </pre> | ||
*Set the position and color of pixels: This is the basic function of GUI, it is used to set the position and color of a pixel in the buffer. | *Set the position and color of pixels: This is the basic function of GUI, it is used to set the position and color of a pixel in the buffer. | ||
Line 178: | Line 183: | ||
Xpoint: The X-axis value of the point in the image buffer | Xpoint: The X-axis value of the point in the image buffer | ||
Ypoint: The Y-axis value of the point in the image buffer | Ypoint: The Y-axis value of the point in the image buffer | ||
− | Color : The color of the point | + | Color: The color of the point |
</pre> | </pre> | ||
Line 188: | Line 193: | ||
</pre> | </pre> | ||
− | *Color of the windows: This function is used to set the color of windows, it always used for updating partial areas like displaying a clock. | + | *Color of the windows: This function is used to set the color of windows, it is always used for updating partial areas like displaying a clock. |
<pre> | <pre> | ||
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) | void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) | ||
Line 199: | Line 204: | ||
</pre> | </pre> | ||
− | *Draw point: Draw a point at the position | + | *Draw point: Draw a point at the position (X point, Y point) of the image buffer, you can configure the color, size, and style. |
<pre> | <pre> | ||
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) | void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) | ||
Line 217: | Line 222: | ||
DOT_PIXEL_8X8 , // 8 X 8 | DOT_PIXEL_8X8 , // 8 X 8 | ||
} DOT_PIXEL; | } DOT_PIXEL; | ||
− | Dot_Style: Style of the point, | + | Dot_Style: Style of the point, define the extended mode of the point. |
typedef enum { | typedef enum { | ||
DOT_FILL_AROUND = 1, | DOT_FILL_AROUND = 1, | ||
Line 224: | Line 229: | ||
</pre> | </pre> | ||
− | *Draw line: Draw a | + | *Draw the line: Draw a line from (Xstart, Ystart) to (Xend, Yend) in the image buffer, you can configure the color, width, and style. |
<pre> | <pre> | ||
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) | void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) | ||
Line 251: | Line 256: | ||
</pre> | </pre> | ||
− | *Draw rectangle: Draw a rectangle from (Xstart, Ystart) to (Xend, Yend) , you can configure the color, width, and style. | + | *Draw a rectangle: Draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can configure the color, width, and style. |
<pre> | <pre> | ||
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) | void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) | ||
Line 278: | Line 283: | ||
</pre> | </pre> | ||
− | *Draw circle: Draw a circle in image buffer, use (X_Center Y_Center) as center and Radius as radius. You can configure the color, width of line and the style of circle. | + | *Draw circle: Draw a circle in the image buffer, use (X_Center Y_Center) as the center and Radius as the radius. You can configure the color, width of the line, and the style of the circle. |
<pre> | <pre> | ||
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) | void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) | ||
Line 284: | Line 289: | ||
X_Center: X-axis of center | X_Center: X-axis of center | ||
Y_Center: Y-axis of center | Y_Center: Y-axis of center | ||
− | + | Radius: Radius of circle | |
Color: Color of the circle | Color: Color of the circle | ||
Line_width: The width of arc, 8 sizes are available. | Line_width: The width of arc, 8 sizes are available. | ||
Line 304: | Line 309: | ||
</pre> | </pre> | ||
− | *Show Ascii character: Show a | + | *Show Ascii character: Show a character in (Xstart, Ystart) position, you can configure the font, foreground, and background. |
<pre> | <pre> | ||
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | ||
Line 310: | Line 315: | ||
Xstart: Xstart of the character | Xstart: Xstart of the character | ||
Ystart: Ystart of the character | Ystart: Ystart of the character | ||
− | + | Ascii_Char: Ascii char | |
Font: five fonts are avaialble: | Font: five fonts are avaialble: | ||
− | + | font8: 5*8 | |
− | + | font12: 7*12 | |
− | + | font16: 11*16 | |
− | + | font20: 14*20 | |
− | + | font24: 17*24 | |
Color_Foreground: foreground color | Color_Foreground: foreground color | ||
Color_Background: background color | Color_Background: background color | ||
</pre> | </pre> | ||
− | *Draw string: Draw string at (Xstart Ystart) , you can configure the fonts, foreground and the background | + | *Draw the string: Draw the string at (Xstart Ystart), you can configure the fonts, foreground, and the background |
<pre> | <pre> | ||
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | ||
Line 327: | Line 332: | ||
Xstart: Xstart of the string | Xstart: Xstart of the string | ||
Ystart: Ystart of the string | Ystart: Ystart of the string | ||
− | + | pString: String | |
Font: five fonts are available: | Font: five fonts are available: | ||
− | + | font8: 5*8 | |
− | + | font12: 7*12 | |
− | + | font16: 11*16 | |
− | + | font20: 14*20 | |
− | + | font24: 17*24 | |
Color_Foreground: foreground color | Color_Foreground: foreground color | ||
Color_Background: background color | Color_Background: background color | ||
</pre> | </pre> | ||
− | *Draw | + | *Draw Chinese string: Draw the Chinese string at (Xstart Ystart) of the image buffer. You can configure fonts (GB2312), foreground, and background. |
<pre> | <pre> | ||
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) | void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) | ||
Line 344: | Line 349: | ||
Xstart: Xstart of string | Xstart: Xstart of string | ||
Ystart: Ystart of string | Ystart: Ystart of string | ||
− | + | pString: string | |
Font: GB2312 fonts, two fonts are available | Font: GB2312 fonts, two fonts are available | ||
− | + | font12CN: ascii 11*21,Chinese 16*21 | |
− | + | font24CN: ascii 24*41,Chinese 32*41 | |
Color_Foreground: Foreground color | Color_Foreground: Foreground color | ||
Color_Background: Background color | Color_Background: Background color | ||
</pre> | </pre> | ||
− | *Draw number: Draw numbers at (Xstart Ystart) of image buffer. You can select font, foreground and | + | *Draw number: Draw numbers at (Xstart Ystart) of the image buffer. You can select font, foreground, and background. |
<pre> | <pre> | ||
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) | ||
Line 358: | Line 363: | ||
Xstart: Xstart of numbers | Xstart: Xstart of numbers | ||
Ystart: Ystart of numbers | Ystart: Ystart of numbers | ||
− | + | Nummber: numbers displayed. It supports int type and 2147483647 is the maximum supported | |
Font: Ascii fonts, five fonts are available: | Font: Ascii fonts, five fonts are available: | ||
− | + | font8: 5*8 | |
− | + | font12: 7*12 | |
− | + | font16: 11*16 | |
− | + | font20: 14*20 | |
− | + | font24: 17*24 | |
Color_Foreground: foreground | Color_Foreground: foreground | ||
Color_Background: background | Color_Background: background | ||
</pre> | </pre> | ||
− | *Display time: Display time at (Xstart Ystart) of image buffer, you can configure fonts, foreground, and background. | + | *Display time: Display time at (Xstart Ystart) of the image buffer, you can configure fonts, foreground, and background. |
− | :This function is used for partial | + | : This function is used for partial updating. Note that some of the e-Paper don't support partial updates and you cannot use partial updates all the time, which will have ghosts problems and destroy the display. |
<pre> | <pre> | ||
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) | void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) | ||
Line 376: | Line 381: | ||
Xstart: Xstart of time | Xstart: Xstart of time | ||
Ystart: Ystart of time | Ystart: Ystart of time | ||
− | + | pTime: Structure of time | |
− | Font: Ascii font, five fonts are | + | Font: Ascii font, five fonts are available |
− | + | font8: 5*8 | |
− | + | font12: 7*12 | |
− | + | font16: 11*16 | |
− | + | font20: 14*20 | |
− | + | font24: 17*24 | |
Color_Foreground: foreground | Color_Foreground: foreground | ||
Color_Background: background | Color_Background: background | ||
</pre> | </pre> |
Latest revision as of 06:50, 2 September 2023
RPi Pico
Hardware Connection
Please take care of the direction when connecting Pico. A logo of the USB port is printed to indicate the directory, you can also check the pins.
If you want to connect the board by an 8-pin cable, you can refer to the table below:
e-Paper | Pico | Description |
VCC | VSYS | Power input |
GND | GND | Ground |
DIN | GP11 | MOSI pin of SPI interface, data transmitted from Master to Slave. |
CLK | GP10 | SCK pin of SPI interface, clock input |
CS | GP9 | Chip select pin of SPI interface, Low Active |
DC | GP8 | Data/Command control pin (High: Data; Low: Command) |
RST | GP12 | Reset pin, low active |
BUSY | GP13 | Busy output pin |
KEY0 | GP2 | User key 0 |
KEY1 | GP3 | User key 1 |
RUN | RUN | Reset |
You can just attach the board to Pico like the Pico-ePaper-7.5.
Setup Environment
You can refer to the guides for Raspberry Pi: https://www.raspberrypi.org/documentation/pico/getting-started/
Download Demo codes
Open a terminal of Pi and run the following command:
cd ~ sudo wget https://files.waveshare.com/upload/2/27/Pico_ePaper_Code.zip unzip Pico_ePaper_Code.zip -d Pico_ePaper_Code cd ~/Pico_ePaper_Code
You can also clone the codes from Github.
cd ~ git clone https://github.com/waveshare/Pico_ePaper_Code.git cd ~/Pico_ePaper_Code
About the examples
The guides are based on Raspberry Pi.
C codes
The example provided is compatible with several types, you need to modify the main.c file, uncomment the definition according to the actual type of display you get.
For example, if you have the Pico-ePaper-2.13, please modify the main.c file, uncomment line 18 (or maybe it is line 19).
Set the project:
cd ~/Pico_ePaper_Code/c
Create build folder and add the SDK. ../../pico-sdk is the default path of the SDK, if you save the SDK to other directories, please change it to the actual path.
mkdir build cd build export PICO_SDK_PATH=../../pico-sdk
Run cmake command to generate Makefile file.
cmake ..
Run the command make to compile the codes.
make -j9
- After compiling, the epd.uf2 file is generated. Next, press and hold the BOOTSEL button on the Pico board, connect the Pico to the Raspberry Pi using the Micro USB cable, and release the button. At this point, the device will recognize a removable disk (RPI-RP2).
- Copy the epd.uf2 file just generated to the newly recognized removable disk (RPI-RP2), Pico will automatically restart the running program.
Python
- First press and hold the BOOTSEL button on the Pico board, use the Micro USB cable to connect the Pico to the Raspberry Pi, then release the button. At this point, the device will recognize a removable disk (RPI-RP2).
- Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the removable disk (RPI-RP2) just identified.
- Update Thonny IDE.
sudo apt upgrade thonny
- Open Thonny IDE (click on the Raspberry logo -> Programming -> Thonny Python IDE ), and select the interpreter:
- Select Tools -> Options... -> Interpreter.
- Select MicroPython (Raspberry Pi Pico and ttyACM0 port).
- Select Tools -> Options... -> Interpreter.
- Open the Pico_ePaper-xxx.py file in Thonny IDE, then run the current script (click the green triangle).
C Code Analysis
Bottom Hardware Interface
We package the hardware layer for easily porting to the different hardware platforms.
DEV_Config.c(.h) in the directory: Pico_ePaper_Code\c\lib\Config.
- Data type:
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
- Module initialize and exit:
void DEV_Module_Init(void); void DEV_Module_Exit(void); Note: 1. The functions above are used to initialize the display or exit handle.
- GPIO Write/Read:
void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin);
- SPI transmits data:
void DEV_SPI_WriteByte(UBYTE Value);
EPD driver
The driver codes of EPD are saved in the directory: Pico_ePaper_Code\c\lib\e-Paper
Open the .h header file, you can check all the functions defined.
- Initialize e-Paper, this function is always used at the beginning and after waking up the display.
//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); // Mode = 0 fully update, Mode = 1 partial update //Other types void EPD_xxx_Init(void);
xxx should be changed by the type of e-Paper, For example, if you use 2.13inch e-Paper (D), to fully update, it should be EPD_2IN13D_Init(0) and EPD_2IN13D_Init(1) for the partial update;
- Clear: this function is used to clear the display to white.
void EPD_xxx_Clear(void);
xxx should be changed by the type of e-Paper, For example, if you use 2.9inch e-Paper (D), it should be EPD_2IN9D_Clear();
- Send the image data (one frame) to EPD and display
//Bicolor version void EPD_xxx_Display(UBYTE *Image); //Tricolor version void EPD_xxx_Display(const UBYTE *blackimage, const UBYTE *ryimage);
There are several types which are different from others
//Partial update for 2.13inch e-paper (D), 2.9inch e-paper (D) void EPD_2IN13D_DisplayPart(UBYTE *Image); void EPD_2IN9D_DisplayPart(UBYTE *Image);
//For 2.13inch e-paper V2, you need to first useEPD_xxx_DisplayPartBaseImage to display a static background and then partial update by the function EPD_xxx_DisplayPart() 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 only hardware reset or use initialize function to wake up e-Paper from sleep mode
xxx is the type of e-Paper, for example, if you use 2.13inch e-Paper D, it should be EPD_2IN13D_Sleep().
Application Programming Interface
We provide basic GUI functions for testing, like draw point, line, string, and so on. The GUI function can be found in the directory: RaspberryPi_JetsonNano\c\lib\GUI\GUI_Paint.c(.h).
The fonts used can be found in the directory: RaspberryPi_JetsonNano\c\lib\Fonts.
- Create a new image, you can set the image name, width, height, rotate angle, and color.
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: image: Name of the image buffer, this is a pointer; Width: Width of the image; Height: Height of the image; Rotate: Rotate the angle of the Image; Color: The initial color of the image;
- Select image buffer: You can create multiple image buffers at the same time and select the certain one and draw by this function.
void Paint_SelectImage(UBYTE *image) Parameters: image: The name of the image buffer, this is a pointer;
- Rotate image: You need to set the rotation angle of the image, this function should be used after Paint_SelectImage(). The angle can be 0, 90, 180, or 270.
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: Rotate the angle of the image, the parameter can be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270.
- 【Note】After rotating, the place of the first pixel is different, we take a 1.54-inch e-paper as an example.
- Image mirror: This function is used to set the image mirror.
void Paint_SetMirroring(UBYTE mirror) Parameters: mirror: Mirror type if the image, the parameter can be MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN.
- Set the position and color of pixels: This is the basic function of GUI, it is used to set the position and color of a pixel in the buffer.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: The X-axis value of the point in the image buffer Ypoint: The Y-axis value of the point in the image buffer Color: The color of the point
- Clear display: To set the color of the image, this function always be used to clear the display.
void Paint_Clear(UWORD Color) Parameters: Color: The color of the image
- Color of the windows: This function is used to set the color of windows, it is always used for updating partial areas like displaying a clock.
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xpoint: The X-axis value of the start point in the image buffer Ypoint: The Y-axis value of the start point in the image buffer Xend: The X-axis value of the end point in the image buffer Yend: The Y-axis value of the end point in the image buffer Color: The color of the windows
- Draw point: Draw a point at the position (X point, Y point) of the image buffer, you can configure the color, size, and style.
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: X-axis value of the point. Ypoint: Y-axis value of the point. Color: Color of the point Dot_Pixel: Size of the point, 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; Dot_Style: Style of the point, define the extended mode of the point. typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
- Draw the line: Draw a line from (Xstart, Ystart) to (Xend, Yend) in the image buffer, you can configure the color, width, and style.
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: Xstart of the line Ystart: Ystart of the line Xend: Xend of the line Yend: Yend of the line Color: Color of the line Line_width: 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, Solid or Dotted. 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 configure the color, width, and style.
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: Xstart of the rectangle. Ystart: Ystart of the rectangle. Xend: Xend of the rectangle. Yend: Yend of the rectangle. Color: Color of the rectangle Line_width: The width of the edges. 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 the rectangle, empty or filled. typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
- Draw circle: Draw a circle in the image buffer, use (X_Center Y_Center) as the center and Radius as the radius. You can configure the color, width of the line, and the style of the circle.
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: X-axis of center Y_Center: Y-axis of center Radius: Radius of circle Color: Color of the circle Line_width: The width of arc, 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 the circle: empty or filled. typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
- Show Ascii character: Show a character in (Xstart, Ystart) position, you can configure the font, foreground, and background.
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: Xstart of the character Ystart: Ystart of the character Ascii_Char: Ascii char Font: five fonts are avaialble: font8: 5*8 font12: 7*12 font16: 11*16 font20: 14*20 font24: 17*24 Color_Foreground: foreground color Color_Background: background color
- Draw the string: Draw the string at (Xstart Ystart), you can configure the fonts, foreground, and the background
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: Xstart of the string Ystart: Ystart of the string pString: String Font: five fonts are available: font8: 5*8 font12: 7*12 font16: 11*16 font20: 14*20 font24: 17*24 Color_Foreground: foreground color Color_Background: background color
- Draw Chinese string: Draw the Chinese string at (Xstart Ystart) of the image buffer. You can configure fonts (GB2312), foreground, and background.
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: Xstart of string Ystart: Ystart of string pString: string Font: GB2312 fonts, two fonts are available font12CN: ascii 11*21,Chinese 16*21 font24CN: ascii 24*41,Chinese 32*41 Color_Foreground: Foreground color Color_Background: Background color
- Draw number: Draw numbers at (Xstart Ystart) of the image buffer. You can select font, foreground, and background.
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: Xstart of numbers Ystart: Ystart of numbers Nummber: numbers displayed. It supports int type and 2147483647 is the maximum supported Font: Ascii fonts, five fonts are available: font8: 5*8 font12: 7*12 font16: 11*16 font20: 14*20 font24: 17*24 Color_Foreground: foreground Color_Background: background
- Display time: Display time at (Xstart Ystart) of the image buffer, you can configure fonts, foreground, and background.
- This function is used for partial updating. Note that some of the e-Paper don't support partial updates and you cannot use partial updates all the time, which will have ghosts problems and destroy the display.
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: Xstart of time Ystart: Ystart of time pTime: Structure of time Font: Ascii font, five fonts are available font8: 5*8 font12: 7*12 font16: 11*16 font20: 14*20 font24: 17*24 Color_Foreground: foreground Color_Background: background