683 views|2 replies

11

Posts

3

Resources
The OP
 

【Digi-Key Follow me Issue 2】Task 1: Control the screen to display Chinese [Copy link]

 This post was last edited by StreakingJerry on 2023-9-19 19:30

Hello everyone, I am an amateur electronic DIY enthusiast. In the first lesson, we will teach you how to use CircuitPython to display Chinese characters.

In traditional embedded development, displaying Chinese characters has always been a troublesome task, because you have to count the Chinese characters that need to be displayed first, and then take the modulus. If there are many Chinese characters to be displayed, there may be a problem of excessive memory usage. This time we conducted experiments on the Adafruit ESP32-S3 TFT Feather. This board has 4M flash, 2M PSRAM, and a 1.14-inch IPS display, which is more than enough for displaying Chinese. Not only that, because the memory is large enough, we can even import a complete Chinese font library, so there is no need to count the Chinese characters that need to be displayed in advance. This is very useful in some applications, such as web browsers, or e-books.

Let's first look at the code implementation method. The CircuitPython firmware already comes with a screen driver, so it is very convenient to use. The initialization code only requires three lines:

import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label

display = board.DISPLAY
group = displayio.Group()
display.show(group)

Here comes the point, because we need to display Chinese, we need to download the PCF font file ourselves and load it into the code.

font = bitmap_font.load_font("/wenquanyi_13px.pcf")

Next, we create a text element and add it to the screen for display, and all the settings are complete. Here we predefine a common color dictionary for easy use.

color = {
        "black" : 0x000000,
        "white" : 0xFFFFFF,
        "red" : 0xFF0000,
        "green" : 0x00FF00,
        "blue" : 0x0000FF,
        "cyan" : 0x00FFFF,
        "magenta" : 0xFF00FF,
        "yellow" : 0xFFFF00,
        }

text_tg = label.Label(font, color=color["white"])
text_tg.y = 60
text_tg.x = 0
text_tg.background_color = None
text_tg.line_spacing = 1.0
text_tg.scale = 3
group.append(text_tg)

Finally, you only need to set the text content of the element in the code. When the text content changes, the new text will appear on the screen synchronously.

text_tg.text = "你好,世界!"

This post is from DigiKey Technology Zone

Latest reply

I have learned it. The master's tutorial has come out, but mine has not yet arrived.   Details Published on 2023-9-22 09:21
 
 

6570

Posts

0

Resources
2
 

Although I am an amateur electronics DIY enthusiast, I have done a good job using CircuitPython to display Chinese characters.

This post is from DigiKey Technology Zone
 
 
 

36

Posts

1

Resources
3
 

I have learned it. The master's tutorial has come out, but mine has not yet arrived.

This post is from DigiKey Technology Zone
 
 
 

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