Micropython Tpyboard v102 Development Board control OLED display Chinese

Source: Internet
Author: User

Reprint please indicate the source of the article in the form of a link, public number: Micropython player


0x00 Preface

Previously saw an article about TPYBoardv102 control OLED screen display, after seeing to try to use the OLED screen to display Chinese. The recent use of spare time to finish the experiment, hereby will be the experimental process and the source to share, convenient for later use.

0X01 Laboratory Equipment

TPYBOARDV102 Development Board 1 pieces

0.96-inch OLED display (ssd1306) 1 blocks

DuPont Line several

Pre-0x02 Preparation

1, first we first look at, before referring to the OLED display characters of the article.

Http://docs.tpyboard.com/zh/latest/tpyboard/tutorial/v10x/oled/?highlight=oled

The source files in the article have been uploaded to GitHub. Address: Https://github.com/TPYBoard/developmentBoard/tree/master/TPYBoard-v10x-master

Find [11. Learn to use OLED display] inside is the source program. I was developed on the basis of font.py and ssd1306.py.

2, in the font.py to increase the Chinese character mode.

Font.py has characters in English, numerals and symbols, we need to add Chinese fonts to font.py.

2.1 First download the Font Extraction tool. Address: http://tpyboard.com/download/tool/187.html

Unzip, double-click to run PCtoLCD2002.exe.

2.2 The top menu bar, click [Options] Press the picture settings below, set it up and click [OK] to save the settings.

2.3 Back to the main interface, enter "I" in the input box and click [Generate Matrix].

The font data obtained are as follows:

0x04,0x0e,0x78,0x08,0x08,0xff,0x08,0x08,0x0a,0x0c,0x18,0x68,0x08,0x08,0x2b,0x10

0x40,0x50,0x48,0x48,0x40,0xfe,0x40,0x44,0x44,0x48,0x30,0x22,0x52,0x8a,0x06,0x02/* "Me", 0*/

2.4 Add the font data you have taken to the font.py.

The green box is the 16 binary utf-8 encoding of "Me".

Online tool: http://tool.lu/hexstr/

Referring to the above methods, I successively added the "I Love Your Motherland" The 5 characters of the font.

Byte2 = {

0xe68891:

[

0X04,0X0E,0X78,0X08,0X08,0XFF,0X08,0X08,0X0A,0X0C,0X18,0X68,0X08,0X08,0X2B,0X10,

0X40,0X50,0X48,0X48,0X40,0XFE,0X40,0X44,0X44,0X48,0X30,0X22,0X52,0X8A,0X06,0X02,

], #我

0XE788B1:

[

0X00,0X01,0X7E,0X22,0X11,0X7F,0X42,0X82,0X7F,0X04,0X07,0X0A,0X11,0X20,0X43,0X1C,

0X08,0XFC,0X10,0X10,0X20,0XFE,0X02,0X04,0XF8,0X00,0XF0,0X10,0X20,0XC0,0X30,0X0E,

], #爱

0XE4BDA0:

[

0X08,0X08,0X08,0X11,0X11,0X32,0X34,0X50,0X91,0X11,0X12,0X12,0X14,0X10,0X10,0X10,

0x80,0x80,0x80,0xfe,0x02,0x04,0x20,0x20,0x28,0x24,0x24,0x22,0x22,0x20,0xa0,0x40,

], #你

0xe7a596:

[

0X20,0X11,0X11,0XF9,0X09,0X11,0X11,0X39,0X55,0X95,0X11,0X11,0X11,0X11,0X17,0X10,

0x00,0xf8,0x08,0x08,0x08,0xf8,0x08,0x08,0x08,0xf8,0x08,0x08,0x08,0x08,0xfe,0x00

], #祖

0XE59BBD:

[

0x00,0x7f,0x40,0x40,0x5f,0x41,0x41,0x4f,0x41,0x41,0x41,0x5f,0x40,0x40,0x7f,0x40,

0x00,0xfc,0x04,0x04,0xf4,0x04,0x04,0xe4,0x04,0x44,0x24,0xf4,0x04,0x04,0xfc,0x04

], #国

}

3, in the ssd1306.py file added Draw_chinese display Chinese method.

def Draw_chinese (Self,ch_str,x_axis,y_axis):

Offset_=0

y_axis=y_axis*8# Chinese height of 8

x_axis=127-(x_axis*16) #中文宽度占16个

For K in Ch_str:

Code = 0x00# Convert Chinese to 16 encoding

Data_code = K.encode ("Utf-8")

Code |= DATA_CODE[0]<<16

Code |= data_code[1]<<8

Code |= DATA_CODE[2]

Byte_data=font.byte2[code]

For y in range (0,16):

A_=bin (Byte_data[y]). Replace (' 0b ', ')

While Len (A_) <8:

a_= ' 0 ' +a_

B_=bin (byte_data[y+16]). Replace (' 0b ', ')

While Len (b_) <8:

b_= ' 0 ' +b_

For x in range (0,8):

Self.set_pixel (X_axis-x-offset_,y+y_axis,int (a_[x)) #文字的上半部分

Self.set_pixel (X_axis-x-8-offset_,y+y_axis,int (b_[x)) #文字的下半部分

Offset_+=16

GitHub Source Address: https://github.com/TPYBoard/developmentBoard/tree/master/TPYBoard-v10x-master/

Find [20. Learn OLED display Chinese].

0X03 Hardware Connection

The experiment uses the OLED SPI communication method, TPYBoardv102 with 2 SPI interface, I use the SPI1.

The specific wiring method is as follows:

Tpyboard v102 (SPI1)

OLED Display (SPI)

3.3V

VCC (2.8v~5.5v)

GND

GND

X6 (SCK)

Sck/d0

X8 (MOSI)

Sda/d1

Y10

Res

Y9

DC

NC (floating)

Cs

0x04 Effect Display

After the hardware wiring OK, the source code is all copied to the TPYBaordv102 loaded disk, press the RST key reset or use the Putty software ctrl+d soft Reset, re-run the effect as follows:


  

Micropython Tpyboard v102 Development Board control OLED display Chinese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.