Reference.Stepper History

Show minor edits - Show changes to markup

May 08, 2012, at 10:44 AM by Tom Igoe -
Changed lines 3-4 from:

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.

to:

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.

Changed line 19 from:
to:
May 22, 2008, at 04:39 AM by David A. Mellis -
Changed line 19 from:
to:
October 06, 2007, at 06:15 AM by David A. Mellis -
Changed lines 3-4 from:

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.

to:

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.

May 17, 2007, at 06:48 PM by David A. Mellis -
Changed lines 17-91 from:


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 and 9 of the Arduino.

 The motor moves 100 steps in one direction, then 100 in the other.

 Created 11 Mar. 2007
 Modified 7 Apr. 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 motorSteps 200
#define motorPin1 8
#define motorPin2 9
#define ledPin 13

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

void setup() {
  // 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);
}

void loop() {
  // Step forward 100 steps:
  Serial.println("Forward");
  myStepper.step(100);
  delay(500);

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

}


// 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);  
  }
}


to:

Example

May 17, 2007, at 06:24 PM by David A. Mellis -
Changed lines 7-9 from:
to:
May 17, 2007, at 06:24 PM by David A. Mellis -
Added lines 5-9:
Added line 18:
Deleted lines 19-27:

Example circuits:

Unipolar Stepper:

  

Bipolar Stepper: Attach:bipolar_stepper.png Δ


May 17, 2007, at 05:13 PM by David A. Mellis -
Changed lines 12-14 from:

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

to:

Example circuits:

Unipolar Stepper:

  

Bipolar Stepper: Attach:bipolar_stepper.png Δ


Example program:

Changed lines 26-80 from:

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

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.

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

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).

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

myStepper.setSpeed(60); // 60 rpms

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.

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

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.

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

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



Example circuits:

Unipolar Stepper:

  

Bipolar Stepper: Attach:bipolar_stepper.png Δ


Example program:

[@

to:
Deleted lines 94-96:

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

May 17, 2007, at 04:37 PM by David A. Mellis -
Changed lines 10-11 from:
to:
May 16, 2007, at 05:44 PM by David A. Mellis -
Added lines 5-10:

Functions

May 16, 2007, at 05:41 PM by David A. Mellis -
Added lines 1-133:

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.

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

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

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.

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

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).

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

myStepper.setSpeed(60); // 60 rpms

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.

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

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.

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

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



Example circuits:

Unipolar Stepper:

  

Bipolar Stepper: Attach:bipolar_stepper.png Δ


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 and 9 of the Arduino.

 The motor moves 100 steps in one direction, then 100 in the other.

 Created 11 Mar. 2007
 Modified 7 Apr. 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 motorSteps 200
#define motorPin1 8
#define motorPin2 9
#define ledPin 13

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

void setup() {
  // 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);
}

void loop() {
  // Step forward 100 steps:
  Serial.println("Forward");
  myStepper.step(100);
  delay(500);

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

}


// 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);  
  }
}



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

Share