1
\$\begingroup\$

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:

enter image description here

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:

video

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?

\$\endgroup\$

4 Answers 4

0
\$\begingroup\$

Your motor is rated for 35W to 55W, and the power supply is only rated for 24W. No wonder you are getting power glitches to motor. Get a more powerful power supply.

\$\endgroup\$
1
  • \$\begingroup\$ that is a fair observation that I didn't notice, I will see if I can manage to grab a better one this week and will put this as accepted answer if that solves the problem \$\endgroup\$
    – pau Fer
    Mar 23, 2020 at 11:19
0
\$\begingroup\$

You need to set the level for both IN1 and IN2 at the same time.

  • Forward will be IN1 high and IN2 low.
  • Reverse will be IN1 low and IN2 high.

It's there in the example code in the datasheet.

\$\endgroup\$
1
  • \$\begingroup\$ Hi JRE, thank you for answering once more, unfortunately that did not solve the problem, but I'm curious, why would LOW affect the motor any differently than not sending any output? \$\endgroup\$
    – pau Fer
    Mar 23, 2020 at 11:21
0
\$\begingroup\$

Electric motors take a large current surge when they start up. The current in a motor is limited partially by the resistance of the windings, but mainly by the back EMF that the motor generates while it is running.

That surge varies on the type of motor and the load that is on it. But it could be as much as 10 times the running current.

Your problem is that either the controller or the power supply cannot provide enough power to get the motor running up to full speed. One or other of them is cutting out as it is overloaded.

\$\endgroup\$
0
\$\begingroup\$

the way I got this to work is repeating the same behaviour by code, so with this the motor work as intended:

import sys
import time
import RPi.GPIO as GPIO

Forward=37
Backward=38
sleeptime=1

GPIO.setmode(GPIO.BOARD)
GPIO.setup(Forward, GPIO.OUT)
GPIO.setup(Backward, GPIO.OUT)

def BuildVoltage(x):
  for x in range(6):
    GPIO.output(Forward, GPIO.HIGH)
    print("High")
    time.sleep(0.5)
    GPIO.output(Forward, GPIO.LOW)
    print("Low")
    time.sleep(0.25)


  GPIO.output(Forward, GPIO.HIGH)
  time.sleep(x)

while (1):

  BuildVoltage(3)  
  GPIO.cleanup()

it gets increasingly fast and then just keeps going at max speed for as long as I want, @Justme did a fair observation about the power supply being 24W and the motor being 35W, unfortunately due to the apocalypses it will take me a few days to try that, but I will definitely see if I can buy a 12v power supply with more W, but the solution above fixes the problem with my current resources.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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