Non-blocking Stepper motor

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. :roll_eyes:

obviously this code doesn’t work…

#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);  
  

}

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.

Checkout the AccelStepper library.

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

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

In the future, to help you find code that does this kind of thing (whether for steppers or otherwise), the term is "non-blocking"...

Thanks for the help but I’m still stuck…

here is the code I wrote.

#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…

Did you find any solution?

You have reactivated a 5 year old thread!!

MarkT: You have reactivated a 5 year old thread!!

Haha!

i am activating 3 years old thread :)

i need a non blocking code/library for esp8266

See reply #2.