pythonraspberry-pigpiogpiozero

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. 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.

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. 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".

terminal output of 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. I also tried using the terminal command to change the output of the pins from high to low but nothing happened. The GPIO pins appear to be stuck in this mode.

Is there any way to fix these stuck GPIO pins? And am I doing the right thing in this case?

Any assistance will be greatly appreciated!!


Solution

  • Your code sets up Motor A by

    motora = Motor(27, 22)
    

    But Motor B is set up by

    motorb = (5, 6).
    

    Shouldn't it be similarly set up by

    motorb = Motor(5, 6)?