继上一帖给esp32刷入micropython之后,忍不住给以esp12e也刷了micropython

这里先说一下webrepl:

通过wifi可以和esp8266交互,以及便携的传输文件

首次使用:

1 import webrepl
2 webrepl.start()

中间可能让你import 一个配置模块来设置密码具体即执行上两句就知道了.

WebREPL - a prompt over WiFi
WebREPL allows you to use the Python prompt over WiFi, connecting through a browser. The latest versions of Firefox and Chrome are supported.For your convenience, WebREPL client is hosted at http://micropython.org/webrepl . Alternatively, you can install it locally from the the GitHub repository https://github.com/micropython/webrepl .Before connecting to WebREPL, you should set a password and enable it via a normal serial connection. Initial versions of MicroPython for ESP8266 came with WebREPL automatically enabled on the boot and with the ability to set a password via WiFi on the first connection, but as WebREPL was becoming more widely known and popular, the initial setup has switched to a wired connection for improved security:import webrepl_setup
Follow the on-screen instructions and prompts. To make any changes active, you will need to reboot your device.To use WebREPL connect your computer to the ESP8266’s access point (MicroPython-xxxxxx, see the previous section about this). If you have already reconfigured your ESP8266 to connect to a router then you can skip this part.Once you are on the same network as the ESP8266 you click the “Connect” button (if you are connecting via a router then you may need to change the IP address, by default the IP address is correct when connected to the ESP8266’s access point). If the connection succeeds then you should see a password prompt.Once you type the password configured at the setup step above, press Enter once more and you should get a prompt looking like >>>. You can now start typing Python commands!

以上参见micropython docs

初次设置好会提示重启,然后电脑就可以通过serial或者浏览器http://micropython.org/webrepl/和micropython交互了,贴张图:

先通过repl交互,如果之前设置好网络的话,esp8266开机之后会自动连接,这一点很方便,

这里通过可以通过.ifconfig()查看IP或者进入路由器后台查看也行,然后把地址填入webrepl点击连接,输入密码即可.

可以看到两侧的信息交互是同步的,在一端输入另一端自动跟随.右侧可以上传或者下载文件.


现在进入正题,micropython实现了spi iic等接口,还写了ssd1306,但是看过我之前的博文可以知道,我自己做过1.3寸oled的转接板,这用的是sh1106.

然后查了查好像micropython还没有实现,可能没工夫管这么小的地方吧,毕竟.96的ssd1306广为人知.

然后之前自己也改过ssh1306的程序,就是有偏移而已,正寻思着要不要自己改改用?百度了一下,国内好像没有,打梯子google一下,发现页首两个好像靠谱:

贴上地址吧:

https://github.com/robert-hh/SH1106 这个项目里面好像说是基于别人的,然后由于看到另一个更为直观

https://blog.boochow.com/article/453949310.html这个是个日本佬的博客,直接放出代码,我采用了这个,效果不错!

当然啦,它用的SPI那会的和现在的有点区别可能,根据traceback删掉第一个参数(你进这个地址去看,和我下面贴的程序就知道哪个参数了,就是哪个1),之后ctrl e进去 ctrl d屏幕竟然就直接点亮了,(当然这里还稍微改了改pin)

贴上我的代码:

from micropython import const
from ssd1306 import SSD1306_SPISET_LOW_COLUMN      = const(0x00)
SET_HIGH_COLUMN     = const(0x10)
SET_PAGE_ADDR       = const(0xb0)
SET_DISP_START_LINE = const(0x40)class SH1106_SPI(SSD1306_SPI):def show(self):for pg in range(0, self.pages):for cmd in (SET_PAGE_ADDR | pg,SET_LOW_COLUMN | 2,SET_HIGH_COLUMN | 0,):self.write_cmd(cmd)self.write_data(self.buffer[pg * 0x80:(pg + 1) * 0x80])#sh1106_spi.pyfrom sh1106 import SH1106_SPI
from machine import Pin, SPI
spi = SPI(baudrate=8000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
oled = SH1106_SPI(128, 64, spi, dc=Pin(16), res=Pin(15), cs=Pin(5))
oled.line(0,0,128,64,1);oled.show()
oled.line(128,0,0,64,1);oled.show()
oled.text('SH1106',36,0);oled.show()
oled.text('Micropython',24,56);oled.show()

注释之前的保存为sh1106.py 然后上传到esp,然后下面的直接ctrl e,效果很好!

这里可以体现出前人栽树后人乘凉的好处了,也意识到梯子很有用.

这里这块板子直接用esp12e,左侧两个按键,一个复位一个io0,背面飞线接spi,就不贴图了,

我给出引脚定义:

GND VCC D0 D1 RES DC CS(我做的板子cs直接接地了)

D0接sck D1接mosi res接的io15 dc接的io16 至于程序里面dc我分配了引脚,是因为现在还没搞清楚怎样丢给它一个None,我直接赋值None不行,直接丢个空的io给它吧,之后再研究...

本来是想做个时钟,数码管io占用太多,然后想到了oled,我有两种.66和1.3,.66的太小了,也想过两块拼一起,emmm太麻烦了.

先进行到这一步吧!

ADDED:

对上面括号参数的附加解释:(仅仅是那个1)

上地址:

这是github ss1306.py

这是docs spi

class machine.SPI(id, ...)
Construct an SPI object on the given bus, id. Values of id depend on a particular port and its hardware. Values 0, 1, etc. are commonly used to select hardware SPI block #0, #1, etc. Value -1 can be used for bitbanging (software) implementation of SPI (if supported by a port).

SPI.init(baudrate=1000000, *, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=None, mosi=None, miso=None, pins=(SCK, MOSI, MISO))
Initialise the SPI bus with the given parameters:baudrate is the SCK clock rate.
polarity can be 0 or 1, and is the level the idle clock line sits at.
phase can be 0 or 1 to sample data on the first or second clock edge respectively.
bits is the width in bits of each transfer. Only 8 is guaranteed to be supported by all hardware.
firstbit can be SPI.MSB or SPI.LSB.
sck, mosi, miso are pins (machine.Pin) objects to use for bus signals. For most hardware SPI blocks (as selected by id parameter to the constructor), pins are fixed and cannot be changed. In some cases, hardware blocks allow 2-3 alternative pin sets for a hardware SPI block. Arbitrary pin assignments are possible only for a bitbanging SPI driver (id = -1).
pins - WiPy port doesn’t sck, mosi, miso arguments, and instead allows to specify them as a tuple of pins parameter.

也就是说,在SPI的构造里面如果给定了id那么后面的sck ,mosi, miso就不需要指定啦,反之如果没有指定id就需要了.

像这样:

1 from sh1106 import SH1106_SPI
2 from machine import Pin, SPI
3 #spi = SPI(baudrate=8000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
4 spi = SPI(1,baudrate=8000000, polarity=0, phase=0)
5 oled = SH1106_SPI(128, 64, spi, dc=Pin(16), res=Pin(15), cs=Pin(5))
6 oled.line(0,0,128,64,1);oled.show()
7 oled.line(128,0,0,64,1);oled.show()
8 oled.text('SH1106',36,0);oled.show()
9 oled.text('Micropython',24,56);oled.show()

至于cs引脚,

class 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 = csimport timeself.res(1)time.sleep_ms(1)self.res(0)time.sleep_ms(10)self.res(1)super().__init__(width, height, external_vcc)

可以看到cs被传入构造,作为时序中的一个动作,不能省略啊!暂时就赋值给不用的io吧

转载于:https://www.cnblogs.com/katachi/p/9629565.html

micropython驱动sh1106点亮oled相关推荐

  1. STM32F1基于正点原子HAL库IIC驱动SH1106芯片的OLED屏

    1.oled.c代码 #include "oled.h" #include "stdlib.h" #include "oledfont.h" ...

  2. STC89C52驱动SH1106芯片点亮OLED问题点总结

    主芯片:STC89C52 OLED驱动芯片:SH1106 OLED屏大小为1.3寸,像素点是128X64(8页X8),通信方式有IIC和SPI两种方式. 烧录软件:STC-ISP 文字图片取模软件:P ...

  3. 基于Stm32f103软件iic利用SH1106驱动0.96寸OLED

    第一次尝试写OLED的驱动,并自己利用取模软件造了基本的字库,再根据字库写了不同的显示函数. 打开OLED屏的数据手册我们可以看到一个完整的驱动流程 接下来我们只需要根据流程发送这些指令就可以点亮OL ...

  4. STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示

    STM32F103C8T6在Arduino框架下驱动SH1106 1.3" IIC OLED显示 效果展示: 相关篇<STM32duino开发的底层驱动程序-bootloader> ...

  5. ESP32驱动 1.3寸OLED SH1106芯片)

    使用U8g2lib库驱动 1.3寸OLED 驱动IC:SH1106 分辨率:128*64 支持电压3.3V/5.0V #include <Arduino.h> #include <U ...

  6. SWM181 驱动SH1106 1.3寸 OLED屏幕显示

    SWM181 驱动SH1106 1.3寸 OLED屏幕显示 ✨实测驱动的屏幕为sh1106,该工程源码不适合通过修改相关的偏移地址来适配ssd1306 I2C 0.96寸屏幕显示,实际修改后,经测试并 ...

  7. esp32使用MicroPython驱动oled屏显示中文和英文

    文章目录 esp32使用MicroPython驱动oled屏显示中文和英文 介绍 安装 特点 开源 硬件连接 API 示例 显示英文字符 显示汉字 参考链接 esp32使用MicroPython驱动o ...

  8. ESP8266如何使用u8g2(I2C)驱动SH1106的OLED

    u8g2是一款单色图形库,非常适合12864之类的显示屏,基本上支持了市面上的主流显示控制器.可是偏偏对SH1106不是那么友好,使用起来不是很方便.打开IDE的示例程序可以看到对SH1106列出来的 ...

  9. STM32(基于HAL库)驱动0.96寸OLED屏幕(六脚)

    STM32驱动0.96寸OLED屏幕(六脚) 1 序言 2 如何利用STM32单片机驱动12864液晶屏 2.1*基本配置* 2.2 *0.96寸OLED端口含义* 2.3 *0.96寸OLED液晶屏 ...

最新文章

  1. 一点通路由器模拟软件最新版_2019年高压电工作业考试最新版题库及答案(全部判断题)...
  2. MyEclipse8.x下安装freemarker ide插件
  3. c++迭代器的一个例子
  4. ibm db2获取目标时间与当前时间的差值_【学术论文】高帧频视觉实时目标检测系统...
  5. 测试用例编写(功能测试框架)
  6. 计算机基础知识必刷,《2019年江苏专转本考试-计算机基础必刷题题库(第四章)》...
  7. 微信小程序 地图实现查找标记地点
  8. bootice添加linux_用BOOTICE工具在U盘上实现SYSLINUX与GRUB4DOS双启动 - 图文
  9. ttest函数使用方法_TTEST 函数 - EXCEL 2010 中文帮助文档
  10. Java实现微信统一服务消息
  11. java调用python实现校验一串字符串是否为单词
  12. Android 如何屏蔽返回键和Home键
  13. css3 实现十字光标和光标外圆圈环绕
  14. 【平衡小车制作】(七)串级PID调参及平衡成果展示(超详解)
  15. 看上去很美--次世代游戏平台XBOX360测评
  16. android studio manifest merger failed,【Androidstudio】Manifest merger failed 问题
  17. 批处理和流处理如何区分? 有边界数据和无边界数据如何区分?
  18. python assertionerror是什么异常_Python 断言和异常
  19. QT/C++从新手到老手系列之QT基础篇-李浩林-专题视频课程
  20. gson线上环境解析日期时报错JsonSyntaxException

热门文章

  1. 关于Excel表操作-通过Fuzzywuzzy实现模糊匹配
  2. C++数字三角形问题
  3. Linux系统下,智能中文车牌识别系统EasyPR的配置
  4. js java cookie_JS设置cookie、读取cookie、删除cookie
  5. 万字长文解读:从Transformer到ChatGPT,通用人工智能曙光初现
  6. (Java)word转pdf(aspose),pdf加水印(itextpdf),并支持POI模板(包括checkbox)导出
  7. 极限题型二:求数列极限常见题型
  8. python中的pylab_在Python2.7中,在函数级导入pylab的首选方法是什么?
  9. 2019,篮球明星科比进军区块链?
  10. QT进行http请求(post/get)