I have a 4 wire stepper motor that I can't seem to get working properly. I tried setting it up with the example code for full revolutions. It turns anti-clockwise (but not fully) and won't turn clockwise at all, it just vibrates.
Any suggestions of what I might be doing wrong, I have tried many combinations of wires to inputs.
You will have to show us a diagram of how you have wired it (draw a sketch and take a photo of it?) and give details of the electronic hardware and software you are using.
Thanks for your reply, its weird I now hooked it up again to take a picture and it started to turn a full 360 degrees anti-clockwise, however it is inconsistent, and still doesn't turn clockwise although sometimes turns a few degrees clockwise.
I am using the example code given within the arduino program:
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(20);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(1000);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(1000);
}
I am using a Nema 17 stepper motor, 1.8 degree, marks on the motor read:
The L293 is not really suitable - it is really meant for DC motors. A Pololu a4988 would be a much better choice. It is specifically for stepper motors up to a max of 2 amps and just needs 2 connections to the Arduino - step and direction. If you want to consider other boards make sure they are for driving stepper motors.
There are a lot of questionable examples on the web. And as pointed out, the motor you are using is designed to be used with a chopper driver IC.
A board based on a chip like the A4988, such as the Pololu A4988 carrier board, would be a good match for that board. It can drive up to 1A as-is, or up to 2A with a small heatsink and forced air. You can also find suppliers on eBay of compatible boards that include the heat sinks.
Note that these are not shields, you'll need to plug them into a protoboard to make the proper connections. Also, you do NOT use the stepper motor library with these. They only require !Enable, Step, and Direction. I am working on some code for several projects, I started with the Blink Without Delay sketch, changing it to use micros() instead of millis().
I don't think you've ever told us which motor shield you are using. That information is of prime importance.
The A4988 takes the place of the motor shield. I have written my own code to drive them so I don't know if there is a suitable library.
Basically you need to connect a Uno pin to the step input to the A4988 (and have a common ground) and turn the pin high and low in succession (it should work fine if highs and lows are 800 microseconds long or greater - I think shorter pulses will work if you need faster motion - you can experiment).
If you want to control direction you need to connect an Arduino pin to the direction input. High will go one way, low the other.
If you want to use microstepping you will need to set some other pins. This could be done by using more Arduino pins or by hardwiring - look at the specification sheet.
Obviously you also need to provide a motor power supply for the A4988.
The motor will move one step for every pulse on your turn pin. A pulse is a short period high followed by a period low. The high period should work if it's 800 microseconds or so. The low shouldn't be shorter, but obviously it can be longer if you want slow steps.
The dir pin should stay high (or low) until you want to change direction.
It looks from your diagram that you failed to connect /reset and sleep. A capacitor is strongly advised across the motor power supply, close to the driver board. Consult Pololu's recommended hookup at Pololu - A4988 Stepper Motor Driver Carrier, Black Edition