注册
登录
电子工程世界-论坛
返回首页
EEWORLD首页
频道
EE大学堂
下载中心
Datasheet
专题
单片机
物联网
汽车电子
嵌入式
手机/便携
模拟电子
家用电子
网络通信
电源管理
工业控制
测试测量
半导体设计/制造
安防电子
传感器
医疗电子
hanyeguxingwo的个人空间
https://home.eeworld.com.cn/space-uid-288414.html
[收藏]
[复制]
[分享]
[RSS]
空间首页
动态
记录
日志
相册
主题
分享
留言板
个人资料
借用开发板
论坛
淘帖
Collection
查看新帖
最新回复
社区活动
联系管理员
我的空间
帖子
日志
收藏
好友
勋章
积分
安全验证
请完成以下验证码
日志
ESP-mp-01开发板SPI驱动OLED显示
已有 1002 次阅读
2016-12-14 10:54
|
个人分类:
MicroPython
昨天使用ESP-mp-01开发板的I2C成功驱动OLED显示,今天测试了SPI方式,同样成功点亮OLED。
【1】硬件连接:
ESP8266 SPI对应的引脚为Pin(14)--SCK,Pin(13)--MOSI,Pin(12)--MISO,Pin(16)--CS:
【2】程序源码:
# main.py -- put your code here!
import machine
from machine import Pin,I2C,SPI
import ssd1306
import math
import time
# construct an I2C bus
#i2c = I2C(scl=Pin(14), sda=Pin(2), freq=100000)
#display = ssd1306.SSD1306_I2C(128,64, i2c)
# construct an SPI bus on the given pins
# polarity is the idle state of SCK
# phase=0 means sample on the first edge of SCK, phase=1 means the second
spi = SPI(baudrate=10000000, polarity=1, phase=0, sck=Pin(14,Pin.OUT), mosi=Pin(13,Pin.OUT), miso=Pin(12))
display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(5),Pin(4), Pin(16))
led_blue = machine.Pin(2, Pin.OUT) # 设置 GPIO2 为输出
led_blue.high()
try:
display.poweron()
display.init_display()
display.text('ESP-mp SPI OLED',1,1)
display.text('Hi, MicroPython!',1,16)
display.text('By: hbzjt2012',1,31)
# Write display buffer
display.show()
time.sleep(3)
display.fill(0)
for x in range(0, 128):
display.pixel(x, 32+int(math.sin(x/64*math.pi)*7 + 8), 1)
display.show()
time.sleep(3)
display.fill(0)
x = 0
y = 0
direction_x = True
direction_y = True
while True:
# Clear the previous lines
prev_x = x
prev_y = y
# Move bars
x += (1 if direction_x else -1)
y += (1 if direction_y else -1)
# Bounce back, if required
if x == 128:
direction_x = False
x = 126
elif x == -1:
direction_x = True
x = 1
if y == 64:
direction_y = False
y = 63
elif y == -1:
direction_y = True
y = 1
# Draw new lines
for i in range(64):
display.pixel(prev_x, i, False)
display.pixel(x, i, True)
for i in range(128):
display.pixel(i, prev_y, False)
display.pixel(i, y, True)
# Make sure the corners are active
display.pixel(0, 0, True)
display.pixel(127, 0, True)
display.pixel(0, 63, True)
display.pixel(127, 63, True)
# Write display buffer
display.show()
except Exception as ex:
led_blue.low()
print('Unexpected error: {0}'.format(ex))
display.poweroff()
复制代码
【3】效果演示:
本文来自论坛,点击查看完整帖子内容。
收藏
邀请
举报
全部
作者的其他最新日志
•
1、初探SensorTile和BlueMS体验
•
STM32F769I-DISCO开发板CoreMark跑分与固件恢复
•
在STM32F769DICSCO上体验MicroPython
•
ESP-mp-01开发板I2C驱动OLED显示
•
PYB Nano驱动8*8LED点阵心形显示
评论 (
0
个评论)
涂鸦板
您需要登录后才可以评论
登录
|
注册
评论
hanyeguxingwo
加为好友
给我留言
打个招呼
发送消息
热门文章
头条资讯
印度iPhone工厂一夜被盗2万部;谷歌回应全球大规模宕机:磁盘满了;特斯拉市值一夜暴增1850亿,销量不到全球1%|雷锋早报
涨价
5G是如何覆盖地铁的?
5G进入爬坡期,这个关键因素,决定了它的成败……
供应链紧张下,NI与益莱储带给您的新选择
【世说芯品】PCB面积总是不够用?试试这个方案呗~
新增数据手册
FFC-18T6BSM11N
755MM-MA-75-A-FC-51-EU
SON-N987LF-07-3120-D
GP6548-2773-BT50Q
P8SG-053R6Z
RKC12CLSTB2201F
热搜器件
SL110
SLW-108-01-T-D
BU4226FVE-TR
RN65C1581FRE6
C48-16R18-11S6-406
193-015-213R561
推荐下载
Vxworks 5.5 操作系统库函数手册(英文版)
学习开发板原理图
凯撒窗的设计
联想B460 BIOS
可编程逻辑器件及EDA技术(东北大学出版杜+2000)
适用于开关电源测试的电磁兼容标准详细
推荐关注
先导式隔膜电磁阀常开与常闭状态下的原理模式
先导式膜片电磁阀如何工作,先导式电磁阀的结构性能原理?
导致阀门颤振是控制阀方向安装不正确的关系吗?-藤仓自动化
数字电磁阀门定位器的使用优势与传统的模拟板不同
MuJoCo 提高机械臂笛卡尔空间IK+路径规划+轨迹优化的成功率及效率
LTspice 电路导入QSPICE的方法