Stepper motor stop

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
martin112
 
Posts: 8
Joined: Mon Mar 14, 2016 11:45 am

Stepper motor stop

Post by martin112 »

I want to use this sketch and would like to expand it

Code: Select all

#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(190.0);
    stepper1.setAcceleration(150.0);
    stepper1.moveTo(17);
    
    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();
}
the problem : I don't know how to stop the motor? it would be nice if the motor stops during the loop and resumes after it. Like:..... start - stop - start - stop,.....






I found something like this, but I miss the acceleration:

Code: Select all

#include <AFMotor.h>
  

AF_Stepper motor(100, 1);
 
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");
 
  motor.setSpeed(200);  // 10 rpm   
 
  motor.step(1000, FORWARD, DOUBLE); 
  delay(1000);
  motor.step(1000, BACKWARD, DOUBLE); 
  motor.release();
  delay(1000);
}
 
void loop() {
  motor.step(1000, FORWARD, DOUBLE); 
  delay(1000);
  motor.step(1000, BACKWARD, DOUBLE);
  delay(1000);
 
}
But in this version I miss the acceleration. Does anybody has an idea? The motor shield is version 1. Thanks and best regards---

User avatar
martin112
 
Posts: 8
Joined: Mon Mar 14, 2016 11:45 am

Re: Stepper motor stop

Post by martin112 »

does anybody can help me? That would help me a lot! I have the Adafruit motorshield V1.2. Just an idea how to stop the stepper? I tried it with commands like delay(); release(); ,......

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper motor stop

Post by adafruit_support_bill »

It looks like the second code you posted should run then stop then run and stop again.

User avatar
martin112
 
Posts: 8
Joined: Mon Mar 14, 2016 11:45 am

Re: Stepper motor stop

Post by martin112 »

thank you for your reply. Thats true - the second code works but it has no function for an acceleration. The motor starts and stops immediately.

I would like to use the acceleration library and just want to start / stop the stepper. There should be a possibility, or not?

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper motor stop

Post by adafruit_support_bill »

It should be possible. You can use the 'blocking' calls like RunToNewPosition(). See the AccelStepper documentation here: http://www.airspayce.com/mikem/arduino/ ... e39a6f0e67

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”