我有一个Raspberry Pi 3 Model B连接到SainSmart 16通道机械继电器。我有一个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
感谢阅读。