使用Openmv驱动OLED

liluan_sama 2019-08-02 05:37:24
想使用openmv控制0.96寸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)
...全文
1686 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liluan_sama 2019-08-09
  • 打赏
  • 举报
回复
没有,觉得浪费引脚,干脆接了个STM32板子,给他发数据让他显示OLED
pengyao1207000001 2019-08-07
  • 打赏
  • 举报
回复
大佬研究出来了码?
liluan_sama 2019-08-02
  • 打赏
  • 举报
回复
用的4线SPI模式

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧