1
\$\begingroup\$

I have a NEMA17 stepper motor (2 Phase, Rated 12V, 1.2A/Phase) and I am trying to make it run with an L298N and a Raspberry Pi. Everything is wired up as shown below in the pictures. I use a 12V, 2A power supply to power the L298N. The RPi is powered separately.

I measured the resistance between the different stepper motor leads. I have been told that two wires are a pair if they have very little resistance. If there is no resistance, they are not a pair. This way, I think The correct pairs are in the A and B terminals of the L298N.

I'm using the following python script:

import RPi.GPIO as GPIO
import time

# Variables

delay = 0.05
steps = 50

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Init pins

coil_A_1_pin = 9
coil_A_2_pin = 25
coil_B_1_pin = 11
coil_B_2_pin = 8

# Set pin states

GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)

# Function for step sequence

def setStep(w1, w2, w3, w4):
  GPIO.output(coil_A_1_pin, w1)
  GPIO.output(coil_A_2_pin, w2)
  GPIO.output(coil_B_1_pin, w3)
  GPIO.output(coil_B_2_pin, w4)


# Example rotations: forward and backward

for i in range(0, steps):
    setStep(1,0,1,0)
    time.sleep(delay)
    setStep(0,1,1,0)
    time.sleep(delay)
    setStep(0,1,0,1)
    time.sleep(delay)
    setStep(1,0,0,1)
    time.sleep(delay)

for i in range(0, steps):
    setStep(1,0,0,1)
    time.sleep(delay)
    setStep(0,1,0,1)
    time.sleep(delay)
    setStep(0,1,1,0)
    time.sleep(delay)
    setStep(1,0,1,0)
    time.sleep(delay)

The stepper motor does not move whatsoever, unfortunately. It does make very little noise when running the script.

Any ideas on how to troubleshoot this project are very welcome.

More details on the stepper motor:
PHASE : 2 PHASE
STEP ANGLE : 1.8 ± 5% ° /STEP
VOLTAGE : 12V
CURRENT : 1.2 A/PHASE
RESISTANCE : 10.0 ± 10% ?/PHASE
INDUCTANCE : 20 ± 20% mH/PHASE
HOLDING TORQUE : 48 N.cm Min
NUMBER OF LEADS : 4
LEAD STYLE : AWG26 UL1007
LEAD STYLE : AWG26 UL1007
ROTOR TORQUE : 68 g.cm2
INSULATION CLASS : B
SIZE : 41 x 41 x 62mm
WEIGHT : 181 grams

schematic

pic1

pic2

pic3

pic4

\$\endgroup\$
9
  • 1
    \$\begingroup\$ And your schematic is.... \$\endgroup\$
    – Tyler
    Jan 29, 2017 at 0:01
  • \$\begingroup\$ Welcome, jvermeulen! as Tyler correctly indicates, a good question also includes a clear schematic of what you're doing – that's what the built-in schematic editor is for. \$\endgroup\$ Jan 29, 2017 at 0:05
  • \$\begingroup\$ @MarcusMüller: A schematic has been added above. I hope it is clearer now! \$\endgroup\$
    – jvermeulen
    Jan 29, 2017 at 19:12
  • 1
    \$\begingroup\$ That is not a schematic, but it might be enough. \$\endgroup\$
    – Tyler
    Jan 29, 2017 at 19:12
  • \$\begingroup\$ @jvermeulen: that's really everything but a schematic (that's why I referred to the built-in schematic editor... sigh), but it certainly helps. \$\endgroup\$ Jan 29, 2017 at 19:31

1 Answer 1

0
\$\begingroup\$

I don't have the "reputation" to comment.....but, are the grounds (12-volt ground and Raspberry Pi ground) connected together? They must be!

\$\endgroup\$
5
  • \$\begingroup\$ That was it! Thanks! I wonder, why is that necessary? Won't the current flow to the ground of the L298N instead of back to the raspberry pi? \$\endgroup\$
    – jvermeulen
    Jan 29, 2017 at 22:01
  • \$\begingroup\$ Current flows in a loop. A small current coming out of the Raspberry Pi must return somehow. The 12-volt supply is isolated from the AC socket that it is plugged into. Same for whatever is powering your Raspberry Pi. You must have a connection between the grounds. \$\endgroup\$ Jan 30, 2017 at 20:42
  • \$\begingroup\$ But, when touching an electric fence, current does flow to your body through another ground, thus not circular. Why does current flow in that case, compared to this case? \$\endgroup\$
    – jvermeulen
    Feb 1, 2017 at 23:31
  • \$\begingroup\$ Any large conductive body can be considered to be a ground. \$\endgroup\$ Feb 3, 2017 at 1:30
  • \$\begingroup\$ For example, planet earth. If you are still confused by all of this, consider starting a new question....we are getting off topic. \$\endgroup\$ Feb 3, 2017 at 1:42

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