I understand that this will be a very trivial question but I cannot find an explanation online, probably because in my ignorance I'm asking the wrong question, to support my explanation I'm leaving code, draws , measurements and a video showing what is happening.
This is the scenario:
I have a L298N controller (this one), with a 12v motor (this one) and a 12v power supply(this one), for some time I thought the controller was defective because it always "blinks" when it is on: the motor starts and runs as it should for like a second, then it stops and starts,stops,starts and so on for as long as I have it connected,this is how it looks like in my test:
in the scenario that I described above when I connect that 5v loose cable to the first or second pin the motor goes fast for like a second and then starts turning itself on and off in some sort of blinking effect, exactly the same happens if I turn that pin on with python (by sharing the GND and turning the selected GPIO pin to HIGH in a code like this):
import sys
import time
import RPi.GPIO as GPIO
mode=GPIO.getmode()
GPIO.cleanup()
Forward=26
Backward=20
sleeptime=1
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Forward, GPIO.OUT)
GPIO.setup(Backward, GPIO.OUT)
def forward(x):
GPIO.output(Forward, GPIO.HIGH)
print("Moving Forward")
time.sleep(x)
GPIO.output(Forward, GPIO.LOW)
def reverse(x):
GPIO.output(Backward, GPIO.HIGH)
print("Moving Backward")
time.sleep(x)
GPIO.output(Backward, GPIO.LOW)
while (1):
forward(5)
reverse(5)
GPIO.cleanup()
but for my surprise at some point (while doing the test of the image) I realised that if I hit the cable a few times to get the motor started then I can leave the pin connected and the motor will keep going at full speed, so I feel like this motor needs to "warm up", but I still don't understand why.
I just took some measurements and now I'm even more confuse:
if I leave the cable on the pin the motor first receives around 3v, then it goes down to 1 and stays between 0v and 0.6v
if I hit the cable on the pin multiple times the voltage start building up, so the first time it receives 3v, the second 3.x then 4.x then 5.x and so on (so at some point it have enough voltage to work at full capacity)
I uploaded a little video to show what is happening, at first I leave the cable and it "blinks", then I "warm it up" and at the end it works as it should:
So my doubt is:
-Why does the motor do not receive enough voltage from the start?
-why does it work if I hit the pin with the cable 8-9 times before leave it connected? Shouldn't the voltage be totally independent of if the motor is running or not? (obviously not as if I disconnect the motor those pins receive 10v constantly,but mind tell me why?)
-If that "warm up" process is necessary how do I get this behaviour using python? Is there a "building volts" process that I should be following in my code?