【发布时间】:2016-11-28 21:48:52
【问题描述】:
我有一个连接到 SainSmart 16 通道机械继电器的 Raspberry Pi 3 Model B。我有一个 python 脚本来改变继电器的状态,虽然程序中的状态会随着不同的 GPIO 通道而改变,但机械继电器永远不会改变状态。
有人有什么想法吗?
我的 Python 脚本
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
sleepTime = 0.5
pinList = [4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26, 21, 20, 16, 12]
for i in pinList:
GPIO.setup(i, GPIO.OUT)
for i in pinList:
time.sleep(sleepTime);
GPIO.output(i, GPIO.HIGH)
print (str(i) + " high")
print ("state: " + str(GPIO.input(i)))
for i in pinList:
time.sleep(sleepTime);
GPIO.output(i, GPIO.LOW)
print(str(i) + " low")
print ("state: " + str(GPIO.input(i)))
GPIO.cleanup()
脚本的输出
4 high
state: 1
17 high
state: 1
27 high
state: 1
22 high
state: 1
10 high
state: 1
9 high
state: 1
11 high
state: 1
5 high
state: 1
6 high
state: 1
13 high
state: 1
19 high
state: 1
26 high
state: 1
21 high
state: 1
20 high
state: 1
16 high
state: 1
12 high
state: 1
4 low
state: 0
17 low
state: 0
27 low
state: 0
22 low
state: 0
10 low
state: 0
9 low
state: 0
11 low
state: 0
5 low
state: 0
6 low
state: 0
13 low
state: 0
19 low
state: 0
26 low
state: 0
21 low
state: 0
20 low
state: 0
16 low
state: 0
12 low
state: 0
感谢阅读。
【问题讨论】:
-
你的继电器的电气特性是什么?
-
使用晶体管激活继电器
-
这是中继:sainsmart.com/…
-
使用我的解决方案,将 12Vdc 更改为 5Vdc(电池)
标签: python raspberry-pi