esp32、8266等microPython设备的显示屏驱动代码,可用于I2C及SPI
OLED ssd1306库文件 很多人在分享这个库文件都是要积分购买的 这里我就免费共享给大家 给博主点个赞呗

#MicroPython SSD1306 OLED driver, I2C and SPI interfaces created by Adafruitimport time
import framebuf# register definitions
SET_CONTRAST        = const(0x81)
SET_ENTIRE_ON       = const(0xa4)
SET_NORM_INV        = const(0xa6)
SET_DISP            = const(0xae)
SET_MEM_ADDR        = const(0x20)
SET_COL_ADDR        = const(0x21)
SET_PAGE_ADDR       = const(0x22)
SET_DISP_START_LINE = const(0x40)
SET_SEG_REMAP       = const(0xa0)
SET_MUX_RATIO       = const(0xa8)
SET_COM_OUT_DIR     = const(0xc0)
SET_DISP_OFFSET     = const(0xd3)
SET_COM_PIN_CFG     = const(0xda)
SET_DISP_CLK_DIV    = const(0xd5)
SET_PRECHARGE       = const(0xd9)
SET_VCOM_DESEL      = const(0xdb)
SET_CHARGE_PUMP     = const(0x8d)class SSD1306:def __init__(self, width, height, external_vcc):self.width = widthself.height = heightself.external_vcc = external_vccself.pages = self.height // 8# Note the subclass must initialize self.framebuf to a framebuffer.# This is necessary because the underlying data buffer is different# between I2C and SPI implementations (I2C needs an extra byte).self.poweron()self.init_display()def init_display(self):for cmd in (SET_DISP | 0x00, # off# address settingSET_MEM_ADDR, 0x00, # horizontal# resolution and layoutSET_DISP_START_LINE | 0x00,SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0SET_MUX_RATIO, self.height - 1,SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0SET_DISP_OFFSET, 0x00,SET_COM_PIN_CFG, 0x02 if self.height == 32 else 0x12,# timing and driving schemeSET_DISP_CLK_DIV, 0x80,SET_PRECHARGE, 0x22 if self.external_vcc else 0xf1,SET_VCOM_DESEL, 0x30, # 0.83*Vcc# displaySET_CONTRAST, 0xff, # maximumSET_ENTIRE_ON, # output follows RAM contentsSET_NORM_INV, # not inverted# charge pumpSET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14,SET_DISP | 0x01): # onself.write_cmd(cmd)self.fill(0)self.show()def poweroff(self):self.write_cmd(SET_DISP | 0x00)def contrast(self, contrast):self.write_cmd(SET_CONTRAST)self.write_cmd(contrast)def invert(self, invert):self.write_cmd(SET_NORM_INV | (invert & 1))def show(self):x0 = 0x1 = self.width - 1if self.width == 64:# displays with width of 64 pixels are shifted by 32x0 += 32x1 += 32self.write_cmd(SET_COL_ADDR)self.write_cmd(x0)self.write_cmd(x1)self.write_cmd(SET_PAGE_ADDR)self.write_cmd(0)self.write_cmd(self.pages - 1)self.write_framebuf()def fill(self, col):self.framebuf.fill(col)def pixel(self, x, y, col):self.framebuf.pixel(x, y, col)def scroll(self, dx, dy):self.framebuf.scroll(dx, dy)def text(self, string, x, y, col=1):self.framebuf.text(string, x, y, col)class SSD1306_I2C(SSD1306):def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):self.i2c = i2cself.addr = addrself.temp = bytearray(2)# Add an extra byte to the data buffer to hold an I2C data/command byte# to use hardware-compatible I2C transactions.  A memoryview of the# buffer is used to mask this byte from the framebuffer operations# (without a major memory hit as memoryview doesn't copy to a separate# buffer).self.buffer = bytearray(((height // 8) * width) + 1)self.buffer[0] = 0x40  # Set first byte of data buffer to Co=0, D/C=1self.framebuf = framebuf.FrameBuffer1(memoryview(self.buffer)[1:], width, height)super().__init__(width, height, external_vcc)def write_cmd(self, cmd):self.temp[0] = 0x80 # Co=1, D/C#=0self.temp[1] = cmdself.i2c.writeto(self.addr, self.temp)def write_framebuf(self):# Blast out the frame buffer using a single I2C transaction to support# hardware I2C interfaces.self.i2c.writeto(self.addr, self.buffer)def poweron(self):passclass SSD1306_SPI(SSD1306):def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):self.rate = 10 * 1024 * 1024dc.init(dc.OUT, value=0)res.init(res.OUT, value=0)cs.init(cs.OUT, value=1)self.spi = spiself.dc = dcself.res = resself.cs = csself.buffer = bytearray((height // 8) * width)self.framebuf = framebuf.FrameBuffer1(self.buffer, width, height)super().__init__(width, height, external_vcc)def write_cmd(self, cmd):self.spi.init(baudrate=self.rate, polarity=0, phase=0)self.cs.high()self.dc.low()self.cs.low()self.spi.write(bytearray([cmd]))self.cs.high()def write_framebuf(self):self.spi.init(baudrate=self.rate, polarity=0, phase=0)self.cs.high()self.dc.high()self.cs.low()self.spi.write(self.buffer)self.cs.high()def poweron(self):self.res.high()time.sleep_ms(1)self.res.low()time.sleep_ms(10)self.res.high()

ssd1306.py相关推荐

  1. 用官方的SSD1306.py 驱动 OLED

    2019独角兽企业重金招聘Python工程师标准>>> 这几天看了一下micropython的I2C OLED驱动(SPI的类似),发现有几个版本.一个是官方的版本,还有早期网上流传 ...

  2. python oled_用官方的SSD1306.py 驱动 OLED

    这几天看了一下micropython的I2C OLED驱动(SPI的类似),发现有几个版本.一个是官方的版本,还有早期网上流传的版本. 网上的版本使用了pyb.I2C驱动,是将Arduino的OLED ...

  3. micropython lcd12864_Esp8266+ssd1306液晶屏+microPython(2020-09-25)

    image.png image.png ssd1306_test.py 保存后上传到芯片根文件夹就可 # 0.96英寸 ssd1306 液晶显示屏 # Esp8266的Pin5一般指芯片上的D1针脚. ...

  4. 【MicroPython ESP32】ssd1306驱动0.96“I2C屏幕cube3D图形显示

    [MicroPython ESP32]ssd1306驱动0.96"I2C屏幕cube3D图形显示 cube3D效果 原例程最早在一个Arduino ssd1306 i2c库的示例中可以找到这 ...

  5. 【MicroPython ESP32】ssd1306驱动0.96“I2C屏幕+mpu6050图形控制

    [MicroPython ESP32]ssd1306驱动0.96"I2C屏幕+mpu6050图形控制 效果演示 随着mpu6050模块的移动,oled屏幕矩形线框内的小方块也随对应的方向移动 ...

  6. ESP32开发之旅——ssd1306 OLED屏的使用

    ESP32开发之旅--ssd1306 OLED屏的使用 前言 在本文中,您将学会ssd1306 OLED屏在ESP32中的使用,本文提供了简单的示例供学习参考. 需要注意的是,本文中的ESP32是使用 ...

  7. 利用pyBoard的实验来讨论部分MicroPython特性

    ▌01 pyBoard系统函数 pyBoard 提供了pyb.micros() 返回MCU从reset开始之后度过的时间,单位us. 相类似的还有millis().使用elapsed_micros(s ...

  8. pyBoard Mini从安装到简单测试

    ▌01 PyBoard Mini 在 淘宝购买到的<Python微控制器编程 从零开始> ,其中提到了 pyBoard Mini 核心板的应用.今天购买到的PyBoard到货了.对其进行初 ...

  9. MicroPython-TPYBoard开发板DIY小型家庭气象站

    2019独角兽企业重金招聘Python工程师标准>>> 对于喜欢登山的人来说,都会非常关心自己所处的高度跟温度,海拔高度的测量方法,海拔测量一般常用的有两种方式,一是通过GPS全球定 ...

  10. esp8266 micropython oled_micropython(4):使用ESP8266 控制 oled 屏幕,并显示 helloworld 字符...

    目录 前言 1,关于esp 8266 和 oled 2,使用lib库驱动 1306 4pin led 3,总结 前言 相关micropython 全部分类: https://blog.csdn.net ...

最新文章

  1. 第二章 实验设计的考虑因素
  2. 链接在HTML的英文,英文:A链接标记ie下会自动补全href_HTML/Xhtml_网页制作
  3. 开方根运算——没有FPU的解决办法
  4. 如何在Mac上直接删除文件而不将其发送到垃圾箱?
  5. 操作系统面试常问问题
  6. h3c交换机配置nat_史上最详细H3C路由器NAT典型配置案例
  7. Node 学习 | Day03 express (初识Express、Express 路由、Express 中间件、使用 Express 写接口)
  8. nomad 服务编排_Nomad微服务的容器模式
  9. 电脑分区不小心格式化了文件恢复教程
  10. 洛谷 P1606 [USACO07FEB]荷叶塘Lilypad Pond(spfa+最短路计数) 题解
  11. Reflect是什么?
  12. 大促系统全流量压测及稳定性保证——京东交易架构分享(含PPT)
  13. 福大软工1816 - 404 Note Found选题报告
  14. ssm众筹平台系统毕业设计(附源码、运行环境)
  15. 索爱有android手机吗,全球最小Android手机 索爱X10 Mini首测
  16. 把h264文件快速包装成mp4格式
  17. 计算机中的桌面是什么样的,从整理电脑桌面中学习如何分类
  18. python财务案例分析考试答案_《财务案例分析》作业及答案(三次)
  19. java中e的几次方_java怎么算e的几次方
  20. 结论太小,以致于大家都看不见它

热门文章

  1. 华为手机解锁码计算工具_华为解锁码-华为解锁助手(华为手机一键解锁工具)v1.0.0.0 快速版-东坡下载...
  2. 数学建模更新10(蒙特卡罗模拟)
  3. 华三OSPF多区域配置实例
  4. 前端实现拖动滑块完成验证
  5. Webpower揭晓2017最有效数字营销策略
  6. ACM题库,分类整理
  7. SPSS26中文免费版下载和安装教程
  8. 个人简历模板ppt大全
  9. php和tp中生成二维码电子名片
  10. 数据结构——线段树学习笔记