采用microbit控制1602LCD,但是没有输出,请各位大佬帮忙检查一下错误
from microbit import *
LCD_I2C_ADDR = 39
class LCD1620():
def __init__(self):
self.buf = bytearray(1)
self.BK = 0x08
self.RS = 0x00
self.E = 0x04
self.setcmd(0x33)
sleep(5)
self.send(0x30)
sleep(5)
self.send(0x20)
sleep(5)
self.setcmd(0x28)
self.setcmd(0x0C)
self.setcmd(0x06)
self.setcmd(0x01)
self.version = '1.0'
def setReg(self, dat):
self.buf[0] = dat
i2c.write(LCD_I2C_ADDR, self.buf)
sleep(1)
def send(self, dat):
d = dat & 0xF0
d |= self.BK
d |= self.RS
self.setReg(d)
self.setReg(d | 0x04)
self.setReg(d)
def setcmd(self, cmd):
self.RS = 0
self.send(cmd)
self.send(cmd << 4)
def setdat(self, dat):
self.RS = 1
self.send(dat)
self.send(dat << 4)
def clear(self):
self.setcmd(1)
def backlight(self, on):
if on:
self.BK = 0x08
else:
self.BK = 0
self.setdat(0)
def on(self):
self.setcmd(0x0C)
def off(self):
self.setcmd(0x08)
def char(self, ch, x=-1, y=0):
if x >= 0:
a = 0x80
if y > 0:
a = 0xC0
a += x
self.setcmd(a)
self.setdat(ch)
def puts(self, s, x=0, y=0):
if len(s) > 0:
self.char(ord(s[0]), x, y)
for i in range(1, len(s)):
self.char(ord(s))
i = LCD1620()
i.puts("Hello microbit!")
求助:microbit控制1602LCD液晶显示屏
- shaoziyang
- 帖子: 3956
- 注册时间: 2019年 10月 21日 13:48
Re: 求助:microbit控制1602LCD液晶显示屏
另外看你的接线,LCD和microbit的地线没有连起来。
以及液晶是多少电压供电的?
以及液晶是多少电压供电的?
Re: 求助:microbit控制1602LCD液晶显示屏
打开REPL是这个
crobit
>>> microbit.reset()
Traceback (most recent call last):
File "__main__", line 76, in <module>
File "__main__", line 11, in __init__
File "__main__", line 38, in setcmd
File "__main__", line 32, in send
File "__main__", line 25, in setReg
OSError: I2C write error -1010
crobit
>>> microbit.reset()
Traceback (most recent call last):
File "__main__", line 76, in <module>
File "__main__", line 11, in __init__
File "__main__", line 38, in setcmd
File "__main__", line 32, in send
File "__main__", line 25, in setReg
OSError: I2C write error -1010
Re: 求助:microbit控制1602LCD液晶显示屏
液晶是5V的,我将液晶的VCC和GND与电池的正负极连在一起了
- shaoziyang
- 帖子: 3956
- 注册时间: 2019年 10月 21日 13:48
Re: 求助:microbit控制1602LCD液晶显示屏
但是microbit的地没有和液晶连接,这样信号是不通的
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 7回复总数
- 1230 阅读次数
- 最新文章 由 zwjiang
2021年 10月 9日 09:17
-
- 1回复总数
- 933 阅读次数
- 最新文章 由 shaoziyang
2021年 10月 9日 12:51
-
- 7回复总数
- 1314 阅读次数
- 最新文章 由 zwjiang
2021年 10月 10日 10:30