Tutorial.Stepper History

Hide minor edits - Show changes to markup

June 12, 2007, at 07:04 AM by David A. Mellis -
Added lines 1-2:
April 18, 2007, at 02:53 PM by Tom Igoe -
Changed line 5 from:

Version 0.4 can control unipolar or bipolar steppers using cicruits based on a darlington array circuit by Sebastian Gassner. Thanks to Sebastian for the additions. Thanks to David Mellis for the debugging help. Thanks to Noah Shibley for the bug catchon version 4.

to:

Version 0.4 can control unipolar or bipolar steppers using cicruits based on a darlington array circuit by Sebastian Gassner. Thanks to Sebastian for the additions. Thanks to David Mellis for the debugging help. Thanks to Noah Shibley for the bug catch on version 4.

April 18, 2007, at 02:53 PM by Tom Igoe -
Changed lines 6-7 from:

Download: Stepper.zip Δ

to:

Download: Stepper.zip

April 18, 2007, at 02:52 PM by Tom Igoe -
Changed lines 6-7 from:

Download: Stepper3.zip

to:

Download: Stepper.zip Δ

April 18, 2007, at 02:52 PM by Tom Igoe -
Changed lines 5-7 from:

Version 0.3 can control unipolar or bipolar steppers using cicruits based on a darlington array circuit by Sebastian Gassner. Thanks to Sebastian for the additions. Thanks to David Mellis for the debugging help. Download: Stepper.zip

to:

Version 0.4 can control unipolar or bipolar steppers using cicruits based on a darlington array circuit by Sebastian Gassner. Thanks to Sebastian for the additions. Thanks to David Mellis for the debugging help. Thanks to Noah Shibley for the bug catchon version 4. Download: Stepper3.zip

Changed lines 12-13 from:

As of version 0.3, here's what you can do:

to:

As of version 0.4, here's what you can do:

Added lines 50-57:

int version(); - return the version number of the library e.g.

Serial.println(myStepper.version()); // prints the version number


April 08, 2007, at 06:13 AM by Tom Igoe -
Added lines 30-31:

To determine the number of steps your motor uses, read the label or data sheet. It might tell you the step degrees. For example, a 1.8-degree stepper takes 200 steps per revolution (1.8 * 200 = 360 degrees).

Added lines 48-49:

Note: step() is a blocking function. This means that it stops all other code from running while it's completing the steps you asked for. For example, if you set the speed to be, say 1 RPM, and then called step(100) on a 100-step stepper, the function would take a full minute to run. To get better interactive control, step only short amounts, and keep the RPMs high.

April 08, 2007, at 06:04 AM by Tom Igoe -
Changed line 27 from:
                  //using pins 8 through 11
to:
                                      //using pins 8 through 11
April 08, 2007, at 06:00 AM by Tom Igoe -
Deleted line 5:
Changed lines 50-51 from:
width="550"
to:
  
Changed lines 53-54 from:
width="550
to:
April 08, 2007, at 05:58 AM by Tom Igoe -
Changed lines 51-52 from:
to:
width="550"
Changed lines 54-55 from:
to:
width="550
April 08, 2007, at 05:56 AM by Tom Igoe -
Changed lines 27-28 from:

Stepper myStepper(100, 8,9,10,11); // Initialize the Stepper library for a 100-step stepper using pins 8 through 11

to:

Stepper myStepper(100, 8,9,10,11); // Initialize the Stepper library for a 100-step stepper

                  //using pins 8 through 11
Deleted line 46:
Added lines 48-56:

Example circuits:

Unipolar Stepper:

Bipolar Stepper:


April 08, 2007, at 05:53 AM by Tom Igoe -
April 08, 2007, at 05:50 AM by Tom Igoe -
Changed lines 7-8 from:

Download: Stepper.zip Δ

to:

Download: Stepper.zip

April 08, 2007, at 05:49 AM by Tom Igoe -
Changed lines 7-8 from:

Download: Stepper.zip

to:

Download: Stepper.zip Δ

April 08, 2007, at 05:48 AM by Tom Igoe -
Changed lines 7-8 from:

Download: Stepper.zip Δ

to:

Download: Stepper.zip

April 08, 2007, at 05:46 AM by Tom Igoe -
Changed lines 7-8 from:

Download: Stepper2.zip

to:

Download: Stepper.zip Δ

April 08, 2007, at 05:45 AM by Tom Igoe -
Changed lines 7-8 from:

Download: Stepper.zip

to:

Download: Stepper2.zip

April 08, 2007, at 05:45 AM by Tom Igoe -
Added lines 5-6:

Version 0.3 can control unipolar or bipolar steppers using cicruits based on a darlington array circuit by Sebastian Gassner. Thanks to Sebastian for the additions. Thanks to David Mellis for the debugging help.

Changed lines 13-15 from:

As of version 0.1, this library has very limited functionality. Here's what you can do:

void Stepper() - initialize a Stepper.

to:

As of version 0.3, here's what you can do:

Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2); - initialize a Stepper for two-wire operation.

Changed line 19 from:

Stepper myStepper = new Stepper(); // initialize a new Stepper

to:

Stepper myStepper(200, 8,9); // Initialize the Stepper library for a 200-step stepper using pins 8 and 9

Changed lines 22-23 from:

void attach(int pin1, int pin2, int pin3, int pin4) - attach four digital I/O pins to the stepper, e.g.

to:

Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2int motor_pin_3, int motor_pin_4); - initialize a Stepper for four-wire operation. , e.g.

Changed line 27 from:

myStepper.attach(8,9,10,11); // Attach pins 8 - 11 to the Stepper instance

to:

Stepper myStepper(100, 8,9,10,11); // Initialize the Stepper library for a 100-step stepper using pins 8 through 11

Changed lines 30-31 from:

int speed - set the Stepper's speed. Speed means the delay between steps in milliseconds e.g.

to:

void setSpeed(long whatSpeed); - set the Stepper's speed, in revolutions per minute e.g.

Changed line 34 from:

myStepper.speed = 50; // 50 ms between steps

to:

myStepper.setSpeed(60); // 60 rpms

Changed lines 37-38 from:

int direction - set the motor's direction, 0 or 1. Physical direction depends on the way you wire the motor e.g.

to:

void step(int number_of_steps); - move the motor a number of steps. Direction depends on whether the number is negative or positive. e.g.

Changed lines 42-43 from:

myStepper.direction = 1; // direction = 1

to:

myStepper.step(100); // moves the stepper 100 steps forward myStepper.step(-100); // moves the stepper 100 steps backward

Changed lines 46-47 from:

void moveMotor(int numberOfSteps) - move the motor a number of steps. Direction depends on the Stepper.direction value. e.g.

to:

Example program:

Changed lines 51-69 from:

myStepper.moveMotor(3); // moves the stepper 3 steps @]

void stepMotor(int thisStep) - moves the stepper one step, using the actual step values 0 - 3. Only for folks who know how steppers really work and want low level access e.g.

myStepper.stepMotor(0); // sets the stepper pins to 1010
myStepper.stepMotor(1); // sets the stepper pins to 0110
myStepper.stepMotor(2); // sets the stepper pins to 0101
myStepper.stepMotor(3); // sets the stepper pins to 1001


Example program:

[@

to:
Changed lines 58-60 from:
 The motor is attached to digital pins 8 - 11 of the Arduino.
 A switch is attached to digital pin 3, and a potentiometer
 is attached to analog pin 0.
to:
 The motor is attached to digital pins 8 and 9 of the Arduino.
Changed lines 60-62 from:
 When the switch is pressed, the motor changes direction.
 The potentimeter controls the motor's speed, by changing the 
 delay between motor steps.
to:
 The motor moves 100 steps in one direction, then 100 in the other.
Deleted lines 61-62:
 The stepMotor() and moveMotor() methods can be used in other ways as well.
Added line 63:
 Modified 7 Apr. 2007
Changed lines 73-81 from:

// define the pin the switch is attached to.

  1. define switchPin 3

// define a sensitivity threshold for the analog input:

  1. define threshold 10

int sensorReading = 0; // reading from the sensor Stepper myStepper; // instance of the Stepper library

to:
  1. define motorSteps 200
  2. define motorPin1 8
  3. define motorPin2 9
  4. define ledPin 13

// initialize of the Stepper library: Stepper myStepper(motorSteps, motorPin1,motorPin2);

Changed lines 82-83 from:
  // attach the motor pins to the Stepper instance:
 myStepper.attach(8,9,10,11);
to:
  // set the motor speed at 60 RPMS:
  myStepper.setSpeed(60);

  // Initialize the Serial port:
  Serial.begin(9600);

  // set up the LED pin:
  pinMode(ledPin, OUTPUT);
  // blink the LED:
  blink(3);
Changed lines 95-106 from:

// read the analog sensor, convert to 0 a byte (0 - 255):

  int sensorReading = analogRead(0) /4;
  // if the sensor's changed more than the threshold since 
  // the last speed setting, change the speed:
  if (abs(myStepper.speed - sensorReading) > threshold) {
    myStepper.speed = sensorReading;
  }
  // read the switch, use it to set the direction:
  myStepper.direction = digitalRead(switchPin);
  // move the motor one step:
  myStepper.moveMotor(1);
to:
  // Step forward 100 steps:
  Serial.println("Forward");
  myStepper.step(100);
  delay(500);

  // Step backward 100 steps: 
  Serial.println("Backward");
  myStepper.step(-100);
  delay(500); 
Added lines 108-118:

// Blink the reset LED: void blink(int howManyTimes) {

  int i;
  for (i=0; i< howManyTimes; i++) {
    digitalWrite(ledPin, HIGH);
    delay(200);
    digitalWrite(ledPin, LOW);
    delay(200);  
  }

}

March 11, 2007, at 11:34 PM by Tom Igoe -
Changed lines 56-117 from:
to:

Example program:


/* 
 Stepper Motor Controller
 language: Wiring/Arduino

 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 8 - 11 of the Arduino.
 A switch is attached to digital pin 3, and a potentiometer
 is attached to analog pin 0.

 When the switch is pressed, the motor changes direction.
 The potentimeter controls the motor's speed, by changing the 
 delay between motor steps.

 The stepMotor() and moveMotor() methods can be used in other ways as well.

 Created 11 Mar. 2007
 by Tom Igoe

 */

// define the pins that the motor is attached to. You can use
// any digital I/O pins.

#include <Stepper.h>

// define the pin the switch is attached to.
#define switchPin 3

// define a sensitivity threshold for the analog input:
#define threshold 10

int sensorReading = 0;        // reading from the sensor
Stepper myStepper;            // instance of the Stepper library

void setup() {
  // attach the motor pins to the Stepper instance:
 myStepper.attach(8,9,10,11);
}

void loop() {
// read the analog sensor, convert to 0 a byte (0 - 255):
  int sensorReading = analogRead(0) /4;
  // if the sensor's changed more than the threshold since 
  // the last speed setting, change the speed:
  if (abs(myStepper.speed - sensorReading) > threshold) {
    myStepper.speed = sensorReading;
  }
  // read the switch, use it to set the direction:
  myStepper.direction = digitalRead(switchPin);
  // move the motor one step:
  myStepper.moveMotor(1);

}




March 11, 2007, at 11:33 PM by Tom Igoe -
Changed lines 13-18 from:

TextString(int strLength) - initialize a TextString of a given length e.g.

TextString myString = TextString(50); // makes a 50-byte long TextString

clear(void) - fill the TextString with zeroes, e.g.

to:

void Stepper() - initialize a Stepper. , e.g.

Changed line 17 from:

myString.clear(); // clears the string

to:

Stepper myStepper = new Stepper(); // initialize a new Stepper

Changed lines 20-21 from:

length(void) - get the length up to the first zero byte e.g.

to:

void attach(int pin1, int pin2, int pin3, int pin4) - attach four digital I/O pins to the stepper, e.g.

Changed line 23 from:

int stringLength = myString.length(); // gives the string length

to:

myStepper.attach(8,9,10,11); // Attach pins 8 - 11 to the Stepper instance

Changed lines 26-27 from:

equals( char *thatString) - compare your TextString to a given string, e.g.

to:

int speed - set the Stepper's speed. Speed means the delay between steps in milliseconds e.g.

Changed lines 29-31 from:

if (myString.equals("Hello")) {

   // compares myString to "Hello"

}

to:

myStepper.speed = 50; // 50 ms between steps

Changed lines 32-33 from:

contains(char *subString) - whether the TextString contains a given substring e.g.

to:

int direction - set the motor's direction, 0 or 1. Physical direction depends on the way you wire the motor e.g.

Changed lines 35-37 from:

if (myString.contains("Hello")) {

   // checks if myString contains the subString "Hello"

}

to:

myStepper.direction = 1; // direction = 1

Changed lines 38-39 from:

trim(void) - trim whitespace from both ends of the TextString. Removes any space characters, carriage returns, newlines, tabs, or vertical tabs. e.g.

to:

void moveMotor(int numberOfSteps) - move the motor a number of steps. Direction depends on the Stepper.direction value. e.g.

Changed line 41 from:

Serial.print(myString.trim()); // prints the trimmed version of myString

to:

myStepper.moveMotor(3); // moves the stepper 3 steps

Changed lines 44-45 from:

trimRight(void) - trim whitespace from the end of the TextString e.g.

to:

void stepMotor(int thisStep) - moves the stepper one step, using the actual step values 0 - 3. Only for folks who know how steppers really work and want low level access e.g.

Changed lines 47-48 from:

Serial.print(myString.trimRight()); // prints the version of myString trimmed on the end

to:

myStepper.stepMotor(0); // sets the stepper pins to 1010 myStepper.stepMotor(1); // sets the stepper pins to 0110 myStepper.stepMotor(2); // sets the stepper pins to 0101 myStepper.stepMotor(3); // sets the stepper pins to 1001

Changed lines 53-89 from:

trimLeft(void) - trim whitespace from the beginning of the TextString e.g.

Serial.print(myString.trimLeft());   // prints the version of myString trimmed from the beginning


setArray(char* thatString) - set the whole character array e.g.

myString.setArray("What's up Doc?");   // puts a string in the array


getArray(void) - get the whole character array e.g.

Serial.println(myString.getArray());   // prints the string

getCharAt(int charNum) - get a given character from the TextString e.g.

char thisChar = myString.getCharAt(5);   // gets the sixth character in the array

setCharAt(int charNum, char thisChar) - set a given charracter in the TextString e.g.

myString.setCharAt(5, 'A');   // sets the sixth character in the array to "A"

version(void) - get the library version. Since there will be more functions added, printing the version is a useful debugging tool when you get an error from a given function. Perhaps you're using an earlier version that doesn't feature the version you need! e.g.

Serial.println(myString.version());   // prints the version of the library 

to:
March 11, 2007, at 11:22 PM by Tom Igoe -
Added lines 1-97:

Stepper Library

This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. For more on that, see Tom Igoe's notes on steppers.

Download: Stepper.zip

To use, unzip it and copy the resulting folder, called Stepper, into the lib/targets/libraries directory of your arduino application folder. Then copy the examples folder from the Stepper folder to your Arduino code folder (the devault location is Documents/Arduino/). Then re-start the Arduino application.

When you restart, you'll see a few warning messages in the debugger pane at the bottom of the program. You can ignore them.

As of version 0.1, this library has very limited functionality. Here's what you can do:

TextString(int strLength) - initialize a TextString of a given length e.g.

TextString myString = TextString(50); // makes a 50-byte long TextString

clear(void) - fill the TextString with zeroes, e.g.

myString.clear();     // clears the string

length(void) - get the length up to the first zero byte e.g.

int stringLength = myString.length(); // gives the string length

equals( char *thatString) - compare your TextString to a given string, e.g.

if (myString.equals("Hello")) {
   // compares myString to "Hello"
}

contains(char *subString) - whether the TextString contains a given substring e.g.

if (myString.contains("Hello")) {
   // checks if myString contains the subString "Hello"
}

trim(void) - trim whitespace from both ends of the TextString. Removes any space characters, carriage returns, newlines, tabs, or vertical tabs. e.g.

Serial.print(myString.trim());   // prints the trimmed version of myString 

trimRight(void) - trim whitespace from the end of the TextString e.g.

Serial.print(myString.trimRight());   // prints the version of myString trimmed on the end


trimLeft(void) - trim whitespace from the beginning of the TextString e.g.

Serial.print(myString.trimLeft());   // prints the version of myString trimmed from the beginning


setArray(char* thatString) - set the whole character array e.g.

myString.setArray("What's up Doc?");   // puts a string in the array


getArray(void) - get the whole character array e.g.

Serial.println(myString.getArray());   // prints the string

getCharAt(int charNum) - get a given character from the TextString e.g.

char thisChar = myString.getCharAt(5);   // gets the sixth character in the array

setCharAt(int charNum, char thisChar) - set a given charracter in the TextString e.g.

myString.setCharAt(5, 'A');   // sets the sixth character in the array to "A"

version(void) - get the library version. Since there will be more functions added, printing the version is a useful debugging tool when you get an error from a given function. Perhaps you're using an earlier version that doesn't feature the version you need! e.g.

Serial.println(myString.version());   // prints the version of the library 


If anyone's interested in helping to develop this library further, please contact me at tom.igoe at gmail.com

Share