1

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

Connections

Connections2

Spec Sheet

  • Update 2 - Realized GPIO 12 was in the wrong pin. Changed it to the correct one (5th up) but still no motor turning.
  • We need a clear photo showing the connections between the Pi and the motor driver board. – joan Dec 24 '18 at 23:06
1

To debug your code, I made it as simple as possible, but not simpler.

  1. You are using PMW for the Enable pin. To make it simple, I just set enable pin high. I guess this is the same as PWM with duty cycle 100%

  2. I removed all the comments and print statements.

  3. I ran the simplified program without any problem. The motor moves, sleeps, and move again.

The simplified program is listed below. If you cannot run this program, then it is hardware problem. If you can run this program, but not the more complicated PWM version, then it is software problem, such as your enable pin cannot do PWM. In this case I can also try PWM and compare with yours.

# l298n_test_01 tlfong01 2019apr07hkt1748 ***
# $ hostnamectl = raspberrypi Raspbian GNU/Linux 9 (stretch) Linux 4.14.34-v7+ arm 
# >>> sys.version = 3.5.3 Jan 19 2017

import RPi.GPIO as GPIO
import time

MotorEnable = 11
MotorPin2   = 10
MotorPin1   =  9 

GPIO.setmode(GPIO.BCM)
GPIO.setup(MotorPin1, GPIO.OUT)
GPIO.setup(MotorPin2, GPIO.OUT)
GPIO.setup(MotorEnable, GPIO.OUT)
GPIO.output(MotorEnable, GPIO.LOW)

GPIO.output(MotorPin1, GPIO.HIGH)
GPIO.output(MotorPin2, GPIO.LOW)
GPIO.output(MotorEnable, GPIO.HIGH)
time.sleep(2.5)

GPIO.output(MotorEnable, GPIO.LOW)
time.sleep(0.5)

GPIO.output(MotorPin1, GPIO.LOW)
GPIO.output(MotorPin2, GPIO.HIGH)
GPIO.output(MotorEnable, GPIO.HIGH)
time.sleep(1.5)

GPIO.output(MotorEnable, GPIO.LOW)
time.sleep(0.5)

GPIO.cleanup()

# End

L293D and L298N Hardware Incompatibilities

Or your hardware are compatible to L293D, but not L298N. For example, your L298N have optocoupler which might invert the input signals.

[L298N] Part Incompatibilities

Manual jumper wire signal testing by hand before writing any program

And I always recommend anxious newbies to go slow, and do jumper signal hardware and wiring checking before writing any software program.

[l298n] Why isn’t my Raspberry Pi motor spinning?

Important L298N/TB6612FNG Power Set up/Close down procedure

It is important to follow the power switching on/off sequence. Otherwise motor might go crazy and burn out.

  1. Setup - Logic power first, then motor power.

  2. Close down - Motor power first, then Logic power.

motor driver signal/power routing

Youtube TB6612FNG Motor Spinning

Your motors might have burnt!

I read the Drok user guide and found that you need to be very careful when using this driver. You might like to check out the following precautions paragraph.

Drok L298N PWM 7A/160W DC Motor Driver

Drok L298N driver precautions

The big problem is that Drok say their driver is 7A, but L298N current limit is only 4A. Am I missing anything?

L298N current limit is 4A only

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.