Unable to compile: noob/stepper motor project

Folks,

I’m getting the following error messages:


sketch_dec10a.ino: In function ‘void loop()’:
sketch_dec10a:20: error: ‘motor’ was not declared in this scope

Using the following script:
/*
This code controls a stepper motor with the
EasyDriver board. It spins forwards and backwards
***************************/
int dirpin = 2;
int steppin = 3;

void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{

int i;

digitalWrite(dirpin, LOW); // Set the direction. LOW = CW, HIGH = CCW, DELAY = Run Time
delay(100);
motor.setSpeed(10); // Set the speed

for (i = 0; i<400; i++) // Iterate for 400 micro steps or 1 revolution
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // “Rising Edge” so the easydriver knows to when to step.
delayMicroseconds(3000000); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.

}

Please advise, and thanks for your time and help.

kdcnewyork: Folks,

I'm getting the following error messages:


sketch_dec10a.ino: In function 'void loop()':

sketch_dec10a:20: error: 'motor' was not declared in this scope

Using the following script: /* This code controls a stepper motor with the EasyDriver board. It spins forwards and backwards ***************************/ int dirpin = 2; int steppin = 3;

void setup() { pinMode(dirpin, OUTPUT); pinMode(steppin, OUTPUT); } void loop() {

int i;

digitalWrite(dirpin, LOW); // Set the direction. LOW = CW, HIGH = CCW, DELAY = Run Time delay(100); motor.setSpeed(10); // Set the speed

motor has not been declared in setup().

Thank you. How do I go about fixing that?

[/quote] motor has not been declared in setup().

[/quote]

kdc,

If you could provide the link to the code you copied, I could help you figure that part out…but if you want a quick answer…
lets say tho that you started here: http://arduino.cc/en/Reference/Stepper
then followed the link here: http://www.tigoe.net/pcomp/code/circuits/motors/stepper-motors/
Which got you the following copy/paste solution from Tom Igoe
(you should really read that whole page and make sure that your setup and driver matches everything they have there, or
you went to sparkfun and checked out their stepper motor drivers)

/*
 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     // change this depending on the number of steps
                           // per revolution of your motor
#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);
  }
}

You’ll prolly get it to work right. It took me a while to dig into stepper code and get it to work right with some crap I got off of dx.com. Now i’m spending money on the good drivers, everything works great, and fairly easy. If this is your first exposure to C plus plus, good luck. You might want to get a book on it. I did.