AccelStepper. How to make step by step movement (Option On/Off button)

538 views
Skip to first unread message

mat_dudi

unread,
Apr 12, 2017, 7:57:40 AM4/12/17
to accelstepper
Hi, how to make the 2 stepper motor (28byj-48) rotate at the same time step by step?

I use 2 stepper motor 28BYJ-48 and want to rotate forward at same time (CW n CCW) but at some step (about 50 degree rotation). The flow begin when I push 'On' a push button and it suppose to light up the LED and also make the stepper rotate. HOWEVER, the stepper keep making full rotation and not step by step. Any idea?

I already make some coding, and it working(stepper rotate, LED light up, On/Off push button) but not what I planned it to work. Everything are okay EXCEPT for rotating step by step,
Here are my coding:

#include <AccelStepper.h>

//some define,variable here//

int ledState = LOW;
int motorEnabled = 0;
boolean buttonState = LOW;
boolean previousButtonState = LOW;

void setup()      /****** SETUP: RUNS ONCE ******/    
{ stepper1.setMaxSpeed(2000.0);
  stepper1.setAcceleration(8000.0);
  stepper1.setSpeed(1000);
   
  stepper2.setMaxSpeed(2000.0);
  stepper2.setAcceleration(8000.0);
  stepper2.setSpeed(1000);
       
  // Set for push button and LED
  pinMode(buttonPin, INPUT);    // set push button as input
  pinMode(ledPin, OUTPUT);      // set LED as output
} //--(end setup )---

void loop()     /****** LOOP: RUNS CONSTANTLY ******/ 
{
  buttonState = digitalRead(buttonPin);
  
  if(previousButtonState != buttonState && buttonState == HIGH){
    motorEnabled = !motorEnabled;
    }
  if(motorEnabled == 1){
    digitalWrite(ledPin, HIGH);
      stepper1.move(500); // rotate about 50 degree CW
      stepper2.move(-500); // rotate about 50 degree CCW
  } 
  else{
    digitalWrite(ledPin, LOW);
    stepper1.stop();
    stepper2.stop();
    }
    
  stepper1.run();
  stepper2.run();    

  previousButtonState = buttonState;
  digitalWrite(ledPin, ledState);
}

Francois Dinel

unread,
Apr 13, 2017, 9:10:15 AM4/13/17
to accelstepper
Hi,

You would use "AccelStepper::targetPosition()"

Take some time and read all documentation on the class definition http://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html

Best regards

mat_dudi

unread,
Apr 14, 2017, 3:00:01 PM4/14/17
to accelstepper
Hi, Franck63. 

Can you explain about that function and give some example please.. I already read those link and find other but not understand well.TQ
Reply all
Reply to author
Forward
0 new messages