stop and move stepper.

sorry for writing this stupid question.... I have a stepper motor and want move it forward and backwards. I used this patch and it works. But it doesn't make a break. Does anybody could help me? I thought that I just have to insert "stepper1.delay(500)". But this doesn't work. Would be fantastic if somebody could help me. I just want to stop the motor for 5 seconds before moving backwards. Thanks

// MultiStepper
// -*- mode: C++ -*-
//
// Control both Stepper motors at the same time with different speeds
// and accelerations. 
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper)
// Public domain!

#include <AccelStepper.h>
#include <AFMotor.h>

// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {  
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep1() {  
  motor1.onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {  
  motor2.onestep(FORWARD, SINGLE);
}
void backwardstep2() {  
  motor2.onestep(BACKWARD, SINGLE);
}

// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()
{  
    stepper1.setMaxSpeed(200.0);
    stepper1.setAcceleration(100.0);
    stepper1.moveTo(240);
    
    stepper2.setMaxSpeed(300.0);
    stepper2.setAcceleration(100.0);
    stepper2.moveTo(1000000);
  }

void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());
    stepper1.run();
    stepper2.run();
}

No, if you want it to wait you'll have to start looking at the clock with millis() - the condition for
restarting to move must involve time, not just input state.

dreimanneins:
I thought that I just have to insert "stepper1.delay(500)". But this doesn't work. Would be fantastic if somebody could help me. I just want to stop the motor for 5 seconds before moving backwards. Thanks

Maybe you could try putting : delay(5000);

between stepper1.run(); and stepper2.run();

Such as:

stepper1.run();
delay(5000);
stepper2.run();

hello, i'm interested in the same topic. Does anybody has an idea. Because southparks idea does not work. Or MarkT. could you please describe it in detail - i do not understand it?

Is there a chance to stop the motor with the adafruit motor shield (version 1)? Would be happy if anybody could help me.
Thanks!

Ok.... after taking a look at what this library does..... it looks like we got to find the stop command.

I searched the net but haven't yet found a document that provides a clearcut rundown on the library commands.

Somewhere in the code..... we just need to get in there and command the motor to stop obviously. Maybe just to try... put a command like this in the main loop.

Stepper1.release();
delay(5000);

Or even...

Stepper1.setSpeed(0);
delay(5000);
Stepper1.setSpeed(10);

thanks for your reply, but it looks like nothing of this works. I tried all commands, but it will not stop. I also searched the internet and i couldn't find a useful information... :frowning: hhhhhmmmm....

I'm thinking that..... before using a software, or anything (eg. driving a motor, or driving a car, or riding a bike, or ice skating, or skiing etc), it's important to not just learn how to 'run' or 'move', but also learn how to stop. Before making the motor move.... understand or know what command is needed to make things stop before allowing it to run.

Well, at least we have access to the on-off switch for emergency stops.

What we got to do now is to get a manual for this library that tells us the command to make the motor stop on our software command.

Anybody have a proper manual for this library? What I mean by that is.... clear cut instructions (documentation) that describes each command, and what each parameter in the command (function) actually means - and what it actually does.

Back again. Looks like other people had been looking for a stop function.

http://forum.arduino.cc/index.php?topic=239806.0

found the library with the stop func:
http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.45.zip

Can you give us wiring setup or driver used or derails about arduino board you have used ....????

if you really need to use delay, you can do it like this (but it's dirty):

void loop() {
  stepper1.moveTo(stepamount);
  stepper1.run();
  if (stepper1.distanceToGo() == 0) {
    stepamount = stepamount + steps;
    delay(500);
    loop();
  }

}

you can set up the ints like that:

int stepamount = 400;
int steps = stepamount;

and in setup:

void setup() {
stepper1.setMaxSpeed(5000.0);
stepper1.setAcceleration(100.0);
stepper1.setSpeed(600);

}

this will make the stepper turn 400 steps, make it wait 500ms and make it turn another 400 steps.

If you need it to turn the opposite direction every second time, you can simply make the stepamount negative in the loop by adding an int in a while-loop and check if it is even or odd, when it is even, just add a "-" in front of stepamount in the moveTo-function, then the motor will turn back to the previous position.

But again: this is very dirty code, because normally you have to do it with Millis - but it works:

#include <AccelStepper.h>
#define HALFSTEP 8
 
int stepamount = 400;
int steps = stepamount;
int i = 0;
 
AccelStepper stepper1(HALFSTEP, 5,6,7,8);
 
void setup() {
  stepper1.setMaxSpeed(5000.0);
  stepper1.setAcceleration(100.0);
  stepper1.setSpeed(600);
 
}//--(end setup )---
 
void loop() {
  stepper1.moveTo(stepamount);
  stepper1.run();
  if (stepper1.distanceToGo() == 0) {
    if (i % 2) {
    stepamount += steps;
    }
    else {
      stepamount -= steps;
    }
    delay(500);
    i++;
  }
    loop();
  

}