Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

AccelStepper + Adafruit Motor shield for multiple steppers!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AccelStepper + Adafruit Motor shield for multiple steppers!

by adafruit on Tue Jan 04, 2011 2:40 pm

I made some mods to AccelStepper to support AF_Motor
https://github.com/adafruit/AccelStepper
This allows fine control of steppers, acceleration and concurrent driving. Cool! Please check it out and let me know!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by douglasmauro on Wed Jan 05, 2011 10:23 am

Does this support NON-Blocking?
Douglas Mauro
TruePath Technologies Inc.
Phone: 585-672-5481
Email: dmauro@truepathtechnologies.com
Web: http://www.truepathtechnologies.com

douglasmauro
 
Posts: 15
Joined: Fri Feb 19, 2010 4:41 pm

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by adafruit on Wed Jan 05, 2011 12:32 pm

it supports everything that accelstepper supports

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by douglasmauro on Wed Jan 05, 2011 12:49 pm

I read the header/doc and it says

API functions never delay() or block

There's a nice *blocking* example but I don't see a non-blocking example :)

I've been looking for a way using my motor shield to run a stepper in background mode ... ie start the stepper and blink some lights while the stepper is still working away.
Douglas Mauro
TruePath Technologies Inc.
Phone: 585-672-5481
Email: dmauro@truepathtechnologies.com
Web: http://www.truepathtechnologies.com

douglasmauro
 
Posts: 15
Joined: Fri Feb 19, 2010 4:41 pm

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by adafruit on Wed Jan 05, 2011 1:46 pm

thats the default action

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by Euphy on Wed Jan 05, 2011 7:05 pm

6000 kinds of awesome!
Euphy
 
Posts: 19
Joined: Sat Aug 28, 2010 10:41 am

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by douglasmauro on Thu Jan 06, 2011 11:47 am

Here's a mash of 2 examples ... in short it shows us a non-blocking (random) movement with an LED that blinks every second. I wanted to use some INT but found this as an easier hack for now to blink the LED

Play around with the rand() lines to +/- the limits

Next step will be to wire up some POTS (danger shield?) for stepper control, direction, speed, accel, etc, etc :)

Code: Select all | TOGGLE FULL SIZE

// somecrazyname.pde
// -*- mode: C++ -*-
//
// mod'ed the AccelStepper Demo to show a non-blocking LED blink
// Douglas R. Mauro

#include <AccelStepper.h>
#include <AFMotor.h>

// change this to your settings that work for motorshield examples!
AF_Stepper motor1(48, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep() { 
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep() { 
  motor1.onestep(BACKWARD, SINGLE);
}

AccelStepper stepper(forwardstep, backwardstep); // use functions to step

const int ledPin =  13;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

void setup()

  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  stepper.setSpeed(50);
  pinMode(ledPin, OUTPUT);       
}

void loop()

  if (stepper.distanceToGo() == 0)
  {
    // Random change to speed, position and acceleration
    // Make sure we dont get 0 speed or accelerations
    stepper.moveTo(rand() % 1000);
    stepper.setMaxSpeed((rand() % 300) + 10);
    stepper.setAcceleration((rand() % 300) + 10);

  }
  stepper.run();
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Douglas Mauro
TruePath Technologies Inc.
Phone: 585-672-5481
Email: dmauro@truepathtechnologies.com
Web: http://www.truepathtechnologies.com

douglasmauro
 
Posts: 15
Joined: Fri Feb 19, 2010 4:41 pm

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by adafruit on Thu Jan 06, 2011 11:49 am

nice ! glad to see its working out for people

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: AccelStepper + Adafruit Motor shield for multiple steppers!

by Euphy on Fri Jan 07, 2011 8:36 pm

This is working rather sweetly for my http://www.instructables.com/id/Linear-Clock/ - thanks very very much for this fork. Simplifies the code nicely, and also means I can use more or less the same code if I decide to simplify the electronic design for production.

Still a few problems with over/understepping, but I think that's more to do with my mechanical design, or moving too fast than anything else. I'll do some more testing.
Euphy
 
Posts: 19
Joined: Sat Aug 28, 2010 10:41 am

Please be positive and constructive with your questions and comments.


cron