Hi,
Not sure if this is the right place but I modified AccelStepper library by Mike McCaulay to work with 28byj-48 motors.
To use it simply define the motor in sketch as follows AccelStepper stepper(5, pin1, pin2, pin3, pin4);
Where ‘5’ is the interface type for the 28byj-48 motor. The pins are just whatever pins you want to use. The library didn’t use number 5 at all so it has its full functionality plus support for 28byj-48 motor.
In case you’ve never used the original library it is pretty awesome as it allows adding more than one stepper and supports acceleration. So now you have it - you can drive more than one 28byj-48 motor.
Here is an example code I am using in the video:
#include <AccelStepper.h>
// Define some steppers and the pins the will use
AccelStepper stepper1(5, 2, 3, 4, 5);
// The first argument '5' indicates that we're using a 28byj-48 geared motor. The rest is just pin numbers.
//You can still use all the other types of motors supported by accelstepper library (e.g. 4 for a normal 4 wire step motor, 8 for a halfstepped normal 4 wire motor etc.)
AccelStepper stepper2(5, 6, 7, 8, 9);
void setup()
{
stepper1.setMaxSpeed(900.0); //max speed of the first motor - modify if you want to
stepper1.setAcceleration(700.0); // rate at which the first motor accelerate -
stepper2.setMaxSpeed(700.0);
stepper2.setAcceleration(400.0);
}
void loop()
{
if (stepper1.distanceToGo() == 0){
stepper1.moveTo(random(1500,7000));//just an easy way to get the motors to move to random positions
}
if (stepper2.distanceToGo() == 0){
stepper2.moveTo(random(1500,7000));
}
stepper1.run();
stepper2.run();
}
What do you think?
Mind you that you have to be logged in to see the attachments and download the modified library. Otherwise you can’t even see that the files are here.
To install just copy and paste the two files into AccelStepper library folder and they will replace the original files ( you need both AccelStepper.cpp and AccelStepper.h ).
AccelStepper.cpp (14.6 KB)
AccelStepper.h (32.9 KB)