AccelStepper stop() problem -RESOLVED

Hi,

I am learning and testing and i have the following problem.
This code make a stepper turn and stop at some define positions. My problem is that when the loop end(so i think) the motor return to the starting position and do all the steps again. For this reason i want to stop it using the stop() you see at the end.

This stop produce an error in compiling!

What do i do wrong since the AccelStepper doc mention this stop()

Also from where should i call the loop to have the process done only one time?

Thank for any help for this new user.

#include <AccelStepper.h>
 
int motorSpeed = 2500;
int motorAccel = 600;
 
int motorDirPin = 2; //digital pin 2
int motorStepPin = 3; //digital pin 3
int x;
int POSstp;
 
int led = 11;
int led1 = 8;
 
//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper stepper(1, motorStepPin, motorDirPin);
 
 
void setup(){
stepper.setMaxSpeed(motorSpeed);
stepper.setSpeed(motorSpeed);
stepper.setAcceleration(motorAccel);
 pinMode(led, OUTPUT);   
 pinMode(led1, OUTPUT);
 Serial.begin(9600);
}
 
 
void loop(){
  x =  stepper.currentPosition(); 
 
  while (x < 3200) {
     Serial.println(x);
     stepper.runToNewPosition(x);
     digitalWrite(led, HIGH);  
     digitalWrite(led, LOW);   
   
 
     x = x + 800; // diff between each stop
 
 
}
 
stepper.stop();
 
}

The point of the loop() function is that it is called repeatedly. Your loop goes to some position then iterates to a second position, then returns. Loop() is then called again, it goes back to the initial position, ad infinitum.

If you want your sketch to stop outright after completing a single task, you must either put it into an infinite loop or shutdown the CPU.

Or put the code that is to run once and stop in setup() and have loop() {} empty.

If the code must go in loop() just have a global variable that starts as "false" and changes to "true" when the motor has run. Don't run the motor if the value of that variable is "true".

...R

Thanks this is clear now.

Do anyone have an idea why the AccelStepper stop() function do not compile and generate an error saying that it doesn't exist?

lou123a:
Do anyone have an idea why the AccelStepper stop() function do not compile and generate an error saying that it doesn't exist?

Not unless you post your code and the error message.

A typo is a good guess - perhaps lower case when there should be upper case?

Study the relevant example code and compare it with your own.

...R

Hi,
The code is the code at the begining of this thread.

The error i get is:

'class AccelStepper' has no member named 'Stop'

I noted that the error write stop with a cap S, but if I change stop() to Stop() the error remains the same.

All other such as stepper.run(), etc work fine and the code compile without any problem. I checked online tutorial and my code is very similar. If i cut and paste the tutorial examples i find, if there is stop() in it, it will not compile.

So ???? I really cannot figure this one.

For the other suggestion regarding the loop, i made the changes and all is fine.

Do you perhaps have an outdated copy of AccelStepper? Either way, open the header file and look for a stop method in the declared class. If it's not there, it's not there.

I just downloaded the file but that make a lot of sense. Will look at this tomorrow and see how old is my version.
Thanks

Have you any reason (such as example code from somewhere or the Accelstepper website) to think that the library does have a Stop/stop function?

...R

Actually no. As I am learning so i assume that if it is on the AccelStepper website sample code it is something that i can use or at least exist.

lou123a:
Actually no. As I am learning so i assume that if it is on the AccelStepper website sample code it is something that i can use or at least exist.

We can't offer help against thin air. Show us the example code and show us your code.

...R

This is my code (removed all non-relevant parts)
It will compile if I REM out the stepper.stop(); line

If I use the stop(), I get the following error when i compile:

‘class AcceStepper’ has no member named ‘stop’

I opened the AccelStepper.h and it doesn’t show any stop() member. This would explain why I get the error!

But If I take the tutorial sample from the AccelStepper site, it clearly show the usage of the stop(), but it doesn’t compile on my machine either, and I get the same error.

It looks like I need to have a library with the member stop(), but if the author site doesn’t have it, where should I get it? And if I get a library with it should I reinstall all the Arduino, and library, or it will just copy over the ‘bad’ one?

I guess this is the problem, not the code.

In any case this is the code I have and the sample from teir site

#include <AccelStepper.h>

 

 

int motorSpeed = 2500; //maximum steps per second (about 3rps / at 16 microsteps)

int motorAccel = 600; //steps/second/second to accelerate

 

int motorDirPin = 2; //digital pin 2

int motorStepPin = 3; //digital pin 3

int x;

 

int led = 11;

int led1 = 8;

 

//set up the accelStepper intance

//the "1" tells it we are using a driver

AccelStepper stepper(1, motorStepPin, motorDirPin);

 

void setup(){

stepper.setMaxSpeed(motorSpeed);

stepper.setSpeed(motorSpeed);

stepper.setAcceleration(motorAccel);


 pinMode(led, OUTPUT);    // moke up for flash

 

}

void loop(){
//if stepper is at desired location

x =  stepper.currentPosition(); 

 while (x < 3200) {

      stepper.runToNewPosition(x); //move 32000 steps (should be 10 rev);

      delay(3000); // Stay there for process to occur

      x = x + 800;

  }

 

     // Indicate process is done and motor should stop

      digitalWrite(led, HIGH);  

         delay(200);

      digitalWrite(led, LOW);  

 

  // if the following is used in the code, code will not compile

      // stepper.stop();    // <<==== would stop the motor

 

}

Accelstepper code sample

#include <AccelStepper.h>

AccelStepper stepper;

void setup()

{    stepper.setMaxSpeed(150);  stepper.setAcceleration(100);}

void loop()

  { 

    stepper.moveTo(500);

  while (stepper.currentPosition() != 300) // Full speed up to 300    stepper.run(); 

stepper.stop(); // Stop as fast as possible: sets new target 

stepper.runToPosition(); 

// Now stopped after quickstop

// Now go backwards 

stepper.moveTo(-500); 

while (stepper.currentPosition() != 0) // Full speed basck to 0   

stepper.run(); 

stepper.stop(); // Stop as fast as possible: sets new target 

stepper.runToPosition();   // Now stopped after quickstop

}

i found the problem.
The library i was using was an old one, so it didn't have the member in it.
Thanks all for helping me on that one.

while it's good that you found the newer version of AccelStepper, could you please let me (us) know where you found the newer version? i've been looking around (have the same problem) and have yet to find the one with the 'stop()' and other functions!

thanks in advance,
Russ from Coral Springs, Fl

rholt:
while it's good that you found the newer version of AccelStepper, could you please let me (us) know where you found the newer version? i've been looking around (have the same problem) and have yet to find the one with the 'stop()' and other functions!

thanks in advance,
Russ from Coral Springs, Fl

I have the same problem, so i need also the new version of this librarie, i just found the older one :frowning:

You are asking a question in a 3-years dead Thread.

Have you downloaded the library from the AccelStepper website?

If that does not solve your problem start a new Thread and explain your problem in detail including posting your program.

...R

Hello everyone

I'm new at programming in any library... So I would like someone help me to make a simple movement with two motors steppers.

What the steppers need to do:

Stepper1: move 260 pulses and stop (wait until the second stepper finish its movement);
Stepper 2: move 200 pulses Clockwise; move 200 pulses Counter clockwise;

Repeat this till the end switch enable;

When the EndSwitch is enable, Stepper1 back to inicial position.

Thaaaanks guys!

@AndrewRatzkob, I already answered your question in your other Thread. Please don't waste our time by double-posting the same question.

...R