Motor Controller Shield R3 and Stepper motor info

I have stripped a dozen DVD drives for their IR and red laser diodes as well as the head stepper motors and chassis frames. I also scrounged the LEDs, some caps, switches and various other usefull looking components for later experimentation.

Due to the total lack of any real useful information on the main Motor Controller Shield R3 page, I have spent the better part of the day digging and searching for scraps of information from all over the web. I thought I would compile my findings in a single thread in hopes it would be useful to the next guy that purchases this shield and finds it has zero documentation with it and just as much example code.

So, here goes.

After stripping the DVD drives (and I assume this applies to many floppies as they use the same steppers), I found that all but 2 of the dozen had 4 wire steppers. All but one of those has the same pin for pin connections at the PCB end of the attached ribbon cable. There were several different layouts to the pins on the motor body but all but 1 had the same AABB pin layout on the attached ribbon cable so leave that intact as you harvest parts. I also harvested the sockets from the main PCB and attached 4 wires to it so that I could easily plug it into a breadboard or connect to the Motor Controller Shield. This plug will make it easy to hook up various steppers as the majority have 4 pins.

Two of the drives had motors with an identifying part number "PLS-020-xxxx". The "xxxx" part differed between the two, not sure as to their meaning but here is a PDF I found: pl15s020.pdf

Given the info on the pdf, it says the motor has 20 pulses per rotation and 1400pps max and is 5v and confirms it as bipolar.

I hooked it up to A-,A+,B-, and B+ on the motor controller. I set up a SPDT-CenterOff switch (that I stripped from one of the DVD drives) feeding A2 and A3 with the center of the switch to +5 and 10k pull down resistors to ground. This will give a movement controller function. I also use the button on the MakerShield hooked to D7. I also use the pot on the MakerShield to feed A4. The pot will control stepper speed. The toggle switch will control direction of movement. And the button will print info to the serial port. Ok, thats it for connections.

Here is the code:

/*

4 Wire BiPoler Stepper Motor controller for Motor Shield R3
Mike Audleman
Jun 9, 2012 - v1.0.0

Code for public domain.
*/
#include <Stepper.h>

// change this to fit the number of steps per revolution for your motor
const int stepsPerRevolution = 20;

// Constants for the Motor Shield R3:
const int DirA = 12;
const int DirB = 13;
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int SenseA = 0;
const int SenseB = 1;

// Set on analog pins for now, would be better on digital pins
const int SwitchUp = 2;
const int SwitchDn = 3;

// A pot hooked to what pin?  This sets the step speed
const int StepSpeedPot = 4;

// Button to print details to the serial console
const int PrintPosButton = 7;

// Set this based on your stepper motor
// And whatever its attached to
const int MaxStepperSpeed = 1400;
const int MinStepperPos = 0;
const int MaxStepperPos = 255;

int CurStep = 0;

// initialize the stepper library on the motor shield r3
Stepper myStepper(stepsPerRevolution,DirA,DirB);     

void setup() {
  Serial.begin(9600);
  pinMode(PrintPosButton, INPUT);

  // PWM to High to disable use
  pinMode(pwmA, OUTPUT);
  pinMode(pwmB, OUTPUT);
  digitalWrite(pwmA, HIGH);
  digitalWrite(pwmB, HIGH);

  // Brakes off to disable use
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);

  // Stepper motor speed
  myStepper.setSpeed(MaxStepperSpeed);

  //Force stepper home, max, home then to center
  myStepper.step(-(MaxStepperPos+MinStepperPos));
  myStepper.step(MaxStepperPos);
  myStepper.step(-MaxStepperPos);
  CurStep = (MaxStepperPos-MinStepperPos)/2;
  myStepper.step(CurStep);
}


void loop() {
  int val;
  // Read the speed from the pot and map to 1 to MaxStepperSpeed
  val = map(analogRead(StepSpeedPot),0,1023,1,MaxStepperSpeed);
  myStepper.setSpeed(val);

  // Print details if user pressed button (no debouncing, don't care)
  if (!digitalRead(PrintPosButton)){
    Serial.print("Current Posiiton: ");
    Serial.println(CurStep);
    Serial.print("Step Speed: ");
    Serial.println(val);
    Serial.println();
  }

  // Read Switch 1 (Up)
  val = analogRead(SwitchUp);
  if (val>500){
    if (CurStep<MaxStepperPos){
      CurStep += 1;
      myStepper.step(1);
    }
  }

  // Read Switch 2 (Down)
  val = analogRead(SwitchDn);
  if (val>500){
    if (CurStep>MinStepperPos){
      CurStep += -1;
      myStepper.step(-1);
    }
  }

}

On boot up, the attached stepper should move to its home position, then to its max travel position, back to home then to center and await you to press the switch to move it up or down. I wrapped the switch code in travel limiting IF statements. It won't try to step beyond the max or below the min using the switch. Turn the pot to change the stepping speed from really freaking slow to its max. I used a map statement to map 0>1023 to 1>MaxStepSpeed. Open the serial monitor window and press the button and it will display the current movement step speed and its current position.

There really isn't any practical use for this script beyond learning connections and how to step a motor on the Motor Controller Shield. Feel free to comment additions, corrections or errata.