Skip to main content

PCF8574驱动设置引脚模式,读写数字信号3.3v

项目描述

PCF8574 8bit IO扩展板的Python驱动

为树莓派开发,需要 python-smbus2 包来访问 I2C 总线。

在带有两个 PCF8574 板的树莓派 3b plus 上进行了测试。

首先使用以下命令安装 smbus2: pip3 install smbus2

然后使用以下命令安装实际软件包: pip3 install pcf8574-io

使用示例:

import pcf8574_io

# You can use up to 8 PCF8574 boards
# the board will start in input mode
# the pins are HIGH in input mode
p1 = pcf8574_io.PCF(0x20)

# You can use multiple boards with different addresses
#p2 = pcf8574_io.PCF(0x21)

# p0 to p7 are the pins name
# INPUT or OUTPUT is the mode
p1.pin_mode("p0", "INPUT")
print(p1.read("p0"))

# You can write and read the output pins
# use HIGH or LOW to set the pin, HIGH is +3.3v LOW is 0v
p1.pin_mode("p7", "OUTPUT")
p1.write("p7", "LOW")
print(p1.read("p7"))

# Additional you can do the following
p1.set_i2cBus(1)
p1.get_i2cBus()
print(p1.get_pin_mode("p7")) # returns string OUTPUT, INPUT
print(p1.is_pin_output("p7")) # returns boolean True, False
print(p1.get_all_mode()) # returns list of all pins ["OUTPUT","INPUT",...etc]

注意:板子只有 25mA 的输出电流,所以如果你想控制一些需要超过 25mA 的继电器模块,使用多个引脚来控制每个继电器。

使用过的板子: 替代文字

#链接 https://pypi.org/project/pcf8574-io/

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pcf8574_io-0.1.1.tar.gz (3.7 kB 查看哈希

已上传 source

内置分布

pcf8574_io-0.1.1-py3-none-any.whl (4.2 kB 查看哈希

已上传 py3