Hi,
I have done a bit of research but am still having some difficulty with this. I am new to arduinos and programming.
I Need to build a test fixture for work and don’t have a ton of time to figure everything out on my own.
What I need is to run 8 stepper motors at the same time, however at different speeds, I also need to be able to stop any one particular motor at any point (other motors can also be stopped at this point)
The items at my disposal are:
Arduino Uno
Arduino Mega
Several A3967 microstepping drivers
Several L298N Motor Control Modules
Nema 17 Stepper motors: http://cncsuperstore.com/index.php?route=product/product&product_id=60
Ideally I would like to use one Arduino Uno, and 8 Drivers
I would also like to be able to set the speed in RPM for each motor
The motors would need to be run indefinitely
This is the bit of code that I found to be the close to my application, however I cant make much of it out, especially because it refers to the accelstepper library. I do not need to vary the acceleration, I do not need to constantly switch rotation, and I need to be able to input my speed as RPM
CODE #1
#include <AccelStepper.h>
// Define two steppers and the pins they will use
AccelStepper stepper1(1, 9, 8);
AccelStepper stepper2(1, 7, 6);
int pos1 = 3600;
int pos2 = 5678;
void setup()
{
stepper1.setMaxSpeed(3000);
stepper1.setAcceleration(1000);
stepper2.setMaxSpeed(2000);
stepper2.setAcceleration(800);
}
void loop()
{
if (stepper1.distanceToGo() == 0)
{
pos1 = -pos1;
stepper1.moveTo(pos1);
}
if (stepper2.distanceToGo() == 0)
{
pos2 = -pos2;
stepper2.moveTo(pos2);
}
stepper1.run();
stepper2.run();
}
This is another bit of code that is close to what I need to do. However I also do not need the acceleration variable, or the reverse, and I need to set the speed to a constant RPM variable for each motor.
CODE #2
<
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper1 (1,3,2); // Defaults to 4 pins on 2, 3, 4, 5
AccelStepper stepper2 (1,5,4); // Defaults to 4 pins on 2, 3, 4, 5
void setup()
{
}
void checkStepper(AccelStepper &astepper)
{ if (astepper.distanceToGo() == 0) {
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
astepper.moveTo(rand() % 12800);
astepper.setMaxSpeed((rand() % 3200) + 1);
astepper.setAcceleration((rand() % 6400) + 1); }
}
void loop()
{
checkStepper(stepper1) ;
checkStepper(stepper2) ;
stepper1.run();
stepper2.run();
}
The bit of code that I do understand is the basic stepper example from the arduino library. However the A3967 drivers only use two pins (this code worked with the L298N driver, because it uses 4 pins) However it is obviously for one stepper only, and my understanding that in order to drive two steppers I need to use the AccelStepper linbrary.
CODE #3
<
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one step:
myStepper.step(100);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(500);
}
I will continue to work on this and will update if I make any progress, however I would really appreciate any input
Thanks
Peter