Template: Pico LCD 0.96 Guide

From Waveshare Wiki
Jump to: navigation, search

Pico-LCD-0.96 Connection & Demo

Hardware connection

Please take care of the direction when you connect Pico, an USB port is printed to indicate. You can also check the pin of Pico and the LCD board when connecting.
You can connect the display according to the table.

e-Paper Pico Description
VCC VSYS Power Input
GND GND GND
DIN GP11 MOSI pin of SPI, data transmitted from Master t Slave
CLK GP10 SCK pin of SPI, clock pin
CS GP9 Chip selection of SPI, low active
DC GP8 Data/Command control pin (High:data; Low: command)
RST GP12 Reset pin, low active
BL GP13 Backlight control

Connection (Directly)

Pico-LCD-0.96-details-3.jpg

Connection (with adapter board)

Pico-LCD-0.96-wiki-2.jpg

Setup Environment

Please refer to Raspberry Pi's guide: https://www.raspberrypi.org/documentation/pico/getting-started/

Download Demo codes

Open the terminal and run the following command:

sudo apt-get install p7zip-full
cd ~
sudo wget  https://files.waveshare.com/upload/2/28/Pico_code.7z
7z x Pico_code.7z -o./Pico_code
cd ~/Pico_code
cd c/build/

Run the Demo codes

This guide is based on Raspberry Pi.

C examples

Open a terminal and enter the directory of C codes:

cd ~/Pico_LCD_code/c/

Create a build folder and add SDK:
For example, if the path of SDK is ../../pico-sdk
Then you should create a build and add the path like these:

cd build
export PICO_SDK_PATH=... /... /.../pico-sdk
(Note: Be sure to write the right path for your own SDK)

Run cmake.. command to generate a Makefile file.

cmake ..

Run make command to build.

make -j9

Open main. c under the c folder, you can change the demo you need. This demo can drive the display of our company's Pico series and the source code will be updated all the time. Please select the corresponding LCD or OLED test function and comment on the irrelevant functions.
Pico LCD 0.96 Guide001.png
Enter "make" and generate the file to be executed. Note that it will take a while to compile the first time.

make -j9

After the compilation is complete, the uf2 file will be generated. Press and hold the button on the Pico board, connect the Pico to the USB port of the Raspberry Pi through the Micro USB cable, and release the button. After connecting, the Raspberry Pi will automatically recognize a removable disk (RPI-RP2) and copy the main.uf2 file in the build folder to the recognized removable disk (RPI-RP2).

cp main.uf2 /media/pi/RPI-RP2/

Python examples

Windows

1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer through the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
2. Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the recognized removable disk (RPI-RP2).
3. Open Thonny IDE (note: use the latest version of Thonny, otherwise there is no Pico support package, the latest version under Windows is v3.3.3).
4. Click Tools -> Settings -> Interpreter, select Pico, and the corresponding port as shown in the figure.
Pico-lcd-0.96-img-config.png
This demo provides two programs:
Serial Port Parameter Configuration.py: This program is used to configure the mode through the serial port.
RX_TX.py: This is used to send and receive information and return what is received.
5. File->Open->RX_TX.py, click to run, as shown below:
Note: If you want to start automatically, please rename RX_TX.py to main.py and save it to Pico.
Pico-lcd-0.96-img-run.png

Raspberry Pi

1. The process of brushing the firmware is the same as on Windows, you can choose to copy the pico_micropython_20210121.uf2 file into pico on your PC or Raspberry Pi.
2. Open Thonny IDE on Raspberry Pi (click on Raspberry logo -> Programming -> Thonny Python IDE) and you can check the version information in Help -> About Thonny.
To make sure your version has the Pico support package, again you can click Tools -> Options... -> Interpreter to select MicroPython (Raspberry Pi Pico and ttyACM0 port).
As shown in the image:
Pico-lcd-0.96-img-config2.png
If your current version of Thonny does not have the Pico support package, enter the following command to update the Thonny IDE.

sudo apt upgrade thonny

3. Click File -> Open... -> python/Pico-LCD-0.96/Pico-LCD-0.96.py and run the script.

Codes Analysis

C

Bottom hardware interface

We package the hardware layer for easily porting to the different hardware platforms.
DEV_Config.c(.h) in the directory:...\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 transmit data
void DEV_SPI_WriteByte(UBYTE Value);

Application functions

We provide basic GUI functions for testing, like draw point, line, string, and so on. The GUI function can be found in directory:..\c\lib\GUI\GUI_Paint.c(.h).
LCD PICO GUI 1.png
The fonts used can be found in the directory: RaspberryPi\c\lib\Fonts
LCD rpi Font.png

  • Create a new image, you can set the image name, width, height, rotate angle, and color.
void Paint_NewImage(UWORD *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color, UWORD Depth)
Parameter:
 	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;
 	Depth: Depth of the color
  • Select image buffer: You can create multiple image buffers at the same time and select a certain one and draw by this function.
void Paint_SelectImage(UBYTE *image)
Parameter:
 	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)
Parameter:
 	Rotate: Rotate the angle of the image, the parameter can be ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270.
【Note】Afer rotating, the place of the first pixel is different as below:
Pico LCD Rotate.jpg
  • Image mirror: This function is used to set the image mirror.
void Paint_SetMirroring(UBYTE mirror)
Parameter:
 	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)
Parameter:
 	Xpoint: The X-axis position of the point in the image buffer
 	Ypoint: The Y-axis position of the point in the image buffer
 	Color: The color of the point
  • Color of the image: To set the color of the image, this function always be used to clear the display.
void Paint_Clear(UWORD Color)
Parameter:
 	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)
Parameter:
 	Xstart: X-axis position of the start point.
 	Ystart: Y-axis position of the start point.
 	Xend: X-axis position of the endpoint.
 	Yend: Y-axis position of the endpoint
 	Color: Color of the windows.
  • Draw point: Draw a point at the position (Xpoint, Ypoint) 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)
Parameter:
 	Xpoint: X-axis position of the point.
 	Ypoint: Y-axis position 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: The style of the point, it defines 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)
Parameter:
 	Xstart: Xstart of the line
 	Ystart: Ystart of the line
 	Xend: Xend of the line
 	Yend: Yend of the line
 	Color: The 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)
Parameter:
 	Xstart: Xstart of the rectangle.
 	Ystart: Ystart of the rectangle.
 	Xend: Xend of the rectangle.
 	Yend: Yend of the rectangle.
 	Color: The 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 style of a 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-axis of center
 	Y_Center: Y-axis of center
 	Radius: radius of circle
 	Color: The color of the circle
 	Line_width: The width of the 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)
Parameter:
 	Xstart: Xstart of the character
 	Ystart: Ystart of the character
 	Ascii_Char:Ascii char
 	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 string: Draw 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)
Parameter:
 	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 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)
Parameter:
 	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: In the image buffer, at (Xstart Ystart) as the left vertex, write a string of numbers, you can choose the Ascii font, font foreground color, or font background color.
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit,UWORD Color_Foreground, UWORD Color_Background);
Parameter:
 	Xstart: Left vertex X coordinate
 	Ystart: Left vertex Y coordinate
 	Nummber: The displayed number is stored in a 32-bit int type, which can be displayed up to 2147483647.
 	 	font8:5*8
 	 	font12:7*12
 	 	font16:11*16
 	 	font20:14*20
 	 	font24:17*24
        Digit: Display decimal places
 	Color_Foreground: Foreground color
 	Color_Background: Background color
  • Display time: Display time at (Xstart Ystart) of the image buffer, you can configure fonts, foreground, and background.
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground)
Parameter:
 	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