Go Down

Topic: 2 Stepper motors with drivers - Help (Read 756 times) previous topic - next topic

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: [Select]
#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
}

Chagrin

Code: [Select]
// 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: [Select]
Stepper myStepperX = Stepper(stepsPerRevolution,4,5,6,7); 
Stepper myStepperY = Stepper(stepsPerRevolution,8,9,10,11);


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
   
   
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy