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!
AccelStepper + Adafruit Motor shield for multiple steppers!
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
- douglasmauro
- Posts: 15
- Joined: Fri Feb 19, 2010 4:41 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
Does this support NON-Blocking?
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
it supports everything that accelstepper supports
- douglasmauro
- Posts: 15
- Joined: Fri Feb 19, 2010 4:41 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
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.
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.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
thats the default action
-
- Posts: 19
- Joined: Sat Aug 28, 2010 10:41 am
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
6000 kinds of awesome!
- douglasmauro
- Posts: 15
- Joined: Fri Feb 19, 2010 4:41 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
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
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
// 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);
}
}
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
nice ! glad to see its working out for people
-
- Posts: 19
- Joined: Sat Aug 28, 2010 10:41 am
Re: AccelStepper + Adafruit Motor shield for multiple steppers!
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.
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.
Please be positive and constructive with your questions and comments.