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"...
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...
| 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.
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:...
| 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.
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)
Need help?
Do you have a question about the VisionFive SPI and is the answer not in the manual?
Questions and answers