为true时的GPIO控制:

2024-07-08 07:27:21 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,伙计们,我一直都在失败:

photo_booth.py:18: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(RELAI, GPIO.OUT)

我也尝试用GPIO 18控制al继电器,但它根本不工作。 我和其他人试过了,但没什么变化。继电器一直开着,它不会随着命令关闭。我的问题是什么?在

你能告诉我这个问题吗?在

#!/usr/bin/python

import RPi.GPIO as GPIO, time, os, subprocess, signal

# GPIO setup

GPIO.setmode(GPIO.BCM)

SWITCH = 24
GPIO.setup(SWITCH, GPIO.IN)
RESET = 25
GPIO.setup(RESET, GPIO.IN)
RELAI = 19
GPIO.setup(RELAI, GPIO.OUT)
GPIO.output(RELAI, GPIO.LOW)
j = 0
k = 0

def entprellen(schalter):
    entprellungs_puffer = 0
    schalter_puffer = 0
    for i in range(1, 11):
        entprellungs_puffer = entprellungs_puffer +1
        schalter_puffer = schalter_puffer + schalter
        time.sleep(0.05)
        if entprellungs_puffer == schalter_puffer:
            print("entprellt")
            return 1
        else:
            return 0

while True:
    if(GPIO.input(SWITCH)):
        j = entprellen(GPIO.input(SWITCH))

        if (j):
            GPIO.output(RELAI,GPIO.LOW)
            time.sleep(0.5)
            print("pose!")
            print("SNAP")
            gpout = subprocess.check_output("gphoto2 --capture-image-and-download --filename /home/pi/photobooth_images/photobooth%H%M%S.jpg", stderr=subprocess.STDOUT, shell=True)
            print(gpout)
            print("please wait while your photos print...")

            subprocess.call("sudo /home/pi/scripts/photobooth/assemble_and_print", shell=True)

            time.sleep(10)
            print("ready for next round")
            GPIO.output(RELAI,GPIO.HIGH)
GPIO.cleanup()

Tags: intrueoutputgpioiftimesetupsleep
1条回答
网友
1楼 · 发布于 2024-07-08 07:27:21

谢谢@stevieb和johnny Mopp 是的,我了解BCM主板模式之间的差异。事实上是有可能逃跑的。 问题是:我像这里一样连接它https://www.youtube.com/watch?v=TVR2SCMN8xY,但它没有工作。然后我试着把pi上的5伏换成3.3伏,结果成功了。问题是继电器开关不正常。我对接力有很多不同的想法。所以我真的不知道该怎么办。我现在有两个继电器:

这是第一个: https://www.amazon.de/gp/product/B01G1ENSTS/ref=ppx_yo_dt_b_asin_title_o03__o00_s00?ie=UTF8&psc=1

几乎相同但不同的品牌: https://www.amazon.de/gp/product/B00UFW1YNK/ref=ppx_yo_dt_b_asin_title_o01__o00_s00?ie=UTF8&psc=1 我希望第二个更好,因为它和教程中显示的一样。但没有改变。 现在我买了这个: https://www.ebay.de/itm/252993630298 它有一个引脚直接向线圈提供5V电压,3.3用于开关。在

你认为它会管用吗?或者你有其他的想法????在

谢谢你的帮助!在

相关问题 更多 >

    热门问题