moonjung
Posts: 1
Joined: Tue May 21, 2019 1:03 am

Why isn't the step motor working?

Tue May 21, 2019 1:13 am

I am trying to turn the motor by connecting the motor driver L298N and the stepper motor. I made a code and put it in a raspberry pie, but I can only hear the clatter and it doesn't work very well. Is there a problem with the code?


<code>

import RPi.GPIO as GPIO
from time import sleep

out11 = 26
out21 = 20
out31 = 16
out41 = 21
out12 = 24
out22 = 17
out32 = 27
out42 = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup(out11,GPIO.OUT)
GPIO.setup(out21,GPIO.OUT)
GPIO.setup(out31,GPIO.OUT)
GPIO.setup(out41,GPIO.OUT)
GPIO.setup(out12,GPIO.OUT)
GPIO.setup(out22,GPIO.OUT)
GPIO.setup(out32,GPIO.OUT)
GPIO.setup(out42,GPIO.OUT)
sleep(0.5)
print "First calibrate by giving some +ve and -ve values....."

GPIO.output(out11,GPIO.LOW)
GPIO.output(out21,GPIO.LOW)
GPIO.output(out31,GPIO.LOW)
GPIO.output(out41,GPIO.LOW)
GPIO.output(out12,GPIO.LOW)
GPIO.output(out22,GPIO.LOW)
GPIO.output(out32,GPIO.LOW)
GPIO.output(out42,GPIO.LOW)
print "set"
sleep(0.5)
while True:


GPIO.output(out11,GPIO.HIGH)
GPIO.output(out12,GPIO.HIGH)
GPIO.output(out21,GPIO.HIGH)
GPIO.output(out22,GPIO.HIGH)
GPIO.output(out31,GPIO.LOW)
GPIO.output(out32,GPIO.LOW)
GPIO.output(out41,GPIO.LOW)
GPIO.output(out42,GPIO.LOW)
sleep(0.0208)
print"2"


GPIO.output(out11,GPIO.LOW)
GPIO.output(out12,GPIO.LOW)
GPIO.output(out21,GPIO.HIGH)
GPIO.output(out22,GPIO.HIGH)
GPIO.output(out31,GPIO.HIGH)
GPIO.output(out32,GPIO.HIGH)
GPIO.output(out41,GPIO.LOW)
GPIO.output(out42,GPIO.LOW)
sleep(0.0208)
print"4"


GPIO.output(out11,GPIO.LOW)
GPIO.output(out12,GPIO.LOW)
GPIO.output(out21,GPIO.LOW)
GPIO.output(out22,GPIO.LOW)
GPIO.output(out31,GPIO.HIGH)
GPIO.output(out32,GPIO.HIGH)
GPIO.output(out41,GPIO.HIGH)
GPIO.output(out42,GPIO.HIGH)
sleep(0.0208)
print"6"


GPIO.output(out11,GPIO.HIGH)
GPIO.output(out12,GPIO.HIGH)
GPIO.output(out21,GPIO.LOW)
GPIO.output(out22,GPIO.LOW)
GPIO.output(out31,GPIO.LOW)
GPIO.output(out32,GPIO.LOW)
GPIO.output(out41,GPIO.HIGH)
GPIO.output(out42,GPIO.HIGH)
sleep(0.0208)
print"8"

User avatar
Gavinmc42
Posts: 2929
Joined: Wed Aug 28, 2013 3:31 am

Re: Why isn't the step motor working?

Tue May 21, 2019 7:39 am

Put a loop in, you are only moving a few steps.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

pcmanbob
Posts: 5968
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Why isn't the step motor working?

Tue May 21, 2019 8:17 am

Hi.

So the first question is have you got the stepper motor connected to the L298N correctly , you need to make sure you have one coil connected to each side of the motor driver board, and you need to make sure the coils are actually connected the same way round.

next you need to tell us which pins on the pi are connected to which pins on the L298N, as an L298N only has 6 control pins and you are using 8 ?

and please when posting code use code tags

Add [code] at the top

code goes here

and [/code] at the bottom.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

B.Goode
Posts: 7757
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Why isn't the step motor working?

Tue May 21, 2019 8:46 am

Gavinmc42 wrote:
Tue May 21, 2019 7:39 am
Put a loop in, you are only moving a few steps.


Probably because of the lack of formatting you may have overlooked

Code: Select all

while True:

User avatar
Gavinmc42
Posts: 2929
Joined: Wed Aug 28, 2013 3:31 am

Re: Why isn't the step motor working?

Wed May 22, 2019 12:35 am

while True:
Did not see that? Still don't?

I also assumed this was driving two motors, hence the 1234 for motor1/motor2.
Without a circuit it is guesswork.
I do prefer the newer mosfet step/direction driver chips over this older bipolar style driver.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Python”