557 views|2 replies

21

Posts

0

Resources
The OP
 

Digi-Key Electronics Follow me Phase 2 Task Submission - Control the screen to display Chinese [Copy link]

 

Digi-Key Electronics Follow me Phase 2 Task Submission - Control the screen to display Chinese

Because Chinese characters need to be displayed, font files are essential. Currently, the firmware can only recognize fonts in bdf and pcf formats. It is necessary to convert the fonts in ttf format to pcf format. Here, a font conversion tool otf2bdf is needed. According to the teacher's introduction in the live broadcast and the experience shared by other forum friends, this dictionary file size is just right for this development and will be uploaded at the end of the article.

The following code can display all Chinese characters in the font library on the screen

First, import the package. Here we use the board displayio adafruit_display_text adafruit_bitmap_font package.

You can add it directly through the shortcut keys of vscode. The specific steps are as follows

Press ctrl+shift+p on the keyboard and enter the following in the pop-up dialog box

You can get the automatic installation package service provided by CircuitPython plug-in

The import code is as follows

import board

import displayio

from adafruit_display_text import label, wrap_text_to_lines

from adafruit_bitmap_font import bitmap_font

Then define a Chinese string information and load the font information to display the Chinese font color, etc. The code is as follows

dis_str = "我是一条中文信息"

font = bitmap_font.load_font("wenquanyi_10pt.pcf")

color = 0x00FFFF

Then determine the number of characters that can be displayed on each line according to the screen rotation angle

def screen_dispstr(str):

if board.DISPLAY.rotation % 180 == 0:

char_num = 23 # 横屏

else:

char_num = 13 # 竖屏

strbuf = ""

for i in range(len(str) / char_num):

strbuf = strbuf + str[i * char_num:(i + 1) * char_num] + "\n"

return strbuf

Initialize the display

display = board.DISPLAY

board.DISPLAY.brightness = 0.35

board.DISPLAY.rotation = 0

Display Chinese characters

text_group = displayio.Group()

text_area = label.Label(font, text=screen_dispstr(dis_str), color=color)

text_area.x = 2

text_area.y = 6

text_area.line_spacing = 0.8

text_area.scale = 1

text_group.append(text_area)

display.show(text_group)

Keep the program looping and outputting to the screen

while True:

pass

Finally, let’s take a look at the finished effect.

After downloading the code provided by the teacher, I learned how to display a picture.

image, palette = adafruit_imageload.load(

"images/ysqd.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette

)

tile_grid = displayio.TileGrid(image, pixel_shader=palette)

group = displayio.Group()

group.append(tile_grid)

board.DISPLAY.show(group)

By calling the palette method in image, you can display a picture on the screen. This study also discovered how the teacher's hidden Easter egg is the original god startup!


The dictionary file is as follows: wenquanyi_10pt.pcf (2.18 MB, downloads: 4)
This post is from DigiKey Technology Zone

Latest reply

This picture of the original god is quite clear!   Details Published on 2023-10-24 18:54
 
 

6748

Posts

2

Resources
2
 

This picture of the original god is quite clear!

This post is from DigiKey Technology Zone

Comments

Haha, yes! Although the resolution of this screen is a bit low, the colors are very full!  Details Published on 2023-10-24 19:32
 
 
 

21

Posts

0

Resources
3
 
wangerxian posted on 2023-10-24 18:54 This original god picture is quite clear!

Haha, yes! Although the resolution of this screen is a bit low, the colors are very full!

This post is from DigiKey Technology Zone
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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