micropython lcd_micropython玩ESP8266(nodemcu)I2C连接1602液晶

这段代码实现了通过micropython和I2C接口,使用PCF8574扩展芯片连接ESP8266(nodemcu)到1602字符液晶显示器。初始化过程包括设置LCD功能、发送复位命令,并提供了写入命令和数据的方法。
摘要由CSDN通过智能技术生成

"""Implements a HD44780 character LCD connected via PCF8574 on I2C.

This was tested with: https://www.wemos.cc/product/d1-mini.html"""

from drivers import lcd_api

from machine import I2C

from time import sleep_ms

# The PCF8574 has a jumper selectable address: 0x20 - 0x27

DEFAULT_I2C_ADDR = 0x27

# Defines shifts or masks for the various LCD line attached to the PCF8574

MASK_RS = 0x01

MASK_RW = 0x02

MASK_E = 0x04

SHIFT_BACKLIGHT = 3

SHIFT_DATA = 4

class I2c_Lcd(lcd_api.Lcd_Api):

"""Implements a HD44780 character LCD connected via PCF8574 on I2C."""

def __init__(self, i2c, i2c_addr, num_lines, num_columns):

self.i2c = i2c

self.i2c_addr = i2c_addr

self.i2c.writeto(self.i2c_addr, bytearray([0]))

sleep_ms(20) # Allow LCD time to powerup

# Send reset 3 t

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值