Go Down

Topic: two steppers (Read 327 times) previous topic - next topic

mipumat

hi i wrote the following code which turns one stepper one time and then (lets a led blink) and reverses - this loops. i am learning my way through...

would anybody be so nice and explain to me how i can drive two steppers independently at the same time? for example i would have another easydriver connected to pins 4, 5 and would like to have this stepper turn only half while the original stepper turns like before.

Code: [Select]
// Schrittmotorsteuerung mit Easydriver Library
// MiPu 2011
//
// Motor 200 schritte/umdrehung, 8 fach microstepping -> 1600 schritte / umdrehung


int dirPin = 2;
int stepperPin = 3;
int LEDPin = 13;

void setup() {
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
  pinMode(LEDPin, OUTPUT);
}

void step(boolean dir,int steps, int stp_int){
  digitalWrite(dirPin,dir);
  delay(50);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(stp_int);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(stp_int);
  }
}

void loop(){
  step(true,1600,3000);          // 1 umdrehung in 5 sekunden
 
  digitalWrite(LEDPin, HIGH);   // LED einschalten
  delay(3000);                  // 1 sekunde warten
  digitalWrite(LEDPin, LOW);    // LED ausschalten
   
  step(false,1600,3000);        // 1 umdrehung zurück in 5 sekunden

  digitalWrite(LEDPin, HIGH);   // LED einschalten
  delay(3000);                  // 1 sekunde warten
  digitalWrite(LEDPin, LOW);    // LED ausschalten
 
}


it would be great if somebody could help. have a nice day.

PaulS

If the stepper motors needed to be turned by hand, and the LEDs needed to be switched by hand, how would you do it? Would you use an egg timer (delay()) that you had to watch closely, or would you use a watch (millis()) that you looked at now and then?

This question gets asked pretty regularly. The answer is always the same. Get rid of the calls to delay(). Look st the blink without delay example for how, and search the forum for some of the previous threads on the topic.

mipumat

thank you for the great hint "blink without delay". this makes sense. i will try to understand this. thanx again.

Go Up