Go Down

Topic: Non-blocking Stepper motor (Read 1 time) previous topic - next topic

aelkhalil

Apr 05, 2012, 02:07 pm Last Edit: Apr 09, 2012, 11:08 am by aelkhalil Reason: 1
Hi,

I need to have my stepper motor continuously run while my arduino takes care of doing other tasks.

I am using the 28BYJ28 stepper with a geeetech stepper motor drive
http://www.ebay.com/itm/Arduino-Stepper-Motor-5V-4-Phase-5-Wire-Driver-Board?item=280706173833&cmd=ViewItem&_trksid=p5197.m7&_trkparms=algo%3DLVI%26itu%3DUCI%26otn%3D4%26po%3DLVI%26ps%3D63%26clkid%3D7504698665209464815#ht_4923wt_830

Basically I am using this motor to rotate a large wheel at a constant speed of 1 RPH. in the meantime, the arduino board needs to take various readings and do tasks, but for simplicity purposes, let say it need to blink an LED without stopping the rotation of the motor.  :smiley-roll:

obviously this code doesn't work...
Code: [Select]
#include <Stepper.h>

Stepper mainwheel(200, 11,9,10,8);      


void setup() {
 // set the speed at 60 rpm:
 mainwheel.setSpeed(100);
  pinMode(13, OUTPUT);  
}

void loop() {

 mainwheel.step(1000);
 
   digitalWrite(13, HIGH);  
 delay(1000);              
 digitalWrite(13, LOW);    
 delay(1000);  
 

}



wildbill

Move the stepper in steps of 1 and use millis to decide when to do so. millis can also help you control the led. Or, look at the blink without delay example and add some stepper code to it.

MarkT

[ I won't respond to messages, use the forum please ]

pbechard

Like MarkT suggested, the AccelSteppher.h library will help. 

Look for these commands:
stepper1.moveTo(4000);
stepper1.run();

Peter

Arduino and electronics newbie... but enjoying what I'm learning

cr0sh

In the future, to help you find code that does this kind of thing (whether for steppers or otherwise), the term is "non-blocking"...
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

aelkhalil

Thanks for the help but I'm still stuck..

here is the code I wrote.

Code: [Select]
#include <AccelStepper.h>

AccelStepper stepper1(4, 11, 9, 10, 8);

void setup()

    stepper1.setSpeed(50);

    stepper1.moveTo(40000);
      pinMode(13, OUTPUT);

}

void loop()
{

    stepper1.run();

      digitalWrite(13, HIGH); 
  delay(1000);             
  digitalWrite(13, LOW);   
  delay(1000);   
}



the LED blinks well but the motor nada...

Go Up