1

I am quite new to this , I am trying to program two motors , aStepper and bStepper. I want the program to rotate aStepper then rotate the bStepper and when that is done rotate aStepper again , and then repeat. The first iteration works fine.However, it only does the loop once and the bStepper doesn't rotate again.

Am I doing something wrong with the loop?

(aStepper is the UNIPOLAR 28BYJ-48 connected to its driver , and bStepper is a Nema 17 connected to A4988)

#include <AccelStepper.h>  
#include <Stepper.h>

#define StepsPerRotation 2038 

#define dirPin 2      
#define stepPin 3
#define motorInterfaceType 1

AccelStepper bStepper = AccelStepper(motorInterfaceType, stepPin, dirPin); 
Stepper aStepper(StepsPerRotation, 8, 10, 9, 11);


void setup() {

  bStepper.setMaxSpeed(200);  
  bStepper.setAcceleration(30);
}

 void loop() {

   aStepper.setSpeed(20);
   aStepper.step(1016);

   bStepper.moveTo(-6000);   
   bStepper.runToPosition(); 

   aStepper.setSpeed(20);
   aStepper.step(-1016);
}

Thank you in advance

A'dam
  • 11
  • 1
  • How should `bStepper` move again after the first time? You directed it to go to position -6000, so it will go to -6000 on the first run. On the second it already is there, so further movement – chrisl Nov 22 '19 at 13:50
  • Oh , I thought after it completes the loop it would just run again. How can i better approach this? with bstepper.runSpeed(); instead? – A'dam Nov 22 '19 at 13:54

0 Answers0