Calling the AccelStepper function

3,166 views
Skip to first unread message

Pallum

unread,
Oct 15, 2013, 2:32:44 PM10/15/13
to accels...@googlegroups.com
I'm trying to implement the AccelStepper library with my Arduino and DRV8825 stepper motor driver but I'm not sure how to read the function call for this.
When calling "AccelStepper stepper(1, 3, 2);" what do the 1, 3, and 2 parameters mean?
And how to I apply that to controlling the motor driver?
The class reference section is very confusing : \

Sandy Noble

unread,
Oct 15, 2013, 3:07:56 PM10/15/13
to accels...@googlegroups.com
Hello, in conjunction with the examples it usually makes sense - I found the docs actually very instructive, one of the more useful ones I've seen.

From the docs:

Constructor & Destructor Documentation

--
AccelStepper::AccelStepper(
     uint8_t interface = AccelStepper::FULL4WIRE,
     uint8_t pin1 = 2,
     uint8_t pin2 = 3,
     uint8_t pin3 = 4,
     uint8_t pin4 = 5,
     bool enable = true )

  [in]interface - Number of pins to interface to. 1, 2, 4 or 8 are supported, but it is preferred to use the MotorInterfaceType symbolic names.
    AccelStepper::DRIVER (1) means a stepper driver (with Step and Direction pins). If an enable line is also needed, call setEnablePin() after construction. You may also invert the pins using setPinsInverted(). 
    AccelStepper::FULL2WIRE (2) means a 2 wire stepper (2 pins required). 
    AccelStepper::FULL3WIRE (3) means a 3 wire stepper, such as HDD spindle (3 pins required). 
    AccelStepper::FULL4WIRE (4) means a 4 wire stepper (4 pins required). 
    AccelStepper::HALF3WIRE (6) means a 3 wire half stepper, such as HDD spindle (3 pins required)
    AccelStepper::HALF4WIRE (8) means a 4 wire half stepper (4 pins required)

  [in]pin1 - Arduino digital pin number for motor pin 1. Defaults to pin 2. For a AccelStepper::DRIVER (pins==1), this is the Step input to the driver. Low to high transition means to step)
  [in]pin2 - Arduino digital pin number for motor pin 2. Defaults to pin 3. For a AccelStepper::DRIVER (pins==1), this is the Direction input the driver. High means forward.
...
--

So the first parameter is the interface type, and is one of the types listed (1, 2, 4, 6 or 8), and the parameters after that define the actual pins that are wired up. The examples don't show anything except the default way of accessing the object, without any parameters at all, which maybe doesn't help.

AccelStepper stepper(1, 3, 2); 
is synonymous with 
AccelStepper stepper(AccelStepper::DRIVER, 3, 2); which might make a bit more sense

The above means that the stepper object is created, interfaced to a hardware stepper motor driver (like a DRV8825) using two wires from arduino pins D3 and D2.

Again looking at the docs, for the constructor, pin1 (defined as D3 in your example) is the step input to the driver and pin2 (defined as D2 in your example) is the direction input to the driver.

Your driver may have an "enable" pin that you want to use too, in which case you'd need to create the stepper object like above, then do stepper.setEnablePin(<enable pin number>).   Otherwise you could just permanently latch the enable pin high or low in your circuit - depends if you want to be able to release or energise the motors programmatically or not.

I'll admit, like many docs, they are most useful when you already have some knowledge of how the system works, and might be a bit opaque without comprehensive examples, but they are certainly worth keeping close.

sn




--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Sandy Noble

Pallum

unread,
Oct 15, 2013, 3:46:45 PM10/15/13
to accels...@googlegroups.com
Now that makes me feel better. The lack of variety in the examples was definitely a bit frustrating but thanks for your clarification!
Reply all
Reply to author
Forward
0 new messages