使用树莓派控制4路继电器
2016-11-11 14:49
585 查看
IND1 不是接在17号GPIO口上,而是GPIO.0口上,即为11号口上才是对的,其它网上的教程这方面都未详细说明 ,我也不知道为什么:)
可能 GPIO默认out的是 GPIO.0 号口。
目前就这么多吧,接下来就是写自动化控制了。
加上简单控制 的python 代码
1:~~~~~~~~
1 #!/user/bin/python
2 # like this use: python gpiotest.py 1 or 0
3
4 import sys
5 import RPi.GPIO as GPIO
6 GPIO.setwarnings(False)
7 GPIO.setmode(GPIO.BCM)
8 args = sys.argv
9 pin = 17 # 这里的pin = 17 为 BCM 编码 的 17 ,树莓派的第11号口,wiringPi的0
10 ct1 = args[1]
11
12 if (int(ct1) == 1):
13 GPIO.setup(pin, GPIO.OUT)
14 GPIO.output(pin,GPIO.HIGH)
15
16 if (int(ct1) == 0):
17 GPIO.setup(pin, GPIO.OUT)
18 GPIO.output(pin,GPIO.LOW)
代码2: 控制4路
##################################################
# P17 ----> Relay_Ch1
# P18 ----> Relay_Ch2
# P27 ----> Relay_Ch3
# P22 ----> Relay_Ch4
##################################################
#!/usr/bin/python
# -*- coding:utf-8 -*-
import RPi.GPIO as GPIO
import time
Relay_Ch1 = 17
Relay_Ch2 = 18
Relay_Ch3 = 27
Relay_Ch4 = 22
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(Relay_Ch1,GPIO.OUT)
GPIO.setup(Relay_Ch2,GPIO.OUT)
GPIO.setup(Relay_Ch3,GPIO.OUT)
GPIO.setup(Relay_Ch4,GPIO.OUT)
print("Setup The Relay Module is [success]")
try:
while True:
#Control the Channel 1
GPIO.output(Relay_Ch1,GPIO.LOW)
print("Channel 1:The Common Contact is access to the Normal Open Contact!")
time.sleep(0.5)
GPIO.output(Relay_Ch1,GPIO.HIGH)
print("Channel 1:The Common Contact is access to the Normal Closed Contact!\n")
time.sleep(0.5)
#Control the Channel 2
GPIO.output(Relay_Ch2,GPIO.LOW)
print("Channel 2:The Common Contact is access to the Normal Open Contact!")
time.sleep(0.5)
GPIO.output(Relay_Ch2,GPIO.HIGH)
print("Channel 2:The Common Contact is access to the Normal Closed Contact!\n")
time.sleep(0.5)
#Control the Channel 3
GPIO.output(Relay_Ch3,GPIO.LOW)
print("Channel 3:The Common Contact is access to the Normal Open Contact!")
time.sleep(0.5)
GPIO.output(Relay_Ch3,GPIO.HIGH)
print("Channel 3:The Common Contact is access to the Normal Closed Contact!\n")
time.sleep(0.5)
#Control the Channel 4
GPIO.output(Relay_Ch4,GPIO.LOW)
print("Channel 4:The Common Contact is access to the Normal Open Contact!")
time.sleep(0.5)
GPIO.output(Relay_Ch4,GPIO.HIGH)
print("Channel 4:The Common Contact is access to the Normal Closed Contact!\n")
time.sleep(0.5)
except:
print("except")
GPIO.cleanup()
相关文章推荐
- 使用树莓派控制LED亮灯
- 树莓派2代通过人体红外感应器控制继电器
- 22、新手入手树莓派教程--控制继电器
- 使用树莓派红外控制空调和风扇
- 树莓派使用命令控制Led开关
- 树莓派3b使用一路继电器控制小风扇
- (14)树莓派B+使用L298N驱动控制四驱车并实现一个简单的web控制端
- 使用Python简单的实现树莓派的WEB控制
- 使用Python简单的实现树莓派的WEB控制
- 【开发日记】“门没关好”之树莓派安装摄像头以及使用Python控制摄像头
- Adafruit的树莓派教程第五课:使用控制电缆
- 使用WiringPi控制树莓派(初步解读开发文档)
- 4路RS485继电器模块 电脑控制开关 PC智能控制器 工控板
- 树莓派使用wiringPi控制LED灯
- 树莓派使用picamera控制摄像头
- 使用安卓手机控制树莓派
- 使用Python简单的实现树莓派的WEB控制
- 树莓派 继电器 实现led简单控制
- 树莓派使用python 控制G90舵机
- CZE-I4O4-V7.0智能数控继电器 4路串口继电器 4路电源开关控制 广告机控制器 CZE-O4-V7.0