likehc

 

 

 

 

 具体 接线 如下图所示

 

 

 

 

 

查看  gpio如果 无此命令,可以安装 wiringpi.

root@raspberrypi:/setup# gpio redall

-bash: gpio: command not found 

 

apt install wiringpi 

root@raspberrypi:/setup# gpio readall 

 

 

 

 

如上面图片所示,把 引脚40 的BCM为21

gpio readall  #列出所有针角

gpio mode 29 out  #设置[以writePi编号为29]的GPIO(即GPIO29口) 口为输出模式

gpio read 29  #获取当前GPIO29口的电平(0或1)

gpio write 29 1   #设置当前GPIO29口的电平为1(1为高电平电源开启,)

gpio write 29 0   #设置当前GPIO29口的电平为0(0为低电平电源关闭)

 

python3 脚本 ,5秒开,5秒关

----------------------------

#!/usr/bin/python

#encoding:utf-8

 

import RPi.GPIO

import time

 

time_out = 5

RELAY = 21

 

RPi.GPIO.setmode(RPi.GPIO.BCM)

RPi.GPIO.setup(RELAY,RPi.GPIO.OUT)

 

try:

   while True:

     RPi.GPIO.output(RELAY,RPi.GPIO.HIGH)

     time.sleep(time_out)

     RPi.GPIO.output(RELAY,RPi.GPIO.LOW)

     time.sleep(time_out)

    

except KeyboardInterrupt:

   pass

RPi.GPIO.cleanup()

 

----------------------------

 

 

 

分类:

技术点:

相关文章:

  • 2022-01-10
  • 2022-02-15
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-12-05
  • 2021-07-02
  • 2021-12-05
猜你喜欢
  • 2021-07-13
  • 2021-05-30
  • 2021-06-08
  • 2021-09-18
相关资源
相似解决方案