I have written a script that controls a L298N motor controller, and I have one strange issue with it. When the script ends, one of the two motors do not stop, and instead go full speed in forward direction.
The reason for this, it appears, is the fact that I am using GPIO.Cleanup() at the end of the script.
If, however, I do not use this method, everything shuts down nicely at the end of the script.
I am using 6 pins, 4 of which indicate the direction of the motor, and two are for PWM pulses.
# Initial set-up
GPIO.setmode(GPIO.BCM)
GPIO.setup(ENA, GPIO.OUT)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)
GPIO.setup(ENB, GPIO.OUT)
self.direction = 0 # Indicates the direction. 1 for forward, -1 for reverse, 0 for stationary
# Setting the direction pins to low
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.LOW)
and each of the enabler pins (ENA & ENB) are instances of GPIO.PWM
self.ENA = GPIO.PWM(ENA, 200) # Send PWM pulses to the enabler pin at a frequency of 200hz
self.ENB = GPIO.PWM(ENB, 200) # Send PWM pulses to the enabler pin at a frequency of 200hz
My question is, should the cleanup method be used in such a case, and is this behaviour normal?