Stepper Motor Dilemma. Have looked everywhere

Sorry to post about something that has been discussed frequently but I am at a loss in regards to driving my particular stepper motor with my arduino duemilanove. It's a shinano kenshi stp 42d217 stepper motor that says 6v 0.76a. That's obviously under the .5a 5v USB powered output. The issue i am having is the tutorials on the arduino site I believe have stepper motors that will run from USB power, and the other sites (tom igoe's, Umass, dorkbot pdx, etc) detail some aspects but are not start to finish tutorials. I'd like to run this motor from my arduino, i have a 9v wall wart power supply, a 12v wall wart power supply and a lab bench power supply. I cannot figure out how to connect the motor through the darlington array to the power supply and then use the arduino to control stepping. I have connected the motor as the arduino tutorial describes and when I touch the motor I can feel the motor trying to move. When I use either power supply i can make the motor move one step and have isolated the coils and power connections. I am posting two images along with this. the first is how i currently have the motor and arduino connected the second is a rough diagram, the question i have is if i'm using an external power supply for the motor alone, how does the the power supply connect to the motor and the darlington array? Does the arduino need to share a ground with the external power supply? If someone could direct me on how best to wire this I would be very grateful.

You can start simple - you can have two power supplies - one for the arduino, the other - for the motor (through the darlington array). You have to connect the two grounds together (the 0v of both supplies).
If you have to use a single supply you have to find a way to physically "split" the output so one part goes to power the arduino and another to the motor. In this case the ground is common by design.
See this recent thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246559182/3#3

Thanks mircho, the issue i'm having is the circuitry. I've got everything pretty much connected as in this diagram

Except the diagram shows a ULN2004 array rather than a ULN2003a which i have. Does anyone know what the difference will be?

http://nate.petre.net/arduinoimages/arduinomovie/MOV06562.flv

I have had some small success. But now the motor goes back and forth but not continuously in one direction. Any advice on how to get this sorted out?

Thanks
Nathaniel

Also I'm using the advanced code from here: http://www.arduino.cc/en/Tutorial/StepperUnipolar

The difference between the ULN2003 and the 2004 is that the 2004 has a larger resistor in the base circuit, so it turns on at a higher voltage. Back in the early days of MOS logic, there were many chips that ran on 9 or 12V, so Sprague made a version for them.

You definitely need to connect the two grounds together, and it should be done with a nice fat wire, because all the current for the motor is flowing through the 2003.

If the ground's okay, you may have the windings hooked up in the wrong sequence. That's often a problem when getting a new unipolar motor working. Try putting a mark on that pulley so you can see more clearly how it's moving.

Ran

Thanks Ran,

I actually looked here:

and found a wiring diagram and code that sort of works. I had to adjust this code:

// Simple stepped motor spin
// by Silveira Neto, 2009, under GPLv3 license
// http://silveiraneto.net/2009/03/16/bumbabot-1/
int coil1 = 8;
int coil2 = 9;
int coil3 = 10;
int coil4 = 11;
int step = 0;
int interval = 100;
 
void setup() {
  pinMode(coil1, OUTPUT);
  pinMode(coil2, OUTPUT);
  pinMode(coil3, OUTPUT);
  pinMode(coil4, OUTPUT);
}
 
void loop() {
  digitalWrite(coil1, step==0?HIGH:LOW);
  digitalWrite(coil2, step==1?HIGH:LOW);
  digitalWrite(coil3, step==2?HIGH:LOW);
  digitalWrite(coil4, step==3?HIGH:LOW);
  delay(interval);
  step = (step+1)%4;
}

so that the int interval is 3.6 for the stepper motor to turn somewhat properly. There is still a visible 'skip' or 'jerk' however. Is that because of the code? Is this something that the stepper library solves?

Thanks again

There is still a visible 'skip' or 'jerk' however.

Probably because you are going too fast.
Try:-
int interval = 200;

Try:-
int interval = 200;

At an interval of 3.2-3.6 the motor will turn continuously in one direction with a fractional skip or hesitation every so often. Anything else the motor will not function properly, it turns back and forth a step and at higher intervals just vibrates and doesn't turn.

A correctly wired up stepping motor can turn at any speed slower than the maximum. If you have the situation where it only works at one speed not faster and not slower then you have got the motor phases wired the wrong way. You have to experiment to find the right connections to match your software. Start with a slow speed say a 500 mS delay and get it reliably turning in one direction. If it then won't turn in the other direction adjust your code not the wiring.

Not sure if you still have this issue, but I just set up the same stepper and it looks like you have the wiring wrong. The black and white wires need to be connected to pin 9 of the darlington array along with the power supply. The rest of the wires need to be on pins 13-16. To make life easier just put them in randomly and change the pin order in your code until things start working.

Stepper stepper(STEPS, 8, 9, 10, 11);

oh, and use the stepper library.

If all else fails, read the following links:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274847452
and
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274902910
I will attach the code for the library and give you instructions regarding how to use it.
First, navigate to: In wiring (Downloaded Arduino 0018) Arduino-0018->libraries->stepper.
Once there, back up (copy to another location in case soething goes wrong and you need to restore the original file) the file Stepper.cpp.
Next, right click in the directory and select "New" from the pop-up menu. From the 2nd pop-up menu, select "text document" from the second pop-up menu. save the file as Stepper.cpp (change the extension from.txt to .cpp) by renaming it if need be.
Lastely, copy the code supplied below into the new Stepper.cpp file and then save it. Perhaps you want to change the extension on the text file last so you aren't hassled by the "Windows cannot open this file, select a program from a list of a list of installed programs" popup window.
Hope this helps!

/*
  Stepper.cpp - - Stepper library for Wiring/Arduino - Version 0.4
  
  Original library     (0.1) by Tom Igoe.
  Two-wire modifications   (0.2) by Sebastian Gassner
  Combination version   (0.3) by Tom Igoe and David Mellis
  Bug fix for four-wire   (0.4) by Tom Igoe, bug fix from Noah Shibley  

  Drives a unipolar or bipolar stepper motor using  2 wires or 4 wires

  When wiring multiple stepper motors to a microcontroller,
  you quickly run out of output pins, with each motor requiring 4 connections. 

  By making use of the fact that at any time two of the four motor
  coils are the inverse  of the other two, the number of
  control connections can be reduced from 4 to 2. 

  A slightly modified circuit around a Darlington transistor array or an L293 H-bridge
  connects to only 2 microcontroler pins, inverts the signals received,
  and delivers the 4 (2 plus 2 inverted ones) output signals required
  for driving a stepper motor.

  The sequence of control signals for 4 control wires is as follows:

  Step C0 C1 C2 C3
     1  1  0  1  0
     2  0  1  1  0
     3  0  1  0  1
     4  1  0  0  1

  The sequence of controls signals for 2 control wires is as follows
  (columns C1 and C2 from above):

  Step C0 C1
     1  0  1
     2  1  1
     3  1  0
     4  0  0

  The circuits can be found at 
 
http://www.arduino.cc/en/Tutorial/Stepper
 
 
 */


#include "WProgram.h"
#include "Stepper.h"

/*
 * two-wire constructor.
 * Sets which wires should control the motor.
 */
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
{
  this->step_number = 0;      // which step the motor is on
  this->speed = 0;        // the motor speed, in revolutions per minute
  this->direction = 0;      // motor direction
  this->last_step_time = 0;    // time stamp in ms of the last step taken
  this->number_of_steps = number_of_steps;    // total number of steps for this motor
  
  // Arduino pins for the motor control connection:
  this->motor_pin_1 = motor_pin_1;
  this->motor_pin_2 = motor_pin_2;

  // setup the pins on the microcontroller:
  pinMode(this->motor_pin_1, OUTPUT);
  pinMode(this->motor_pin_2, OUTPUT);
  
  // When there are only 2 pins, set the other two to 0:
  this->motor_pin_3 = 0;
  this->motor_pin_4 = 0;
  
  // pin_count is used by the stepMotor() method:
  this->pin_count = 2;
}


/*
 *   constructor for four-pin version
 *   Sets which wires should control the motor.
 */

Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4)
{
  this->step_number = 0;      // which step the motor is on
  this->speed = 0;        // the motor speed, in revolutions per minute
  this->direction = 0;      // motor direction
  this->last_step_time = 0;    // time stamp in ms of the last step taken
  this->number_of_steps = number_of_steps;    // total number of steps for this motor
  
  // Arduino pins for the motor control connection:
  this->motor_pin_1 = motor_pin_1;
  this->motor_pin_2 = motor_pin_2;
  this->motor_pin_3 = motor_pin_3;
  this->motor_pin_4 = motor_pin_4;

  // setup the pins on the microcontroller:
  pinMode(this->motor_pin_1, OUTPUT);
  pinMode(this->motor_pin_2, OUTPUT);
  pinMode(this->motor_pin_3, OUTPUT);
  pinMode(this->motor_pin_4, OUTPUT);

  // pin_count is used by the stepMotor() method:  
  this->pin_count = 4;  
}

/*
  Sets the speed in revs per minute

*/
void Stepper::setSpeed(long whatSpeed)
{
  this->step_delay = 60L * 1000L / this->number_of_steps / whatSpeed;
}

/*
  Moves the motor steps_to_move steps.  If the number is negative, 
   the motor moves in the reverse direction.
 */
void Stepper::step(int steps_to_move)
{  
  int steps_left = abs(steps_to_move);  // how many steps to take
  
  // determine direction based on whether steps_to_mode is + or -:
  if (steps_to_move > 0) {this->direction = 1;}
  if (steps_to_move < 0) {this->direction = 0;}
    
    
  // decrement the number of steps, moving one step each time:
  while(steps_left > 0) {
  // move only if the appropriate delay has passed:
  if (millis() - this->last_step_time >= this->step_delay) {
      // get the timeStamp of when you stepped:
      this->last_step_time = millis();
      // increment or decrement the step number,
      // depending on direction:
      if (this->direction == 1) {
        this->step_number++;
        if (this->step_number == this->number_of_steps) {
          this->step_number = 0;
        }
      } 
      else { 
        if (this->step_number == 0) {
          this->step_number = this->number_of_steps;
        }
        this->step_number--;
      }
      // decrement the steps left:
      steps_left--;
      // step the motor to step number 0, 1, 2, or 3:
      stepMotor(this->step_number % 4);
    }
  }
}

/*
 * Moves the motor forward or backwards.
 */
void Stepper::stepMotor(int thisStep)
{
  if (this->pin_count == 2) {
    switch (thisStep) {
      case 0: /* 01 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 1: /* 11 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 2: /* 10 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      break;
      case 3: /* 00 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      break;
    } 
  }
  if (this->pin_count == 4) {
    switch (thisStep) {
      case 0:    //1100
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 1:    // 0110
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 2:    //0011
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, HIGH);
      break;
      case 3:    //1001
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;
    } 
  }
}

/*
  version() returns the version of the library:
*/
int Stepper::version(void)
{
  return 4;
}

/me :slight_smile:
jrine313692aol.com