Dual stepper motor control

Hi all,

I have my stepper motor code which controls a pitch and yaw stepper motors. The code for the yaw (X) stepper works fine however I am having issues with my pitch (Y) stepper which has a step angle of 0.018 degrees.

My problem is that I need my pitch stepper to rotate 45 degrees in total at 5 degree motions. It can rotate after the yaw stepper does a full sweep. I tried to limit the pitch angle by using a += logic but that didnt work.

Is there anyway I can stop the pitch stepper motor once it has rotated a total of 45 degrees (2500 steps) after doing nine rotations at 5 degrees a time once a 120 degree yaw (X) sweep has been finished.

Below is my code, and thank you for taking the time to help.
Jacob.

// Include the Arduino Stepper Library
#include <Stepper.h>
int posX = 0; // Yaw stepper
int posY = 0; // Pitch stepper

// Number of steps per output rotation
const int stepsPerRevolution = 200;

// Create Instance of Stepper library
Stepper XStepper(stepsPerRevolution, 4, 5, 6, 7);
Stepper YStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup()
{
// set the speed at 60 rpm:
XStepper.setSpeed(60);
YStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}

void loop()
{
// step one revolution in one direction:
for(posX = 0; posX = 1000; posX = 111)
{
XStepper.step(posX);

if (posY <=2500) {
posY += 278;
YStepper.step(-posY);}
XStepper.step(-posX);

}

}

Reference > Language > Structure > Control structure > For

It is much easier for people to help if you use the code button </> when posting code. And if you use the AutoFormat too to indent your code consistently it will make it easier for you to see how the blocks of code relate to each other.

    // Include the Arduino Stepper Library
#include <Stepper.h>
int posX = 0;  // Yaw stepper
int posY = 0;  // Pitch stepper

    // Number of steps per output rotation
const int stepsPerRevolution = 200;

    // Create Instance of Stepper library
Stepper XStepper(stepsPerRevolution, 4, 5, 6, 7);
Stepper YStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup()
{
        // set the speed at 60 rpm:
    XStepper.setSpeed(60);
    YStepper.setSpeed(60);
        // initialize the serial port:
    Serial.begin(9600);
}

void loop() 
{
        // step one revolution in one direction:
    for(posX = 0; posX = 1000; posX = 111)
    {
        XStepper.step(posX);
        
        if (posY <=2500) {
            posY += 278;
            YStepper.step(-posY);
        }
        
        XStepper.step(-posX);
    }
 }

I also like to indent comments an extra bit so I can read the code without my eyes tripping over the comments

…R

This line is wrong

for(posX = 0; posX = 1000; posX = 111)

It should be

for(posX = 0; posX <= 1000; posX += 111)

There is nothing technically wrong with using a global variable as the counter in a FOR loop but it is more usual to use a local variable.

…R