Waveshare General 2 Inch LCD Display Module Instruction Manual

June 1, 2024
WAVESHARE

Waveshare-LOGO

Waveshare General 2 Inch LCD Display Module

Waveshare-General-2-Inch-LCD-Display-Module-PRODUCT

Product Information

Specifications

  • Operating voltage: 3.3V/5V (Please ensure voltage consistency for proper functionality)
  • Interface: SPI
  • LCD type : IPS
  • Driver: ST7789V
  • Resolution: 240(V) x 320 (H) RGB
  • Display size: 30.60H x 40.80V mm
  • Pixel size: 0.0975H x 0.0975V mm
  • Dimension: 58 x 35 mm

Frequently Asked Questions

  • Q: What are the supported platforms for this LCD module?
    • A: This LCD module provides examples for Raspberry Pi, STM32, and Arduino.

Introduction

This product provides Raspberry Pi, STM32, Arduino examples

Feature

  • As a 2inch IPS display module with a resolution of 240 * 320, it uses an SPI interface for communication. The LCD has an internal controller with basic functions, which can be used to draw points, lines, circles, and rectangles, and display English, Chinese as well as pictures.
  • We provide complete supporting Raspberry Pi demos (BCM2835 library, WiringPi library, and python demos), STM32 demos, and Arduino demos.

Specifications

  • Operating voltage: 3.3V/5V (Please ensure that the power supply voltage and logic voltage are consistent, otherwise it will not work properly)
  • Interface: SPI
  • LCD type: IPS
  • Driver: ST7789V
  • Resolution: 240(V) x 320 (H) RGB
  • Display size: 30.60(H)x 40.80(V)mm
  • Pixel size: 0.0975(H)x 0.0975(V)mm
  • Dimension: 58 x 35 (mm)

Interface Description

Raspberry Pi hardware connection

Please connect the LCD to your Raspberry Pi by the 8PIN cable according to the table below
Use the pin header or PH2.0 8PIN interface, you need to connect according to the following table

Connect to Raspberry Pi

Waveshare-General-2-Inch-LCD-Display-Module-FIG-2

The 2inch LCD uses the PH2.0 8PIN interface, which can be connected to the Raspberry Pi according to the above table: (Please connect according to the pin definition table. The color of the wiring in the picture is for reference only, and the actual color shall prevail.)

Waveshare-General-2-Inch-LCD-Display-Module-FIG-3

STM32 hardware connection

The example we provide is based on STM32F103RBT6, and the connection method provided is also the corresponding pin of STM32F103RBT6. If you need to transplant the program, please connect according to the actual pin.

STM32F103ZET connection pin correspondence

Waveshare-General-2-Inch-LCD-Display-Module-FIG-4

Take the XNUCLEO-F103RB development board developed by our company as an example, the connection is as follows:

Waveshare-General-2-Inch-LCD-Display-Module-FIG-5

Arduino Hardware Connection

Arduino UNO Connection pin correspondence

Waveshare-General-2-Inch-LCD-Display-Module-FIG-6

The connection diagram is as follows (click to enlarge):

Waveshare-General-2-Inch-LCD-Display-Module-FIG-7

Hardware Description

LCD & Controller

The LCD supports 12-bit, 16-bit, and 18-bit input color formats per pixel, namely RGB444, RGB565, and RGB666 three color formats, this demo uses RGB565 color format, which is also a commonly used RGB format.

For most LCD controllers, the communication mode of the controller can be configured, usually with an 8080 parallel interface, three-wire SPI, four-wire SPI, and other communication methods. This LCD uses a four-wire SPI communication interface, which can greatly save the GPIO port, and the communication speed will be faster.

Communication Protocol

Waveshare-General-2-Inch-LCD-Display-Module-FIG-8

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

  • RESX: the reset pin, it should be low when powering the module and be higher at other times;
  • CSX: slave chip select, when CS is low, the chip is enabled.
  • D/CX: data/command control pin, when DC = 0, write command, when DC = 1, write data
  • SDA: the data pin for transmitting RGB data, it works as the MOSI pin of SPI interface;
  • SCL works as the SCLK pins of the SPI interface.
  • SPI communication has data transfer timing, which is combined by CPHA and CPOL.
  • CPOL determines the level of the serial synchronous clock at idle state. When CPOL = 0, the level is Low. However, CPOL has little effect to the transmission.
  • CPHA determines whether data is collected at the first clock edge or at the second clock edge of serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.
  • There are 4 SPI communication modes. SPI0 is commonly used, in which CPHL = 0, CPOL = 0.

Working with Raspberry Pi

Enable SPI interface

PS: If you are using the system of the Bullseye branch, you need to change “apt-get” to “apt”, the system of the Bullseye branch only supports Python3.

  • Open the terminal, and use the command to enter the configuration page.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-9

Reboot Raspberry Pi

  • sudo reboot

Please make sure the SPI is not occupied by other devices, you can check in the middle of/boot/config.txt.

Install Libraries

Install BCM2835 libraries

Waveshare-General-2-Inch-LCD-Display-Module-FIG-10

Install wiringPi libraries

Waveshare-General-2-Inch-LCD-Display-Module-FIG-11

Install Python libraries

Waveshare-General-2-Inch-LCD-Display-Module-FIG-12

Download Examples

Open Raspberry Pi terminal and run the following command

Waveshare-General-2-Inch-LCD-Display-Module-FIG-13

Run the demo codes

  • Please go into the RaspberryPi directory (demo codes) first and run the commands in terminal

C codes

  • Re-compile the demo codes

Waveshare-General-2-Inch-LCD-Display-Module-FIG-14

  • The test program of all screens can be called directly by entering the corresponding size
    • sudo ./main Screen Size

Depending on the LCD, one of the following commands should be entered:

Waveshare-General-2-Inch-LCD-Display-Module-FIG-15

python

  • Enter the python program directory and run the command ls -l

Waveshare-General-2-Inch-LCD-Display-Module-FIG-16

Test programs for all screens can be viewed, sorted by size:

  • 0inch96_LCD_test.py: 0.96inch LCD test program
  • 1inch14_LCD_test.py: 1.14inch LCD test program
  • 1inch28_LCD_test.py: 1.28inch LCD test program
  • 1inch3_LCD_test.py: 1.3inch LCD test program
  • 1inch47_LCD_test.py: 1.47inch LCD test program
  • 1inch54_LCD_test.py: 1.54inchLCD test program
  • 1inch8_LCD_test.py: 1.8inch LCD test program
  • 2inch_LCD_test.py: 2inch LCD test program
  • 2inch4_LCD_test.py: 2inch4 LCD test program

Just run the program corresponding to the screen, the program supports python2/3

Waveshare-General-2-Inch-LCD-Display-Module-FIG-17

FBCP Porting

PS: FBCP is currently not compatible with 64-bit Raspberry Pi system, it is recommended to use 32-bit system.

  • Framebuffer uses a video output device to drive a video display device from a memory buffer containing complete frame data. Simply put, a memory area is used to store the display content, and the display content can be changed by changing the data in the memory.
  • There is an open source project on github: fbcp-ili9341. Compared with other fbcp projects, this project uses partial refresh and DMA to achieve a speed of up to 60fps

Download Drivers

Waveshare-General-2-Inch-LCD-Display-Module-FIG-18

Method 1: Use a script (recommended)

  • Here we have written several scripts that allow users to quickly use fbcp and run corresponding commands according to their own screen
  • If you use a script and do not need to modify it, you can ignore the second method below.

Note: The script will replace the corresponding /boot/config.txt and /etc/rc.local and restart, if the user needs, please back up the relevant files in advance.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-19

Method 2: Manual Configuration

Environment Configuration

Raspberry Pi’s vc4-kms-v3d will cause fbcp to fail, so we need to close vc4 -kms-v3d before installing it in fbcp.

  • sudo nano /boot/config.txt

Just block the statement corresponding to the picture below.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-20

A reboot is then required.

  • sudo reboot

Compile and run

Waveshare-General-2-Inch-LCD-Display-Module-FIG-21

Replace it by yourself according to the LCD Module you use, above cmake [options] ..

Waveshare-General-2-Inch-LCD-Display-Module-FIG-22

Set up to start automatically

  • sudo cp ~/Waveshare_fbcp/buil
  • d/fbcp /usr/local/bin/fbcp
  • sudo nano /etc/rc.local

Waveshare-General-2-Inch-LCD-Display-Module-FIG-23

  • Add fbcp& before exit 0. Note that you must add “&” to run in the background, otherwise the system may not be able to start.

Set the Display Resolution

Set the user interface display size in the /boot/config.txt file.

  • sudo nano /boot/config.txt

Then add the following lines at the end of the config.txt.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-24

Replace the above hdmi_cvt=[options] according to the LCD Module you are using

Waveshare-General-2-Inch-LCD-Display-Module-FIG-25

And then reboot the system

  • sudo reboot

After rebooting the system, the Raspberry Pi OS user interface will be displayed

Waveshare-General-2-Inch-LCD-Display-Module-FIG-26

API Description

  • The RaspberryPi series can share a set of programs, because they are all embedded systems, and the compatibility is relatively strong.
  • The program is divided into bottom-layer hardware interface, middle-layer LCD screen driver, and upper-layer application;

Hardware Interface

  • We have carried out the low-level encapsulation, if you need to know the internal implementation can go to the corresponding directory to check, for the reason the hardware platform and the internal implementation are different.
  • You can open DEV_Config.c(.h) to see definitions,which in the directory RaspberryPi\c\lib\Config.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-27

Data type:

Waveshare-General-2-Inch-LCD-Display-Module-FIG-28

Module initialization and exit processing

Waveshare-General-2-Inch-LCD-Display-Module-FIG-29

GPIO read and write:

  • void DEV_Digital_Write(UWORD Pin, UBYTE Value);
  • UBYTE DEV_Digital_Read(UWORD Pin);

SPI write data:

  • void DEV_SPI_WriteByte(UBYTE Value);

Upper application

If you need to draw pictures or display Chinese and English characters, we provide some basic functions here about some graphics processing in the directory RaspberryPi\c\lib\GUI\GUI_Paint.c(.h).

Waveshare-General-2-Inch-LCD-Display-Module-FIG-30

The fonts can be found in RaspberryPi\c\lib\Fonts directory

Waveshare-General-2-Inch-LCD-Display-Module-FIG-31

  • New Image Properties: Create a new image buffer, this property includes the image buffer name, width, height, flip Angle, and color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-32
  • Select image buffer: The purpose of the selection is that you can create multiple image attributes, there can be multiple images buffer, you can select each image you create.Waveshare-General-2-Inch-LCD-Display-Module-FIG-33
  • Image Rotation: Set the rotation Angle of the selected image, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.Waveshare-General-2-Inch-LCD-Display-Module-FIG-34
  • Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror, or image center mirror.Waveshare-General-2-Inch-LCD-Display-Module-FIG-35
  • Set points of the display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.Waveshare-General-2-Inch-LCD-Display-Module-FIG-36
  • Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.Waveshare-General-2-Inch-LCD-Display-Module-FIG-37
  • The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.Waveshare-General-2-Inch-LCD-Display-Module-FIG-38
  • Draw point: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.Waveshare-General-2-Inch-LCD-Display-Module-FIG-39
  • Draw line: In the image buffer, draw line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width and the style of the line.Waveshare-General-2-Inch-LCD-Display-Module-FIG-40
  • Draw rectangle: In the image buffer, 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.Waveshare-General-2-Inch-LCD-Display-Module-FIG-41
  • Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.Waveshare-General-2-Inch-LCD-Display-Module-FIG-42
  • Write Ascii character: In the image buffer, use (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-43
  • Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, you can choose Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-44
  • Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose character font, font foreground color, and font background color of the GB2312 encoding.Waveshare-General-2-Inch-LCD-Display-Module-FIG-45
  • Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-46
  • Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.
  • Read the local bmp image and write it to the cache.

For Linux operating systems such as Raspberry Pi, you can read and write pictures. For Raspberry Pi, in the directory: RaspberryPi\c\lib\GUI\GUI_BMPfile.c(.h).

Waveshare-General-2-Inch-LCD-Display-Module-FIG-47

Testing Code for Users

For Raspberry Pi, in the directory: RaspberryPi\c\examples, for all the test code;

Waveshare-General-2-Inch-LCD-Display-Module-FIG-48

If you need to run the 0.96-inch LCD test program, you need to add 0.96 as a parameter when running the main demo.

Re-execute in Linux command mode as follows:

  • make clean
  • make
  • sudo ./main 0.96

Python (for Raspberry Pi)

  • Works with python and python3.
  • For python, his calls are not as complicated as C.
  • Raspberry Pi: RaspberryPi\python\lib\

Waveshare-General-2-Inch-LCD-Display-Module-FIG-49

lcdconfig.py

  • Module initialization and exit processingWaveshare-General-2-Inch-LCD-Display-Module-FIG-50

GPIO read and write:

  • def digital_write(pin, value)
  • def digital_read(pin)

SPI write data.

  • def spi_writebyte(data)

xxx_LCD_test.py (xxx indicates the size, if it is a 0.96inch LCD, it is 0inch96_LCD_test.py, and so on)

python is in the following directory:

Raspberry Pi: RaspberryPi\python\examples\

Waveshare-General-2-Inch-LCD-Display-Module-FIG-51

If your python version is python2 and you need to run the 0.96inch LCD test program, reexecute it as follows in linux command mode:

  • sudo python 0inch96_LCD_test.py

If your python version is python3 and you need to run the 0.96inch LCD test program, reexecute the following in linux command mode:

  • sudo python3 0inch96_LCD_test.py

About Rotation Settings

If you need to set the screen rotation in the python program, you can set it by the statement im_r= image1.rotate(270).

  • im_r= image1.rotate(270)

Rotation effect, take 1.54 as an example, the order is 0°, 90°, 180°, 270°

Waveshare-General-2-Inch-LCD-Display-Module-FIG-52

GUI Functions

Python has an image library PIL official library link , it does not need to write code from the logical layer like C and can directly call to the image library for image processing. The following will take a 1.54-inch LCD as an example, we provide a brief description of the demo.

It needs to use the image library and install the library

  • sudo apt-get install python3-pil

And then import the library

  • from PIL import Image,ImageDraw,ImageFont.

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

Define an image cache to facilitate drawing, writing, and other functions on the picture

  • image1 = Image.new(“RGB”, (disp.width, disp.height), “WHITE”)

The first parameter defines the color depth of the image, which is defined as “1” to indicate the bitmap of one-bit depth. 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, which is defined as “WHITE”.

Create a drawing object based on Image1 on which all drawing operations will be performed on here.

  • draw = ImageDraw.Draw(image1)

Draw a line.

  • draw.line([(20, 10),(70, 60)], fill = “RED”,width = 1)

The first parameter is a four-element tuple starting at (0, 0) and ending at (127,0). Draw a line. Fill =”0″ means the color of the line is white.

Draw a rectangle

  • draw.rectangle([(20,10),(70,60)],fill = “WHITE”,outline=”BLACK”)

The first argument is a tuple of four elements. (20,10) is the coordinate value in the upper left corner of the rectangle, and (70,60) is the coordinate value in the lower right corner of the rectangle. Fill =” WHITE” means BLACK inside, and outline=”BLACK” means the color of the outline is black.

Draw a circle

  • draw.arc((150,15,190,55),0, 360, fill =(0,255,0)

Draw an inscribed circle in the square, the first parameter is a tuple of 4 elements, with (150, 15) as the upper left corner vertex of the square, (190, 55) as the lower right corner vertex of the square, specifying the level median line of the rectangular frame is the angle of 0 degrees, the second parameter indicates the starting angle, the third parameter indicates the ending angle, and fill = 0 indicates that the color of the line is white. If the figure is not square according to the coordination, you will get an ellipse. Besides the arc function, you can also use the chord function for drawing a solid circle.

  • draw.ellipse((150,65,190,105), fill = 0)

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

Character.

The ImageFont module needs to be imported and instantiated:

  • Font1 = ImageFont.truetype(“../Font/Font01.ttf”,25)
  • Font2 = ImageFont.truetype(“../Font/Font01.ttf”,35)
  • Font3 = ImageFont.truetype(“../Font/Font02.ttf”,32)

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

Note: Each character library contains different characters; If some characters cannot be displayed, it is recommended that you can refer to the encoding set ro used. To draw English characters, you can directly use the fonts; for Chinese characters, you need to add a symbol u:

  • draw.text((40, 50), ‘WaveShare’, fill = (128,255,128),font=Font2)
  • text= u”微雪电子”
  • draw.text((74, 150),text, fill = “WHITE”,font=Font3)

The first parameter is a tuple of 2 elements, with (40, 50) as the left vertex, the font is Font2, and the fill is the font color. You can directly make fill = “WHITE”, because the regular color value is already defined Well, of course, you can also use fill = (128,255,128), the parentheses correspond to the values of the three RGB colors so that you can precisely control the color you want. The second sentence shows Micro Snow Electronics, using Font3, the font color is white.

read local image

  • image = Image.open(‘../pic/LCD_1inch28.jpg’)

The parameter is the image path.

Other functions

Using with STM32

Software description

  • The demo is developed based on the HAL library. Download the demo, find the STM32 program file directory, and open the LCD_demo.uvprojx in the STM32\STM32F103RBT6\MDK-ARM directory to check the program.Waveshare-General-2-Inch-LCD-Display-Module-FIG-53

  • Open main.c, you can see all the test programs, remove the comments in front of the test programs on the corresponding screen, and recompile and download.Waveshare-General-2-Inch-LCD-Display-Module-FIG-54

  • LCD_0in96_test() 0.96inch LCD test program

  • LCD_1in14_test() 1.14inch LCD test program

  • LCD_1in28_test() 1.28inch LCD test program

  • LCD_1in3_test() 1.3 inch LCD test program

  • LCD_1in54_test() 1.54inch LCD test program

  • LCD_1in8_test() 1.8inch LCD test program

  • LCD_2in_test() 2inch LCD test program

Program description

Underlying hardware interface

Data type

  • define / UBYTE / uint8_t

  • define / UWORD / uint16_t

  • define / UDOUBLE / uint32_t

Module initialization and exit processing

Waveshare-General-2-Inch-LCD-Display-Module-FIG-55

Write and read GPIO

  • void / DEV_Digital_Write(UWORD Pin, UBYTE Value);
  • UBYTE / DEV_Digital_Read(UWORD Pin);

SPI write data

  • UBYTE / SPI4W_Write_Byte(uint8_t value);

The upper application

For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory STM32\STM32F103RB\User\GUI_DEV\GUI_Paint.c(.h)

Note: Because of the size of the internal RAM of STM32 and arduino, the GUI is directly written to the RAM of the LCD.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-56

The character font which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts

Waveshare-General-2-Inch-LCD-Display-Module-FIG-57

  • New Image Properties: Create a new image property, this property includes the image buffer name, width, height, flip Angle, color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-58

Set the clear screen function, usually call the clear function of LCD directly

Waveshare-General-2-Inch-LCD-Display-Module-FIG-59

Set the drawing pixel function

Waveshare-General-2-Inch-LCD-Display-Module-FIG-60

Select image buffer: the purpose of the selection is that you can create multiple image attributes, image buffer can exist multiple, you can select each image you create

Waveshare-General-2-Inch-LCD-Display-Module-FIG-61

Image Rotation: Set the selected image rotation Angle, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-62

Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror,horizontal mirror, vertical mirror, or image center mirror.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-63

Set points of display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-64

Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-65

Image buffer part of the window filling color: the image buffer part of the window filled with a certain color, generally as a window whitewashing function, often used for time display, whitewashing on a second

Waveshare-General-2-Inch-LCD-Display-Module-FIG-66

Draw points: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-67

Line drawing: In the image buffer, line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, line width, line style.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-68

Draw rectangle: In the image buffer, 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.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-69

Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-70

Write Ascii character: In the image buffer, at (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-71

Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, can choose Ascii visual character library, font foreground color, font background color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-72

Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose GB2312 encoding character font, font foreground color, font background color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-73

Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font background color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-74

Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-75

Arduino Software Description

Note: The demos are all tested on Arduino uno. If you need other types of Arduino, you need to determine whether the connected pins are correct.

Arduino IDE Installation Steps

Run program

In the product encyclopedia interface download the program , and then unzip it. The Arduino program is located at ~/Arduino/…

Waveshare-General-2-Inch-LCD-Display-Module-FIG-76

Please select the corresponding program according to the LCD screen model to open

Waveshare-General-2-Inch-LCD-Display-Module-FIG-77

You can view test programs for all screen sizes, sorted by size:

  • For example, 1.54inch LCD Module. Open the LCD_1inch54 folder and run the LCD_1inch54.ino file.
  • Open the program, select the development board model Arduino UNO

Waveshare-General-2-Inch-LCD-Display-Module-FIG-78

Select the corresponding COM port

Waveshare-General-2-Inch-LCD-Display-Module-FIG-79

Then click to compile and download

Waveshare-General-2-Inch-LCD-Display-Module-FIG-80

Program Description

Document Introduction

Take Arduino UNO controlling a 1.54-inch LCD as an example, open the Arduino\LCD_1inch54 directory:

Waveshare-General-2-Inch-LCD-Display-Module-FIG-81

Of which:

  • LCD_1inch54.ino: open with Arduino IDE;
  • LCD_Driver.cpp(.h): is the driver of the LCD screen;
  • DEV_Config.cpp(.h): It is the hardware interface definition, which encapsulates the read and write pin levels, SPI transmission data, and pin initialization;
  • font8.cpp, font12.cpp, font16.cpp, font20.cpp, font24.cpp, font24CN.cpp, fonts.h: fonts for characters of different sizes;
  • image.cpp(.h): is the image data, which can convert any BMP image into a 16-bit true color image array through Img2Lcd (downloadable in the development data).
  • The program is divided into bottom-layer hardware interface, middle-layer LCD screen driver, and upper-layer application;

Underlying Hardware Interface

The hardware interface is defined in the two files DEV_Config.cpp(.h), and functions such as read and write pin level, delay, and SPI transmission are encapsulated.

write pin level

  • void DEV_Digital_Write(int pin, int value)

The first parameter is the pin, and the second is the high and low level.

Read pin level

  • int DEV_Digital_Read(int pin)

The parameter is the pin, and the return value is the level of the read pin.

Delay

DEV_Delay_ms(unsigned int delaytime)

  • millisecond level delay.

SPI output data

  • DEV_SPI_WRITE(unsigned char data)

The parameter is char type, occupying 8 bits.

The Upper Application

For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory GUI_Paint.c(.h)

Note: Because of the size of the internal RAM of STM32 and Arduino, the GUI is directly written to the RAM of the LCD.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-82

*The fonts used by the GUI all depend on the font.cpp(h) files under the same file**

Waveshare-General-2-Inch-LCD-Display-Module-FIG-83

  • New Image Properties: Create a new image property, this property includes the image buffer name, width, height, flip Angle, and color.

Waveshare-General-2-Inch-LCD-Display-Module-FIG-84

  • Set the clear screen function, usually call the clear function of LCD directly.Waveshare-General-2-Inch-LCD-Display-Module-FIG-85
  • Set the drawing pixel function.Waveshare-General-2-Inch-LCD-Display-Module-FIG-86
  • Select image buffer: the purpose of the selection is that you can create multiple image attributes, image buffers can exist multiple, and you can select each image you create.Waveshare-General-2-Inch-LCD-Display-Module-FIG-87
  • Image Rotation: Set the selected image rotation Angle, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.Waveshare-General-2-Inch-LCD-Display-Module-FIG-88
  • Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror, or image center mirror.Waveshare-General-2-Inch-LCD-Display-Module-FIG-89
  • Set points of display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.Waveshare-General-2-Inch-LCD-Display-Module-FIG-90
  • Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.Waveshare-General-2-Inch-LCD-Display-Module-FIG-91
  • Draw points: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.Waveshare-General-2-Inch-LCD-Display-Module-FIG-92
  • Line drawing: In the image buffer, line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, line width, line style.Waveshare-General-2-Inch-LCD-Display-Module-FIG-93
  • Draw rectangle: In the image buffer, 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.Waveshare-General-2-Inch-LCD-Display-Module-FIG-94
  • Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.Waveshare-General-2-Inch-LCD-Display-Module-FIG-95
  • Write Ascii character: In the image buffer, at (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-96
  • Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, can choose Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-97
  • Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose GB2312 encoding character font, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-98
  • Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-99
  • Write numbers with decimals: at (Xstart Ystart) as the left vertex, write a string of numbers with decimals, you can choose Ascii code visual character font, font foreground color, font background colorWaveshare-General-2-Inch-LCD-Display-Module-FIG-100
  • Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.Waveshare-General-2-Inch-LCD-Display-Module-FIG-101
  • Display image: at (Xstart Ystart) as the left vertex, display an image whose width is W_Image and height is H_Image;

Waveshare-General-2-Inch-LCD-Display-Module-FIG-102

VisionFive2

Adaptive Model

Hardware Connection

Waveshare-General-2-Inch-LCD-Display-Module-FIG-103

VisionFive2 Pin Connection

Waveshare-General-2-Inch-LCD-Display-Module-FIG-104

Install Corresponding Libraries

Waveshare-General-2-Inch-LCD-Display-Module-FIG-105

Demo Download

Waveshare-General-2-Inch-LCD-Display-Module-FIG-106

Run the Corresponding Demo According to the Screen You Purchased

Waveshare-General-2-Inch-LCD-Display-Module-FIG-107

Resources

Document

Software

Demo codes

3D Drawing

FAQ

‘Question:’ 1. The LCD keeps black when using it with Raspberry Pi?

Answer:

  • Please check that if you have enabled SPI interface
  • Check BL pin, if BL pin has no output value, you can try to disconnect BL pin and test it again.

‘Question:’ 2. The python codes has error? Answer:

  • Please install image libraries and test it again. Run command: sudo apt-get install pythonimaging to install it and test again.

‘Question:’ 3.Why doesn’t the screen display properly when connected to an Arduino?

Answer:

  • When using an Arduino, please make sure it is plugged into a 5v power supply.

‘Question:’ 4.Incorrect use of Raspberry Pi controls may cause?

Answer:

If running the wiringPi demo is normal, then running python or BCM2835 may cause the screen to fail to refresh normally, because the bcm2835 library is a library function of the Raspberry Pi cpu chip, and the bottom layer is to directly operate the registers, while the bottom layer of the wiringPi library and python are read and written by reading and writing. The device file of the linux system operates the device, which may cause the GPIO port to be abnormal. Restarting the Raspberry Pi can solve it perfectly.

‘Question:’ 5.How to flip the image?

Answer:

  • C language control can use the function Paint_SetRotate(Rotate); But the flip angle in C language can only be 0, 90, 180, 270 degrees; Python can call rotate(Rotate) to flip any angle.

‘Question:’ 6.What is the maximum power consumption of the 2inch LCD Module?

Answer:

  • 3.3V 46mA

Support

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

References

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

WAVESHARE User Manuals

Related Manuals