Stepper Motor setup

I have been trying to get a stepper motor to work. I have hooked one up to a driver and the driver to a Teensy 2.0. The stepper erratically moves in different directions, stops and vibrates. I can’t control the motor in a predictable manner.



The 2 black and reddish coloured wires close to the 100 uF capacitor are connected to a 12V 1A power supply.

I hooked the stepper driver according to this diagram:

More information about the driver can be found here (click)

The Bipolar stepper motor is 1.8A and 1.8 degrees.

The code that I am running is this:

#include <AccelStepper.h>

AccelStepper Xaxis(1, 5, 6);

void setup() {
  Xaxis.setMaxSpeed(400);
  Xaxis.setSpeed(45);
}

void loop() {  
   Xaxis.runSpeed();
}

It’s a modified version of the code found here (click)
http://pjrc.com/teensy/td_libs_AccelStepper.html
I have also tried code from Arduino’s reference.
http://arduino.cc/en/reference/stepper

Thanks for reading and all help is appreciated.

I hope that the information is sufficient.

It's a modified version of the code found here (click)

Cannot access this link.

Which version of the AccelStepper library do you have - looked at the code of mine and its broken for motor interface type = DRIVER, as the step1() method pulses the step pin before the direction pin.

You may need to rewrite this to do the correct thing (the A4988 requires 200ns setup time on direction pin before the step pulse).

MarkT: Which version of the AccelStepper library do you have - looked at the code of mine and its broken for motor interface type = DRIVER, as the step1() method pulses the step pin before the direction pin.

You may need to rewrite this to do the correct thing (the A4988 requires 200ns setup time on direction pin before the step pulse).

I'm not experiencing the same error that you are... I'm pretty sure I have version 1.3. I got it here: http://pjrc.com/teensy/td_libs_AccelStepper.html

Any chance you could give me a link to the newest version; if there is one?

I'm not experiencing the problem, not used the AccelDriver in that mode, but I looked at the code and its obviously broken - the one you used has the same broken code.

Look in AccelStepper.cpp, change this code:

void AccelStepper::step1(uint8_t step)
{
    // _pin[0] is step, _pin[1] is direction
    setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    delayMicroseconds(_minPulseWidth);
    setOutputPins(_direction ? 0b10 : 0b00); // step LOW

}

to this:

void AccelStepper::step1(uint8_t step)
{
    setOutputPins(_direction ? 0b10 : 0b00); // update direction
    // _pin[0] is step, _pin[1] is direction
    setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    delayMicroseconds(_minPulseWidth);
    setOutputPins(_direction ? 0b10 : 0b00); // step LOW

}

Its probably not your problem though, but it will cause an extra step in the wrong direction every time the direction changes.

Is it possible your power supply is inadequate? You state the motor is 1.8A and the PS is only 1A?