Advertisement

Quick Links

Using VisionFive SPI to
Support LCD Display
with Python
Application Note
Version: 1.1
Date: 2022/07/29
Doc ID: VisionFive-ANEN-013-1.1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the VisionFive SPI and is the answer not in the manual?

Questions and answers

Summary of Contents for StarFive VisionFive SPI

  • Page 1 Using VisionFive SPI to Support LCD Display with Python Application Note Version: 1.1 Date: 2022/07/29 Doc ID: VisionFive-ANEN-013-1.1...
  • Page 2 StarFive does not assume any liability rising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation indirect, incidental, special, exemplary, or consequential damages.
  • Page 3 Preface About this guide and technical support information. About this document This application note provides steps to use VisionFive's SPI to make a 2.4inch LCD display with specified pictures. Revision History Table 0-1 Revision History Version Released Revision V1.1 2022/07/29 Added "cd"...
  • Page 4: Table Of Contents

    Contents List of Tables...........................5 List of Figures......................... 6 Legal Statements........................ii Preface............................iii 1. Introduction........................7 1.1. 40-Pin Header Definition..................7 2. Preparation........................8 2.1. Preparing Hardware....................8 2.1.1. Hardware Setup..................... 8 2.2. Preparing Software....................10 3. Running Demo Code......................12 4. Demo Source Code......................15 www.starfivetech.com ©...
  • Page 5: List Of Tables

    目录 List of Tables Table 0-1 Revision History..................... iii Table 2-1 Hardware Preparation.................... 8 Table 2-2 Connect the 2.4inch LCD to the 40-Pin Header............ 9 www.starfivetech.com © 2018-2022 上海赛昉科技有限公司 版权所有...
  • Page 6: List Of Figures

    目录 List of Figures Figure 1-1 40-Pin Definition....................7 Figure 2-1 Connect the 2.4inch LCD to the 40-Pin Header..........10 Figure 3-1 Example Output....................13 Figure 3-2 Example Output....................13 www.starfivetech.com © 2018-2022 上海赛昉科技有限公司 版权所有...
  • Page 7: Introduction

    1. Introduction This application note provides steps to use VisionFive's SPI to make a 2.4inch LCD display with specified pictures. 1.1. 40-Pin Header Definition The following figure shows the location of the 40-pin header. The VisionFive board is taken as an example: Figure 1-1 40-Pin Definition www.starfivetech.com ©...
  • Page 8: Preparation

    2.1. Preparing Hardware Prepare the following hardware items before running the demo code: Table 2-1 Hardware Preparation Type Item Notes Gener­ StarFive single board computer The following boards are applica­ ble: • StarLight • VisionFive Gener­ • 16 GB (or more) micro-SD...
  • Page 9 | 2 - Preparation Table 2-2 Connect the 2.4inch LCD to the 40-Pin Header 40-Pin GPIO Header 2.4inch LCD Module Pin Number Pin Name 3.3V Power GPIO18 (SPI MOSI) GPIO12 (SPI SCLK) GPIO15 (SPI CE0) GPIO0 GPIO44 GPIO19 www.starfivetech.com © 2018-2022 上海赛昉科技有限公司 版权所有...
  • Page 10: Preparing Software

    | 2 - Preparation Figure 2-1 Connect the 2.4inch LCD to the 40-Pin Header  2.4inch LCD Module 5V Power 3.3V Power 5V Power GPIO48 (I2C SDA) GPIO47 (I2C SCL) GPIO14 (UART TX) GPIO46 GPIO13 (UART RX) GPIO45 GPIO44 GPIO22 GPIO21 GPIO20 GPIO19 3.3V Power GPIO18 (SPI MOSI) GPIO17 GPIO16 (SPI MISO) GPIO15 (SPI CE0) GPIO12 (SPI SCLK) GPIO11 (SPI CE1) GPIO10 GPIO9 GPIO8 GPIO7 (PWM0) GPIO6 GPIO5 (PWM1) GPIO4...
  • Page 11 | 2 - Preparation 1. Flash Fedora OS into a Micro-SD card as described in the Flashing Fedora OS to a Micro-SD Card section in the VisionFive Single Board Computer Quick Start Guide. 2. Log into the Fedora and make sure VisionFive is connected to the Internet. For detailed instructions, refer to the Using SSH over Ethernet or Using a USB to Serial Converter section in the VisionFive Single Board Computer Quick Start Guide.
  • Page 12: Running Demo Code

    3. Running Demo Code To run the demo code, perform the following on VisionFive Fedora: 1. Locate to the directory where the test code, 2.4inch_LCD_demo, exists: a. Execute the following command to get the directory where VisionFive.gpio exists: pip show VisionFive.gpio Example Result: Location: /usr/local/lib64/python3.9/site-packages Note:...
  • Page 13: Figure 3-1 Example Output

    | 3 - Running Demo Code • On the 2.4inch LCD: ◦ First, the following picture with the StarFive logo will be displayed for two seconds. Figure 3-1 Example Output ◦ Then the following two official example figures will be displayed in turn.
  • Page 14 | 3 - Running Demo Code -----------lcd demo----------- Set SPI mode successfully spi mode: 0x0 bits per word: 8 max speed: 40000000 Hz(40000 kHz) 2022-07-04 16:40:40 2022-07-04 16:40:41 2022-07-04 16:40:41 2022-07-04 16:40:42 2022-07-04 16:40:42 2022-07-04 16:40:43 2022-07-04 16:40:44 2022-07-04 16:40:44 2022-07-04 16:40:45 The output indicates: ◦...
  • Page 15: Demo Source Code

    4. Demo Source Code The Python source code of this demo is provided for reference purpose only. 2.4inch_LCD_demo.py: Please make sure the 2.4inch LCD module is connected to the correct pins. The following table describes how to connect the 2.4inch LCD Module to the 40-pin header. ------------------------------------------------- __2.4inch LCD Module___Pin Number_____Pin Name VCC 17 3.3 V Power...
  • Page 16 | 4 - Demo Source Code disp.lcd_clear(WHITE) image = Image.open('./visionfive.bmp') disp.lcd_ShowImage(image, 0, 0) time.sleep(2) #Add the part of displaying pictures circularly. while True: print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))) #Rotate the picture by 90 degrees (anticlockwise). #To keep consistent with the display direction of other pictures. image = Image.open('./LCD_2inch4_parrot.bmp') image = image.transpose(Image.Transpose.ROTATE_90) disp.lcd_ShowImage(image, 0, 0)
  • Page 17 | 4 - Demo Source Code #Add a short delay for each change of electrical level. lcd_reset(self): gpio.output(self.rstpin, gpio.HIGH) time.sleep(0.01) gpio.output(self.rstpin, gpio.LOW) time.sleep(0.01) gpio.output(self.rstpin, gpio.HIGH) time.sleep(0.01) lcd_spisend(self, data): spi.transfer(data) lcd_sendcmd(self, cmd): gpio.output(self.dcpin, gpio.LOW) spi.transfer(cmd) lcd_senddata(self,data): gpio.output(self.dcpin, gpio.HIGH) spi.transfer(data) #Write multiple bytes. lcd_sendnbytes(self, data): gpio.output(self.dcpin, gpio.HIGH) spi.write(data)
  • Page 18 | 4 - Demo Source Code self.lcd_senddata(0x39) self.lcd_senddata(0x2C) self.lcd_senddata(0x00) self.lcd_senddata(0x34) self.lcd_senddata(0x02) self.lcd_sendcmd(0xF7) #Pump ratio control. self.lcd_senddata(0x20) self.lcd_sendcmd(0xEA) #Driver Timing Control B. self.lcd_senddata(0x00) self.lcd_senddata(0x00) self.lcd_sendcmd(0xC0) #Power Control 1. self.lcd_senddata(0x1D) #VRH[5:0] self.lcd_sendcmd(0xC1) #Power Control 2. self.lcd_senddata(0x12) #SAP[2:0], BT[3:0]. self.lcd_sendcmd(0xC5) #VCOM Control 1. self.lcd_senddata(0x33) self.lcd_senddata(0x3F) self.lcd_sendcmd(0xC7)
  • Page 19 | 4 - Demo Source Code self.lcd_senddata(0x0F) self.lcd_senddata(0x22) self.lcd_senddata(0x1C) self.lcd_senddata(0x1B) self.lcd_senddata(0x08) self.lcd_senddata(0x0F) self.lcd_senddata(0x48) self.lcd_senddata(0xB8) self.lcd_senddata(0x34) self.lcd_senddata(0x05) self.lcd_senddata(0x0C) self.lcd_senddata(0x09) self.lcd_senddata(0x0F) self.lcd_senddata(0x07) self.lcd_senddata(0x00) self.lcd_sendcmd(0XE1); #Set Gamma. self.lcd_senddata(0x00) self.lcd_senddata(0x23) self.lcd_senddata(0x24) self.lcd_senddata(0x07) self.lcd_senddata(0x10) self.lcd_senddata(0x07) self.lcd_senddata(0x38) self.lcd_senddata(0x47) self.lcd_senddata(0x4B) self.lcd_senddata(0x0A) self.lcd_senddata(0x13) self.lcd_senddata(0x06) self.lcd_senddata(0x30) self.lcd_senddata(0x38) self.lcd_senddata(0x0F) self.lcd_sendcmd(0x29) #Display On.
  • Page 20 | 4 - Demo Source Code #Clear contents of image buffer. _buffer = [color]*(self.width * self.height *2) self.lcd_setPos(0, 0, self.width, self.height) gpio.output(self.dcpin, gpio.HIGH) #Multi-byte-write. self.lcd_sendnbytes(_buffer) lcd_ShowImage(self, Image, Xstart, Ystart): #Set buffer to the value of the Python Imaging Library image. #Write display buffer to the physical display.

Table of Contents