Pages: [1]   Go Down
Author Topic: 2 Stepper motors with drivers - Help  (Read 684 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My aim is to have two steppers, one for the x - axis and one for the y - axis. Will this code work, or am i missing somthing?

Code:
#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, 4,5,6,7,8,9,10,11); 

void setup() {
  // initialize the serial port:
  Serial.begin(9600);

const unsigned long int X_STEPS_MAX = 745683;
const unsigned long int Y_STEPS_MAX = 87346;

unsigned long int X_position = 0;
unsigned long int Y_position = 0;

boolean X_increasing = true;

void loop() {
    if (X_increasing) {
        if (X_position == X_STEPS_MAX) {
             Y_position ++;
             Y_step_down();
             X_increasing = false;
         } else {
            X_position++;
            X_step_right();
         }
    } else { // decreasing
        if (X_position == 0) {
             Y_position ++;
             Y_step_down();
             X_increasing = true;
         } else {
            X_position--;
            X_step_left();
         }
     }

   while (Y_position == Y_STEPS_MAX);  // stop everything
}
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 4,5,6,7,8,9,10,11);

You've left out quite a bit of detail, but this is no good for starters. You probably want:

Code:
Stepper myStepperX = Stepper(stepsPerRevolution,4,5,6,7); 
Stepper myStepperY = Stepper(stepsPerRevolution,8,9,10,11);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, thank you very much smiley
Logged

Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is very simple code i put together for roughly the same thing, im not sure what motors/driver combo your using but this works very well for me. youll more than likely need to change the variables bc i have fine tuned them for my system. good luck!!

#include <Stepper.h>
 
const int stepsPerRevolution = 64; 
 
Stepper pan(stepsPerRevolution, 8,10,9,11);
Stepper tilt(stepsPerRevolution, 3,5,4,6);
 
void setup() {
 
  pan.setSpeed(300);    // pan
  tilt.setSpeed(300);   // tilt
}
 
 void loop() {
 
  int sensorReading = analogRead(A0); // pan
 
  if (sensorReading < 300) { pan.step(4); }   // pan left
  if (sensorReading > 800) { pan.step(-4); }  // pan right
 
  int sensorReading2 = analogRead(A1); // tilt
 
  if (sensorReading2 < 300) { tilt.step(4); } // motion down
  if (sensorReading2 > 800) { tilt.step(-4); } // motion up
   
   
 }
Logged

Pages: [1]   Go Up
Jump to: