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 的继电器模块,使用多个引脚来控制每个继电器。
使用过的板子:
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
pcf8574_io-0.1.1.tar.gz
(3.7 kB
查看哈希)
内置分布
pcf8574_io-0.1.1-py3-none-any.whl
(4.2 kB
查看哈希)
关
pcf8574_io -0.1.1.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | cc6f88b2deaa589a28a3748b6b2ca4212d0707d67685f9a0ed4221037e9c9fe9 |
|
| MD5 | d1f5afe039a4696f2147d113d4064b49 |
|
| 布莱克2-256 | 35267a0b7fd47a46b03cfc9d419bf7be8d50dcf7b0f2f46a0d0231826d63c4b4 |
关
pcf8574_io -0.1.1-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 117126d8671fad811259d2d53211c8e2bae612254996e8acc7c8ffae5d040311 |
|
| MD5 | 2b2f7ea85d688a2cbdd352ada7c9e141 |
|
| 布莱克2-256 | ee1158b2c5d2ba38aa713c4294dc62aaab7795fa6eb7f1b45f29c8a5201ea357 |