I bought two DROK L298 H-Bridges to control my DC motor (one for backup). I've connected it up to my Raspberry Pi 3 with BCM 12 as my PWM and 16 and 19 as my IN1 and IN2. Below is my code to test if the motor works - but it doesn't turn.
I tested the code on an L293D chip which turns the motor and tested both L298 H-bridges with no success. Looking for thoughts on how to get the motor working on the L298 H-bridge.
import RPi.GPIO as GPIO
import time
MotorPin1 = 16 # pin36
MotorPin2 = 19 # pin35
MotorEnable = 12 # pin32
GPIO.setmode(GPIO.BCM) # Numbers GPIOs by BCM
GPIO.setup(MotorPin1, GPIO.OUT) # mode --- output
GPIO.setup(MotorPin2, GPIO.OUT)
GPIO.setup(MotorEnable, GPIO.OUT)
GPIO.output(MotorEnable, GPIO.LOW) # motor stop
pwm = GPIO.PWM(MotorEnable, 1) # configuring Enable pin (MotorEnable) for PWM)
pwm.start(50) #starting pwm with 50% duty cycle
print 'Press Ctrl+C to end the program...'
print 'Raising...'
GPIO.output(MotorPin1, GPIO.HIGH) # clockwise
GPIO.output(MotorPin2, GPIO.LOW)
GPIO.output(MotorEnable, GPIO.HIGH) # motor driver enable
time.sleep(2.5)
GPIO.output(MotorEnable, GPIO.LOW) # motor stop
time.sleep(0.5)
print 'Dropping...'
pwm.ChangeDutyCycle(20) #decreasing dutycycle to 20
GPIO.output(MotorPin1, GPIO.LOW) # counter-clockwise
GPIO.output(MotorPin2, GPIO.HIGH)
GPIO.output(MotorEnable, GPIO.HIGH) # motor driver enable
time.sleep(1.5)
GPIO.output(MotorEnable, GPIO.LOW) # motor stop
time.sleep(0.5)
pwm.stop()
GPIO.cleanup() # Release resource
- Update * Pictures of the spec sheet & connections
- Update 2 - Realized GPIO 12 was in the wrong pin. Changed it to the correct one (5th up) but still no motor turning.
photo
showing the connections between the Pi and the motor driver board. – joan Dec 24 '18 at 23:06