yqzp
@yqzp
0
声望
2
楼层
461
资料浏览
0
粉丝
0
关注
yqzp 发布的帖子
-
想用自己的0.96寸OLED显示东西,不想用拓展板之类的,求有没有解决办法?
自己写了半天的配置,结果OLED没反应……查帖子也没人解决啊只说有LCD!
希望有大佬解释一下原因# SPI Control 0.96 OLED未完 import sensor, image, time from pyb import Pin, SPI gram = [ [0] * 8 for i in range(128)] cs = Pin("P3", Pin.OUT_OD) rst = Pin("P7", Pin.OUT_PP) rs = Pin("P8", Pin.OUT_PP) # The hardware SPI bus for your OpenMV Cam is always SPI bus 2. spi = SPI(2, SPI.MASTER, baudrate=int(1000000000/66), polarity=0, phase=0) def write_command_byte(c): cs.low() rs.low() spi.send(c) cs.high() def write_data_byte(c): cs.low() rs.high() spi.send(c) cs.high() def write_command(c, *data): write_command_byte(c) if data: for d in data: write_data_byte(d) def write_image(img): cs.low() rs.high() spi.send(img) cs.high() def write_string(*s): if s: for d in s: write_data_byte(d) # Reset the OLED. def reset_oled(): rst.low() time.sleep(100) rst.high() time.sleep(100) # 开启OLED显示 def display_on(): write_command_byte(0x8D) time.sleep(120) write_command_byte(0x14) time.sleep(120) write_command_byte(0xAF) # Sleep Exit time.sleep(120) # 关闭OLED显示 def display_off(): write_command_byte(0x8D) time.sleep(120) write_command_byte(0x10) time.sleep(120) write_command_byte(0xAE) # Sleep time.sleep(120) #更新显存到LCD def OLED_Refresh_Gram(): for i in range(0,8): write_command_byte (0xb0+i) #设置页地址(0~7) write_command_byte (0x00) #设置显示位置—列低地址 write_command_byte (0x10) #设置显示位置—列高地址 for n in range(0,128): write_string(gram[n][i]) # 画点函数 def draw_point(x,y,t): if(x>127|y>63):return; temp = 1<<(7-(y%8)) if(t):gram[x][7-y//8]|=temp else:gram[x][7-y//8]&=~temp # 填充函数x1<=x2;y1<=y2 0<=x1<=127 0<=y1<=63 def OLED_Fill(x1,y1,x2,y2,dot) : for x in range(x1,x2): for y in range(y1,y2): draw_point(x,y,dot) OLED_Refresh_Gram() reset_oled() time.sleep(120) display_on() time.sleep(120) while(True): OLED_Fill(20,5,108,58,1) time.sleep(120)