Following this video, my motors should be constantly running as per the program and should stop running after the program is executed.
When I first ran the script, the motors did run, as per the directions and stopped. Later on my second try, one of my wires connecting the motor, disconnected. I immediately reattached it after stopping the program. The motor kept running regardless of the status of the program. By this, I mean that it did not change the directions or stop as per the time.
I restarted my Pi and it worked fine for 2 tries and then slowly, the speed of the motors decreased and then at one point stopped. I thought that my batteries were dead as the motors might have consumed a lot of power, but using a voltmeter I found out that it still was nearly full.
I tried running it again, and this time it did not even run. As another test I restarted my Pi, and it worked again and slowly decreased the speed as the previous incident.
Does anyone have a solution to my problem?
This is the circuit layout:
I had made a code error on the first try, which I had later realized when the motors spun only in 1 direction. For the forward function, I had accidentally copy-pasted the same line that is, the
gpio.output(17, True) instead of assigning the values for different GPIOS.
import RPi.GPIO as gpio import time def init(): gpio.setmode(gpio.BCM) gpio.setup(17, gpio.OUT) gpio.setup(22, gpio.OUT) gpio.setup(23, gpio.OUT) gpio.setup(24, gpio.OUT) def forward(steps): init() gpio.output(17, False) gpio.output(22, True) gpio.output(23, False) gpio.output(24, True) time.sleep(steps) gpio.cleanup() def reverse(steps): init() gpio.output(17, True) gpio.output(22, False) gpio.output(23, True) gpio.output(24, False) time.sleep(steps) gpio.cleanup() print("GOING FORWARD") foward(4) print("GOING BACKWARD") reverse(2)