Pages: [1]   Go Down
Author Topic: can not get steppers to speed up.  (Read 868 times)
0 Members and 1 Guest are viewing this topic.
Surrey BC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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)
« Last Edit: November 18, 2011, 04:18:50 pm by CrossRoads » Logged

High School Engineering Teacher

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the speed improve if all the serial.prints are commented out, or the serial speed is set faster?
Logged

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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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.
Logged

Surrey BC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

High School Engineering Teacher

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34164
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nuff said.
Logged

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.

Pages: [1]   Go Up
Jump to: