Arduino Uno: Displaying Chinese Characters on OLED

Arduino Uno: Displaying Chinese Characters on OLED In this week’s general education class “Open Source Hardware and Makers”, the teacher explained the display principle of OLED screens, the concept of serial buses, and driving methods. During the class experiment, we wrote programs to drive the OLED display to show characters at specified positions. After the experiment, the teacher assigned an extension task, which was to display Chinese characters on the OLED screen, even custom characters. For this, I explored some relevant materials.

1. Basic Experiment

1. Experiment Preparation:

Platform: Arduino Grove Development Board (based on Uno)

Development System: Windows 10

OLED Display: SSD 1306 128*64 (included with Groove)

IDE: Arduino IDE

2. Preparing the Experiment Library:

Download the U8g2 library

Arduino Uno: Displaying Chinese Characters on OLED

3. Uploading the Program:

After installation, compile and upload the example program

Arduino Uno: Displaying Chinese Characters on OLED

The display effect is as follows:

Arduino Uno: Displaying Chinese Characters on OLED

The initial experiment is now complete.

2. Advanced Experiment

1. Introduction:

Why do we say it is a preliminary implementation? Let’s take a look at the official Chinese library.

Arduino Uno: Displaying Chinese Characters on OLED

This library can display very few Chinese characters, modifying the program from 1 and 3 here to:

u8g2.print(“Temperature:温度”);

It is found that the character “温” does not display at all, indicating that the character is not in the font library. So what to do?

I first thought of using the gb2312a font library provided above, but note that this library is not included in the U8g2 library and needs to be downloaded and imported separately.

Download the corresponding version zip file from https://github.com/larryli/U8g2_wqy_Arduino/releases, then in the Arduino IDE menu project, load library and add a .ZIP library.

Arduino Uno: Displaying Chinese Characters on OLED

Then add based on the original program

Arduino Uno: Displaying Chinese Characters on OLED

Change the font to

Arduino Uno: Displaying Chinese Characters on OLED

After compiling, an error is found, and it will report an error as long as the header file is included

Arduino Uno: Displaying Chinese Characters on OLED

The reason is simple, the Arduino Uno’s memory is pitifully small, only 32 KB. Think about it, any Chinese font is unlikely to be less than 3MB, but our Arduino development board has very little memory and storage space, how could it possibly load a complete Chinese font?

In summary, in microcontroller development, we generally do not import all fonts, we only need to import the fonts we need.

3. Installing Custom Chinese Font Library

1. Preparation Work:

To do this, we need to use a tool from U8g2: bdfconv.

(Note: Installing the U8g2 library does not install the tools we will use later, so you still need to download it yourself.)

Download the tools folder from GitHub and import it into the Arduino library folder.

Arduino Uno: Displaying Chinese Characters on OLED

We first need to add the required fonts to a U8g2\tools\font\build\chinese1.map file.

Open this file with Notepad and find that it stores the unicode codes of the fonts. We just need to replace it with the characters we want to add.

Arduino Uno: Displaying Chinese Characters on OLED

Use Baidu’s online unicode converter to convert “Temperature and Humidity Meter” to \u6e29\u6e7f\u5ea6\u6d4b\u91cf\u4eea (taking these characters as an example, the Chinese3 library can only display the characters “度” and “仪”)

Then replace \u with $ and import it into the chinese1.map file. This can be done using the “replace” function in Notepad, no need to change it character by character.

Arduino Uno: Displaying Chinese Characters on OLED

2. Converting Characters:

Press win+r to open the command line, enter the bdfconv folder (this step needs to be modified according to the folder where the Arduino library is located, generally in the Documents directory)

Arduino Uno: Displaying Chinese Characters on OLED

Execute the following command (can be executed directly)

Arduino Uno: Displaying Chinese Characters on OLED

In its directory, obtain the u8g2_font_unifont.c file, open it with Notepad, and copy the following content:

Arduino Uno: Displaying Chinese Characters on OLED

Paste it into:

~/Documents\Arduino\libraries\U8g2\src\clib directory’s u8g2_fonts.c file;

Search for wqy16_t_chinese1 and replace the above content, save and exit (the above conversion is for 16*16).

Arduino Uno: Displaying Chinese Characters on OLED

Remember to change the text of array size too! (This point is crucial!)

3. Running Tests:

Now the wqy16_t_chinese1 font library contains the fonts we need, let’s run a test.

Arduino Uno: Displaying Chinese Characters on OLED

The result is as shown:

Arduino Uno: Displaying Chinese Characters on OLED

All can be displayed normally, successfully completing the display of any Chinese characters! 🎉🎉🎉

Comparison with using chinese3:

Arduino Uno: Displaying Chinese Characters on OLED

References:

Arduino Uno: Displaying Chinese Characters on OLED

Text Edited by: Marine Science 202083450083 Li Liuxing (Freshman)

Image Provided by: Li Liuxing

Beautification Editing: Cheng Hongliu Wang Yingying

Editor: Chen Xueming

Arduino Uno: Displaying Chinese Characters on OLED

Leave a Comment

Your email address will not be published. Required fields are marked *