Go Down

Topic: can not get steppers to speed up. (Read 904 times) previous topic - next topic

nobikes

Nov 18, 2011, 10:03 pm Last Edit: Nov 18, 2011, 10:18 pm by CrossRoads Reason: 1
I have been playing around with some steppers and controlling them with buttons. an X+, X- , Y+, Y- button. i have got the code so i can jog around the 2 axis table but it is very slow. I am using .9 degree steppers, 400 steps per revolution. I have set the speed everywhere from 30 RPM to 10 000 RPM but the steppers never seem to move faster than 1 or 2 RPM.

Could some one look at my code and see if i am missing something?

Code: [Select]

#include <Stepper.h>

int button1 = 12;
int button2 = 13;
int button3 = 7;
int button4 = 2;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

const int stepsPerRevolution = 400;  

Stepper myStepper(stepsPerRevolution, 8,9,10,11);            
Stepper myStepper2(stepsPerRevolution, 3,4,5,6);

int stepCount = 0;  

void setup() {

 myStepper.setSpeed(1000);
 myStepper2.setSpeed(1000);

 pinMode (button1, INPUT);
 pinMode (button2, INPUT);
 pinMode (button3, INPUT);
 pinMode (button4, INPUT);

 Serial.begin(9600);
}

void loop() {
 buttonState1 = digitalRead(button1);
 buttonState2 = digitalRead(button2);
 buttonState3 = digitalRead(button3);
 buttonState4 = digitalRead(button4);

 if (buttonState1 == HIGH) {

   Serial.println("X+");
   myStepper.step(1);

 }
 else {
   Serial.println("Nothing x+");
 }
 if (buttonState2 == HIGH) {

   Serial.println("X-");
   myStepper.step(-1);

 }

 else {
   Serial.println("Nothing x-");
 }

 if (buttonState3 == HIGH) {

   Serial.println("Y+");
   myStepper2.step(1);

 }

 else {
   Serial.println("Nothing y+");
 }

 if (buttonState4 == HIGH) {

   Serial.println("Y-");
   myStepper2.step(-1);

 }

 else {
   Serial.println("Nothing y-");
 }

 if (buttonState4 == HIGH && buttonState2 == HIGH) {

   Serial.println("Y- , X -");

   myStepper.step(-1), myStepper2.step(-1);


 }


 if (buttonState1 == HIGH && buttonState3 == HIGH) {

   Serial.println("Y+ , X+");
   myStepper2.step(1),  myStepper.step(1);

 }

}
  (code tags added by moterator)
High School Engineering Teacher

CrossRoads

Does the speed improve if all the serial.prints are commented out, or the serial speed is set faster?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

PaulS

Code: [Select]
    myStepper2.step(1),  myStepper.step(1);
This is a novel use of the comma operator. Almost makes one think you don't know what you are doing, though.

nobikes

Thank you CrossRoads, commenting out the serial printing worked, it is running great now. Why would that cause a problem?



PaulS sorry that i am not a programmer, but thank you for the positive reinforcement!
High School Engineering Teacher

Grumpy_Mike

Quote
Why would that cause a problem?

Because it takes time to print and you are only stepping the motors one step at a time. Therefore your stepping rate is determined by the delays in the program calling for that single step. The speed setting is only effective when you do more than one step at a time.

CrossRoads

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up