Hi ! Am working on stepper motor using Arduino UNO with V2 Motor shield. Am using 2 Stepper motor for doing raster scanning i.e Stepper1 motor just moves one step and stops till the stepper 2 reaches end of the scanning board i.e 15500steps and stops for sec till Stepper 1 moves one step and stops till Stepper 2 comes back to the same start position. I have the code below but problem is speed is too slow and i couldn't find any functions to increase the speed And also i have trouble putting in loop ..
void loop()
{
stepper1.run();
stepper2.run();
char letter = 'a';
switch (letter) {
case 'a':
stepper1.moveTo(10);// This is the main part like i explained above but its reducing the speed
delay(100); //
stepper2.moveTo(1000);//
step1spot=10;
step2spot=1000;
stepper1.moveTo(10);
delay(10);
stepper2.moveTo(-1000);
break;
}
if (stepper1.distanceToGo() == 0 && stepper2.distanceToGo() == 0) {
delay(1000);
stepper1.moveTo(-step1spot);
stepper2.moveTo(-step2spot);
stepper1.run();
stepper2.run();
}
}
And am also struggling to put the loops ...
Please do help me with this
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your entire code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Also post a link to the specs of your stepper motors.
Am working on stepper motor using Arduino UNO with V2 Motor shield.
That is a very poor choice for controlling stepper motors. A real stepper driver shield, per motor, would be a much better choice. Not only would you waste a lot less energy, but you'd be able to adjust the current supplied to each stepper motor, improving the torque and speed of the steppers.
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMSbot(0x61);
Adafruit_MotorShield AFMStop(0x60);
// Connect two steppers with 200 steps per revolution (1.8 degree)
// to the top shield
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);
void backwardstep1(){
myStepper1->onestep(BACKWARD ,DOUBLE);
}
void backwardstep11(){
myStepper1->onestep(BACKWARD ,DOUBLE);
}
void forwardstep2(){
myStepper2->onestep(FORWARD,MICROSTEP);
}
void backwardstep2(){
myStepper2->onestep(BACKWARD,MICROSTEP);
}
AccelStepper stepper1(backwardstep1, backwardstep11);
AccelStepper stepper2(backwardstep2,forwardstep2);
void setup()
{
AFMStop.begin();
AFMSbot.begin();
stepper1.setMaxSpeed(10000.0);
stepper1.setAcceleration(100.0);
stepper2.setMaxSpeed(10.0);
stepper2.setAcceleration(40.0);
}
void loop()
{
stepper1.run();
stepper2.run();
int step1spot = 0; //an experiment where i tried using stepspot variables to
int step2spot = 0; //keep track of motor location; probably unnecessary
char letter = 'a';
switch (letter) {
case 'a':
stepper1.moveTo(10);
delay(100);
stepper2.moveTo(1000);
break;
case'f';
stepper1.moveTo(10);
delay(10);
stepper2.moveTo(-1000);
break;
}
if (stepper1.distanceToGo() == 0 && stepper2.distanceToGo() == 0) {
delay(1000);
stepper1.moveTo(-step1spot);
stepper2.moveTo(-step2spot);
stepper1.run();
stepper2.run();
}
}
This is code am using , but speed is too slow .Let me know for any change or it would be great if someone can help me with the function through which i can increase the speed of motor
These 2 lines should not be inside any IF. They should just be in loop()
stepper1.run();
stepper2.run();
There should be no delay()s anywhere. The loop() function needs to be able to repeat as fast as possible in order to call stepper.run() as often a possible.
Have a look at how millis() is used to manage timing without blocking in Several things at a time.