简体   繁体   English

Raspberry pi gpio引脚卡在“ in”和“ high”模式下

[英]Raspberry pi gpio pins are stuck in the “in” and “high” mode

I am running Raspbian Stretch on a Raspberry Pi 2. I was trying to build a basic obstacle avoidance rover and ran into a problem with the motors. 我在Raspberry Pi 2上运行Raspbian Stretch。我试图构建一个基本的避障漫游车,但遇到了电动机问题。 Schematic found here: 原理图在这里找到:

I don't have the dc-dc converter and I have a LED with a 330 ohm resistor connected to pin 17. 我没有DC-DC转换器,而LED上有一个330欧姆电阻连接到引脚17。

I was using this code to run it: 我正在使用以下代码运行它:

from gpiozero import LED
from gpiozero import Motor
import RPi.GPIO as GPIO
from time import sleep

# prereqs
GPIO.setmode(GPIO.BCM)
Motorbin = 5
Motorbout = 6
GPIO.setup(Motor2in,GPIO.OUT)
GPIO.setup(Motor2out,GPIO.OUT)

led = LED(17)

for i in range(2):
    led.on()
    sleep(0.5)
    led.off()
    sleep(0.5)



# motors are going to start running now

motora = Motor(27, 22)
motora.forward()
sleep(5)
motora.backward()
sleep(5)
motora.stop()

for i in range(2):
    led.on()
    sleep(0.5)
    led.off()
    sleep(0.5)

motorb = (5, 6)
motorb.forward()
sleep(5)
motorb.backward()
sleep(5)
motorb.stop()

GPIO.cleanup

I ran the code and my LED blinked twice, the first motor (motora) moved forward and backward, but the second motor (motorb) did not move at all. 我运行了代码,我的LED闪烁了两次,第一个马达(马达)向前和向后移动,但是第二个马达(马达)完全没有移动。 I ran the terminal command "gpio readall" and found that the pins that my second motor are running on (BCM 5, 6) were set to "IN" and both were set to "1". 我运行了终端命令“ gpio readall”,发现第二个电动机正在运行的引脚(BCM 5、6)被设置为“ IN”,并且都被设置为“ 1”。

terminal output of gpio readall gpio readall的终端输出

I tried using the GPIO.setup command to change pin 5 and 6 to an output pin but it still stayed the same. 我尝试使用GPIO.setup命令将引脚5和6更改为输出引脚,但仍然保持不变。 I also tried using the terminal command to change the output of the pins from high to low but nothing happened. 我还尝试使用terminal命令将引脚的输出从高电平更改为低电平,但没有任何反应。 The GPIO pins appear to be stuck in this mode. GPIO引脚似乎卡在此模式下。

Is there any way to fix these stuck GPIO pins? 有什么办法可以解决这些卡住的GPIO引脚吗? And am I doing the right thing in this case? 在这种情况下,我做对了吗?

Any assistance will be greatly appreciated!! 任何协助将不胜感激!

Your code sets up Motor A by 您的代码通过以下方式设置了Motor A

motora = Motor(27, 22)

But Motor B is set up by 但是马达B是由

motorb = (5, 6).

Shouldn't it be similarly set up by 它是否应该由

motorb = Motor(5, 6)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM