5710 views|6 replies

157

Posts

0

Resources
The OP
 

【Weixue RP2040 dual-core development board】 Four ways to display five pictures [Copy link]

Image display 4 ways

material:

图片显示2.docx (2 MB, downloads: 7)

Image2Lcd2.9.zip (513.02 KB, downloads: 4) Python.rar (446.12 KB, downloads: 6)

We have talked a lot about theory before. Now let’s do some practical work.

  • The simplest way to display images

1. Use image acquisition software to obtain image dot matrix data

2. Image display effect, single-color display image 90*90

3. The program uses Weixue's official LCDDome, and adding the following code makes the operation simple and effective. . .

4. framebuf.MONO_HLSB frame buffer operation is as follows

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/framebuf.html

But the memory of Pico is too small, and the monochrome 240*240 images cannot be loaded into it all at once.

A monochrome image requires 37k of cache consumption, but Micropico has only 19k of cache left. The chip cache is around 256k, and the rest of the memory should be consumed by the C program and interpreter, so the image size is changed to 90*90, so that the refresh speed is fast.

  1. Weixue code data, add the screenshot code above to achieve

  • Color image display

This time, we generate dot matrix data from the image and store the dot matrix data in the internal program cache. Due to the limitation of internal cache space, the color image is further reduced in size.

1. The parameter configuration of the dot matrix software is shown in the figure

The hexadecimal dot matrix data generated by this tool software can be stored in the internal cache.

  1. Main code

The main code refers to the necessary code except LCDdome

Pattern =[ ] #Store the generated dot matrix data in the brackets

#The following 32, 32 is the x, y size of the image RGB565 encoding method

buf = framebuf.FrameBuffer(bytearray(pattern), 32, 32, framebuf.RGB565)# RGB565

# MONO_HLSB MONO_VLSB

# Load the processed pixels

LCD.blit(buf,90,90,LCD.white)

#print(byteModehex)

# Display the loaded data

LCD.show()

3. The display effect is as shown in the figure

  • Color image display (external flash storage image information)
  1. Software Configuration

Two pictures are set here. Due to the pixel color saturation, the display effect of the first picture is not good.

  1. Actual display effect

  1. Video of the actual image refresh process

Since the internal cache space is limited and the dot matrix data needs to be decoded and re-encoded, the refresh speed is very slow. If the C language is used for development, the refresh speed will be doubled, because the C language does not need more operations. Just like the smooth display of the last image.


一次性刷新

  1. Dot matrix document production

4.1. The code generated by img2LCD software is in C language, and the generated dot matrix data is as follows

4.2. When the micropython program uses file = open("huawei.txt",'r'); to read the txt file, it gets a string, and the string contains carriage return and line feed\r\n. So for the convenience of operation, I re-edited the dot matrix data with vscode, removed 0x, and created a new txt document to store the processed dot matrix code in it. As shown in the figure

5. Import the Txt document into pico

6. Main code

#LCD.fill_rect(0,0,240,240,0)

file = open("huawei.txt",'r');

#file = open("maliao.txt",'r');

j = 0

while j<19:

# Due to cache space limitations, all data cannot be loaded into the cache at once, so the current design loads 5 lines of dot matrix data at a time and scans 19 times to display the image

byteModehex = bytearray(960)

#Create a new hexadecimal buffer array and apply for space

offset = 2040*j

#Offset the image to display five lines at a time 96*5 Because RGB565 takes 2 bytes, 5 lines need 96*5*2. The main dot matrix data is 960 bytes

# Because the data in the txt file is a character line, which is actually two characters in a hexadecimal format, 96*5*2*2=1920. This is the valid data that needs to be obtained from the txt file.

# But when reading a txt file, there are carriage return and line feed characters inside, and there are 32 characters in a line. In addition, there are 2 characters after each line (\r\n), so 1920/32*34 = 2040

file.seek(offset,0)

i = 0

huan = 0

#file.seek(960,0)

while i<960: # effective data of dot matrix is 960 bytes

#The main reason for the full display of the image is again that too much judgment and calculation consumes the chip operation cycle

patten = file.read(2) # readline # read # readlines

if patten[0] =='\r' or patten[0] =='\n': # Prevent cached data from getting \r\n and affecting dot matrix dislocation

#print('newline')

huan = huan+1

else :

# Convert the character to the high 4 digits of hexadecimal

if patten[0] >='A' or patten[0] <='F':

num = ord(patten[0]) - ord('A') +10

elif patten[0] >='0' or patten[0] <='9':

num = ord(patten[0]) - ord('0') +10

# Convert the character to the lower 4 bits of hexadecimal

if patten[1] >='A'or patten[1] <='F':

num1 = ord(patten[1]) - ord('A') +10

elif patten[1] >='0'or patten[1] <='9':

num1 = ord(patten[1]) - ord('0') +10

#The fourth bit of the high four bits forms a byte

number = num*16+num1

#Store valid data into the cache array in sequence

byteModehex = number

i = i+1

#patbuf = patten.strip().split()

#time.sleep(0.01) # Delay

#print(byteModehex)

#print(pattern)

#print("huan",huan)

#print(offset)

#The y axis gradually refreshes downward

y = 70 + j*5

#Use frame buffer to standardize RGB display pixels one by one

buf = framebuf.FrameBuffer(bytearray(byteModehex), 96, 5, framebuf.RGB565)# RGB565 # MONO_HLSB MONO_VLSB

LCD.blit(buf, 70, y,LCD.white)

#print(byteModehex)

#LCD.show() # This bit refreshes every 5 lines and the video phenomenon is always the same

j = j+1

LCD.show() #Refresh at this position. Multiple data is passed to the LCD, but it is not displayed. After the initial transmission, it is refreshed uniformly. Data loading still consumes time, but the refresh is not stuck. Refreshing in seconds is a common method for LCD display.

file.close() #The third step is to close the refrigerator door, otherwise the elephant may run away

  • Update firmware version image display

https://bbs.eeworld.com.cn/thread-1227388-1-1.htmlFor details, please refer to this link, which is more detailed and better.

链接已隐藏,如需查看请登录或者注册
Firmware code download link

  1. Firmware Update

First, update the firmware, because the Weixue firmware does not have a picture display function, only an LCD display with basic functions.

  1. Download the picture to Pico, right-click on the picture in Thonny and upload it.

The image is used. Bmp image pixel size is 240*240 Any image can be

3. The example code display effect is great

'''

jpg.py

Draw a full screen jpg using the slower but less memory intensive method

of blitting each Minimum Coded Unit (MCU) block. Usually 8×8 pixels but can

be other multiples of 8.

GC9A01 display connected to a Raspberry Pi Pico.

Pico Pin Display

========= =======

14 (GP10) BL

15 (GP11) RST

16 (GP12) DC

17 (GP13) CS

18 (GND) GND

19 (GP14) CLK

20 (GP15) DIN

bigbuckbunny.jpg (c) copyright 2008, Blender Foundation / www.bigbuckbunny.org

'''

import gc

import time

from machine import Pin, SPI

import gc9a01

gc.enable()

gc.collect()

def main():

'''

Decode and draw jpg on display

'''

spi = SPI(1, baudrate=60000000, sck=Pin(10), mosi=Pin(11))

tft = gc9a01.GC9A01(

spi,

240,

240,

reset=Pin(12, Pin.OUT),

cs=Pin(9, Pin.OUT),

dc=Pin(8, Pin.OUT),

backlight=Pin(25, Pin.OUT),

rotation=0)

# enable display and clear screen

tft.init()

# cycle thru jpg's

while True:

for image in ["bigbuckbunny.jpg", "bluemarble.jpg"]:

tft.jpg(image, 0, 0, gc9a01.SLOW)

time.sleep(5)

main()

This post is from Mobile and portable

Latest reply

Everything is written in C~so C language runs fastest~   Details Published on 2023-11-25 11:13
 
 

4771

Posts

12

Resources
2
 

Hua Xiaozi saluted after reading the post

This post is from Mobile and portable

Comments

I don't quite understand what it means.  Details Published on 2023-1-12 16:16
 
 
 

6788

Posts

2

Resources
3
 

Everything is written in C~so C language runs fastest~

This post is from Mobile and portable

Comments

Right, right, right  Details Published on 2023-1-12 16:18
 
 
 

157

Posts

0

Resources
4
 
Azuma Simeng posted on 2023-1-12 15:08 Hua Xiaozi read the post and saluted

I don't quite understand what it means.

This post is from Mobile and portable
 
 
 

157

Posts

0

Resources
5
 
wangerxian posted on 2023-1-12 15:28 Everything is written in C~so C language runs the fastest~

Right, right, right

This post is from Mobile and portable
 
 
 

157

Posts

0

Resources
6
 
G886 posted on 2023-1-25 20:39 All monochrome 240*240 images cannot be loaded at once. Series

The cache is too small


This post is from Mobile and portable
 
 
 

154

Posts

0

Resources
7
 

Everything is written in C~so C language runs fastest~

This post is from Mobile and portable
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list