使用树莓派控制4路继电器
来源:互联网 发布:淘宝退货率计算公式 编辑:程序博客网 时间:2024/06/08 16:24
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()
# 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()
0 0
- 使用树莓派控制4路继电器
- 树莓派控制继电器开关
- 树莓派3b使用一路继电器控制小风扇
- 树莓派GPIO远程控制继电器
- 继电器控制
- 【esp8266】Soc方式使用esp8266控制继电器
- 树莓派 继电器 实现led简单控制
- 51单片机(AT89C52)控制双路继电器
- RS232串口控制继电器板(独立控制16路)
- 4路RS485继电器模块 电脑控制开关 PC智能控制器 工控板
- 单片机控制继电器
- 单片机控制继电器电路
- 直流继电器控制交流电
- 单片机控制继电器
- 单片机控制继电器实验
- Arduino 控制四路继电器
- 单片机控制继电器电路
- AVR控制继电器
- discuz主题列表页伪静态化设置方法(lnmp+wamp+lamp通用)
- 完美解决thinkphp验证码出错无法显示的方法
- mark-----调屏大师介绍
- 产品经理新手如何写体验报告?
- 配置ubuntu虚拟机上的caffe和Theano
- 使用树莓派控制4路继电器
- CALayer实现,界限、透明度、位置、旋转、缩放组合动画
- 一分钟读懂互联网广告竞价策略GFP+GSP+VCG
- Android 调试LCM小技巧
- Qt控件简单介绍
- 页面从输入 URL 到页面加载显示完成的过程
- linux 防火墙添加端口
- C# 用正则表达式实现金额转中文大写
- 01-复杂度2 Maximum Subsequence Sum (25分)