一、环境搭建
链接一年过期,注意看看时间
- thonny-4.0.1获取:百度云盘资源获取
软件直接下载安装即可,什么你说你不会用thonny?请跳转至第0篇文章
- 取字软件PCtoLCD2002:百度云盘资源获取
具体配置如下图:
打开软件,点击上面的选项
会弹出如下图所示:
跟着图设置完之后一点要记得按确定
出来之后在下方输入框中输入你想要的文字,点击生成字模
把内容复制了
- 使用的开发板:esp32s(esp-wroom-32)
二、代码编写
把刚刚复制的内容放到下面代码的chine
里
(没有ssd1306的请看上一篇文章)
# oled.py
from machine import Pin, SoftSPI
from ssd1306 import SSD1306_SPI
dc = Pin(2, Pin.OUT)
res = Pin(15, Pin.OUT)
cs = Pin(4, Pin.OUT)
spi = SoftSPI(baudrate=100000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
oled = SSD1306_SPI(128, 64, spi, dc, res, cs)
class Chine:
chine = [
0x20,0x20,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x20,0x20,0x00,
0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00, # 元,0
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
0x40,0x40,0x40,0x4F,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x4F,0x40,0x40,0x40,0x00, # 旦,1
0x00,0xE0,0x00,0xFF,0x10,0x20,0x08,0x08,0x08,0xFF,0x08,0x08,0xF8,0x00,0x00,0x00,
0x01,0x00,0x00,0xFF,0x00,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x81,0x00, # 快,2
0x00,0x00,0xE0,0x9C,0x84,0x84,0x84,0xF4,0x82,0x82,0x83,0x82,0x80,0x80,0x00,0x00,
0x00,0x20,0x10,0x08,0x06,0x40,0x80,0x7F,0x00,0x00,0x02,0x04,0x08,0x30,0x00,0x00, # 乐,3
]
def ByteOpera16x16(num, dat):
byte = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]
if dat & byte[num]:
return 1
else:
return 0
def LcdShowCh_32x32(n, x_axis, y_axis):
for i in range(2): # 行的显示,改为4会有异常
for a in range(16): # 列的显示,改为8显示左半个字
for b in range(8): # 像素点显示,8显示完整,数字小像素显示少
index = n * 32 + i * 16 + a
if index < len(Chine.chine) and ByteOpera16x16(b, Chine.chine[index]):
oled.pixel(x_axis + a, y_axis + i * 8 + b, 1)
else:
oled.pixel(x_axis + a, y_axis + i * 8 + b, 0)
def main():
oled.fill(0) # 清屏
LcdShowCh_32x32(0, 0, 0)# 显示“元”
LcdShowCh_32x32(1, 16, 0)# 显示“旦”
LcdShowCh_32x32(2, 32, 0)# 显示“快”
LcdShowCh_32x32(3, 48, 0)# 显示“乐”
oled.show() # 显示
if __name__ == "__main__":
main()