Pages: [1]   Go Down
Author Topic: Non-blocking Stepper motor  (Read 1237 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

}

« Last Edit: April 09, 2012, 04:08:11 am by aelkhalil » Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Checkout the AccelStepper library.
Logged

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

Ontario
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Logged

Peter

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

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

here is the code I wrote.

Code:
#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...
Logged

Pages: [1]   Go Up
Jump to: