Accel_Stepper Library?

Hi all,

I am working on operating a stepper motor using an arduino uno. My goal is the be able to push and button and have the motor rotate cw to a specific position, stop, and than return to its initial position. The problem I am having is controlling the speed. I have done research and the motor that I had laying around can’t reach the desired rpm’s so I have another motor on the way. In the mean time, I would like to fix my code so I have better control over the speed of the motor. I have read that the accelstepper library is what I need but when I try to run a basic AccelStepper code I get an error saying its a bad file. Any suggestions?
Thanks!

int switchPin = 12;
int dirPin = 8;
int stepPin = 7;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean motorOn = false;


void setup() {
  pinMode (switchPin, INPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT); 
  digitalWrite(dirPin, LOW);
  digitalWrite(stepPin, LOW);
  Serial.begin(9600);
}


boolean debounce(boolean last) 
{
  boolean current = digitalRead(switchPin);  
  if (last != current)  
  { 
    delay(5);
    current = digitalRead(switchPin); 
  }
  return current; 
}

void loop() 
{
  currentButton = debounce(lastButton);  
    if (lastButton == LOW && currentButton == HIGH) 
  {
int n=1;
  
  while (n<=800){  
  Serial.println(n);

  digitalWrite(dirPin, HIGH);
  delayMicroseconds(100);  
  digitalWrite(dirPin, LOW);
  delayMicroseconds(100);
  n=n+1;
  }
  delay(2000);
  int j=1;
  while (j<=800){  
  Serial.println(j);
 
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(1000);
  j=j+1; 
  }
}
}

but when I try to run a basic AccelStepper code I get an error saying its a bad file.

I doubt that.

Any suggestions?

Post your exact messages.

Sorry, not a bad file, a file that doesn't exist.

Build options changed, rebuilding all Accel_Stepper.ino:1:26: fatal error: AccelStepper.h: No such file or directory compilation terminated. Error compiling.

The following is the code that I used for it.

#include "AccelStepper.h"

Stepper stepper(200, 9, 8);
int pos = 3600;

void setup() {
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(1000):

}

void loop() {
  if (stepper.distanceToGo() == 0)
  [
  delay(500);
  pos = -pos;
  stepepr.moveTo(pos);
  ]
  stepper.run();

}
[code]

[/code]

Have you downloaded and installed the AccelStepper library ?

It is not a standard library.

...R

Yeah I did. I pop-up window shows up when I try to open it and says "Arduino can only open its own sketches and other files ending in .ino or .pde". Than when I try to include it in a code the error saying there is no such file appears.

What version of the IDE are you using and where have you installed the library ?

...R

I have 1.6.5 IDE. I downloaded the zip file than extracted it into the file that I have the sketches that I have made. Is there an arduino file for libraries that is part of the arduino program?

I figured out where the file needs to be and the program runs it now. Is the accelstepper library the best way to control speed and positioning for a stepper motor? I also thought about trying to use a pwm code? thoughts?

RG22: I also thought about trying to use a pwm code? thoughts?

PWM has nothing to do with stepper motors.

If you are using a stepper motor driver that just needs step and direction signals you can easily write your own code. See this simple stepper code.

The AccelStepper library is valuable if you are using a h-bridge to control the stepper (which I don't recommend) or if the acceleration feature is important to your project. It is not suitable if you want to coordinated movement of two or more steppers such as would be required for CNC or 3D printing.

...R Stepper Motor Basics

Thanks for the links. I've read a bunch of forums to control stepper motors but the forum that you have posted has cleared up my confusion. ' Thank you for the help! Much appreciated!

RG22: Thanks for the links. I've read a bunch of forums to control stepper motors but the forum that you have posted has cleared up my confusion. ' Thank you for the help! Much appreciated!

Thank you for your kind words.

...R