如何使用PCF8574 i2clcd44780背包与adafruit_LCD python代码作为树莓pi上的gpio扩展器

2024-04-27 17:10:30 发布

您现在位置:Python中文网/ 问答频道 /正文

adafruit库在RPI-GPIO或MCP230XX i2C-GPIO扩展器上使用python提供LCD控制。我想对PCF8574使用相同的想法。 都是关于这些事情的: http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html

我用于LCD的Adafruit库是这样的: https://github.com/adafruit/Adafruit_Python_CharLCD

在Adafruit中,GPIO还包含一个PCF8574 i2C GPIO扩展器的库。 https://github.com/adafruit/Adafruit_Python_GPIO

在示例中,只使用了MCP230XX,而没有使用PCF8574。在

经过几个小时的尝试,我无法让它与adafruit代码正常工作。在

请注意,我找到了一个工作代码,但是为了更好的维护和支持,我想使用adafruit代码。 工作代码如下: https://github.com/goshkis/rpi/blob/master/lcddriver.py

以下是我当前的代码:

#!/usr/bin/env python

import time
import Adafruit_CharLCD as LCD
import Adafruit_GPIO.PCF8574 as PCF

# Define PCF pins connected to the LCD.
PCF8574T_addr = 0x27
lcd_rs        = 0
lcd_rw        = 1
lcd_en        = 2
lcd_d4        = 4
lcd_d5        = 5
lcd_d6        = 6
lcd_d7        = 7
lcd_backlight = 3

# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows    = 2

# Initialize i2C device using its I2C address.
gpio = PCF.PCF8574(PCF8574T_addr, busnum=1)

# Initialize the LCD
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
                           lcd_columns, lcd_rows, lcd_backlight, gpio=gpio)

# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.set_backlight(True)
lcd.message("Gartenwasser startet...")
time.sleep(1)

你能找出我犯的那个错误吗?在


Tags: 代码httpsimportgithubadafruitcomgpiolcd