RPI Stepper Lesson 10

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
allen00se
 
Posts: 6
Joined: Sun Jan 19, 2014 9:43 pm

RPI Stepper Lesson 10

Post by allen00se »

I have a project that I want to build based of of the Raspberry PI Lesson10, however I want to substitute in a better stepper. Is it possible to use all of the same components but use the Nema 17 stepper http://www.adafruit.com/products/324 ? I realize I would need a larger power supply, but I am not sure if everything else would work since it is a bi-polar and the tutorial uses a uni-polar.

Thanks in advance,
Krys

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI Stepper Lesson 10

Post by adafruit_support_mike »

The motor in the tutorial is a unipolar, but it's driven as a bipolar.. that's both possible and common.

A unipolar motor has a center tap in each coil, and to run it unipolar you connect that tap to VCC then take each end of each coil to GND in turn. It's easy electrically because you don't need an H-bridge to do it.. just one transistor at either end of each coil. Trouble is, you're only using half of each coil at any time, which reduces the torque.

In a bipolar stepper, you use an H-bridge to send one side to VCC and the other to GND, then later swap the polarities to GND and VCC. The driver is more complicated, but you use the whole coil at any given time, so you get as much torque as is possible for that armature.

To run a unipolar stepper as a bipolar, you just ignore the center tap and hook it up to an H-bridge, which is what we show in the tutorial.

Even if you had the signals wrong, it wouldn't hurt anything. A bipolar stepper won't actually conduct power if you use unipolar signals. You'd just connect one end of each coil to GND at each step.

User avatar
allen00se
 
Posts: 6
Joined: Sun Jan 19, 2014 9:43 pm

Re: RPI Stepper Lesson 10

Post by allen00se »

adafruit_support_mike wrote:The motor in the tutorial is a unipolar, but it's driven as a bipolar.. that's both possible and common.

A unipolar motor has a center tap in each coil, and to run it unipolar you connect that tap to VCC then take each end of each coil to GND in turn. It's easy electrically because you don't need an H-bridge to do it.. just one transistor at either end of each coil. Trouble is, you're only using half of each coil at any time, which reduces the torque.

In a bipolar stepper, you use an H-bridge to send one side to VCC and the other to GND, then later swap the polarities to GND and VCC. The driver is more complicated, but you use the whole coil at any given time, so you get as much torque as is possible for that armature.

To run a unipolar stepper as a bipolar, you just ignore the center tap and hook it up to an H-bridge, which is what we show in the tutorial.

Even if you had the signals wrong, it wouldn't hurt anything. A bipolar stepper won't actually conduct power if you use unipolar signals. You'd just connect one end of each coil to GND at each step.
Thanks for the great explanation! From what I can tell the L293d is capable of driving a bipolar stepper, although i haven't found a tutorial on using it with the RPI. Would the wiring scheme be similar to this diagram used to wire the L293d to a picaxe? Image
Thanks in advance.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI Stepper Lesson 10

Post by adafruit_support_mike »

There's a Fritzing diagram for the connections to an L293D in the tutorial: http://learn.adafruit.com/adafruits-ras ... ware-l293d The unconnected red wire would be the center tap for a unipolar motor.

(BTW - that tutorial does show how to drive a unipolar motor, but it's done using the ULN2803)

User avatar
allen00se
 
Posts: 6
Joined: Sun Jan 19, 2014 9:43 pm

Re: RPI Stepper Lesson 10

Post by allen00se »

adafruit_support_mike wrote:
(BTW - that tutorial does show how to drive a unipolar motor, but it's done using the ULN2803)
Yes I saw the unipolar, I am interested in driving a bipolar. I went ahead and ordered the L293D and the Nema 17 stepper, so hopefully I can get them to work together. Also I ordered an L298N breakout board in case the L293D doesnt work.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI Stepper Lesson 10

Post by adafruit_support_mike »

The motor in question draws 350mA @ 12v and an L293D can handle 600mA per channel. They should work together without any problems.

User avatar
allen00se
 
Posts: 6
Joined: Sun Jan 19, 2014 9:43 pm

Re: RPI Stepper Lesson 10

Post by allen00se »

So i go tmy stepper hooked up and working, however as it turns it vibrates quite alot, is there any way to tune the software on lesson 10? I would imagine that I have everything hooked up correctly or it wouldnt turn at all, but the vibration seems excessive (sounds like a cell phone vibrating on a hard surface). Any ideas?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI Stepper Lesson 10

Post by adafruit_support_mike »

That may be the motor's way of saying you've given it a good power supply.

Steppers don't turn smoothly like DC motors. They snap from one position to the next. Most steppers are spec'd to have the rotor hit each position within a small repeatable error.. usually around 0.5 degrees. That means you get a burst of torque to start the rotor moving and another burst of torque to stop it. Forces act in both directions, so when the stator pushes the rotor, the rotor pushes back against the stator.

If you have a good, strong power supply, the coils will generate a lot of torque, and yeah, that pretty much gives you a vibration motor. Clamping the motor's frame to a fixed mounting helps, as does giving the rotor a load to smooth out the stop/start torque.

Try microstepping the rotor. That makes the current through the coils approximate a sine wave (which is what you'd get if the rotor was spinning smoothly), so instead of snapping all the way from A to B, it takes a series of smaller steps. If the current through the coil pulling the rotor toward point A is three times as large as the current pulling toward point B, the rotor will stop 1/4 of the way from A to B. If the currents are equal, the rotor will stop halfway between A and B. Then you make B three times as large as A to get the 3/4 step, and finally shut off A entirely and let the rotor move all the way to B.

When the steps are smaller, the rotor doesn't have to move as quickly from one position to the next (even if the overall rate of rotation is the same, but the math to prove that gets hairy), and the coils pulling against each other reduce the torque acting on the rotor at any given moment. The result is smoother operation, both electrically and mechanically.

User avatar
CPSC
 
Posts: 1
Joined: Mon Sep 01, 2014 4:27 pm

Re: RPI Stepper Lesson 10

Post by CPSC »

Hey everyone, i have a similar problem and therefor thought that its best just to tag along here.
I have the Nema 17 hooked up to the L293D using the wiring diagram given in lesson 10 replacing only the power supply by a 12V battery pack.

The setup is shown below. I hope i didnt forget anything.
L293D Stepper.png
L293D Stepper.png (334.37 KiB) Viewed 420 times
i am trying to drive the stepper using the code from lesson 10:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

enable_pin=18
coil_a1_pin=4
coil_a2_pin=17
coil_b1_pin=23
coil_b2_pin=24

GPIO.setup(enable_pin, GPIO.OUT)
GPIO.setup(coil_a1_pin, GPIO.OUT)
GPIO.setup(coil_a2_pin, GPIO.OUT)
GPIO.setup(coil_b1_pin, GPIO.OUT)
GPIO.setup(coil_b2_pin, GPIO.OUT)

GPIO.output(enable_pin, 1)

def forward(delay, steps):
    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)
    
def backwards(delay, steps):
    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)

def setStep(w1, w2, w3, w4):
    GPIO.output(coil_a1_pin, w1)
    GPIO.output(coil_a2_pin, w2)
    GPIO.output(coil_b1_pin, w3)
    GPIO.output(coil_b2_pin, w4)

try:
    while True:
        delay=raw_input("Delay between steps(ms):")
        steps=raw_input("Steps forward:")
        forward(int(delay)/1000.0, int(steps))
        steps=raw_input("Steps backwards:")
        backwards(int(delay)/1000.0, int(steps))
except KeyboardInterrupt:
    GPIO.cleanup()
Now the problem:
The Nema17 should have 200 steps a 1,8°,using above code one full rotation are not 200 steps, but instead 50.
When i enter "1" step forward with 1000 ms delay I can clearly see that the motor jumps 4 times instead of once. So 1 step has 4 subdivisions. 50*4=200... so somewhere I am losing resolution?

Is that normal or am doing something wrong?
Many thanks!

Christoph

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI Stepper Lesson 10

Post by adafruit_support_mike »

There are two different ways to define a 'step'.

The tutorial uses the version that says one full cycle of coil activations counts as 'one step'. It's convenient for programmers trying to write stepper motor controllers because every step uses exactly the same signal pattern.

The other version (which motor manufacturers use) says that each coil activation counts as 'one step'. It's a better mechanical and electrical description of the motor because with each coil activation, the teeth on the rotor line up with the teeth on the active coil. The animation on this tutorial page shows how that works: https://learn.adafruit.com/all-about-st ... pper-motor

Lesson 10 uses the full-cycle definition because writing code for the single-activation version is a bit harder. You have to keep track of which coil is currently active and which one will be activating next.

So: your motor has four coils around the stator and 200 coil-activation postions per revolution. The code from the turorial activates all four coils in the same sequence in its forward() and backwards() functions and calls each pattern 'one step'. The motor manufacturer calls each sequence 'four steps'.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”