Stepper motor only works on pins 8 through 11

I am trying to control 2 stepper motors with a joystick. I started by trying to make two steppers turn together, but this was impossible. My motors come from the Elegoo starter kit, so it came with an example code. I ran it and it was working with one stepper, but not two. After checking 8 times the connections and trying to debug my code, I figured that the motor was not working if I placed it anywhere else than pins 8 through 11. When I place it anywhere else, it just vibrates but doesn't move. I have searched through an infinite amount of threads about this same subject but none were talking about placing the motor on specific pins nor any solution at all. I couldn't reply since the threads were closed so I decided to start a new thread and hope that someone help me.
Here's the code I am trying to run if it can help :

//www.elegoo.com
//2018.10.25

/*
  Stepper Motor Control - one revolution

  This program drives a unipolar or bipolar stepper motor.
  The motor is attached to digital pins 8 - 11 of the Arduino.

  The motor should revolve one revolution in one direction, then
  one revolution in the other direction.

*/

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
const int rolePerMinute = 15;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm

// initialize the stepper library on pins 8 through 11:
Stepper X(stepsPerRevolution, 8, 10, 9, 11);
// initialize the stepper library on pins 2 through 5:
Stepper Y(stepsPerRevolution, 2, 3, 4, 5);

void setup() {
  X.setSpeed(rolePerMinute);
  Y.setSpeed(rolePerMinute);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {  
  // step one revolution  in one direction:
  Serial.println("clockwise");
  X.step(stepsPerRevolution);
  Y.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  X.step(-stepsPerRevolution);
  Y.step(-stepsPerRevolution);
  delay(500);
}

Try

Stepper Y(stepsPerRevolution, 2, 4, 3, 5);

To move two steppers in parallel, you need another stepper library e.g. my MobaTools lib or the AccelStepper library, because the stepper.h is blocking while the motor moves.

In the examples of the MobaTools library, only two pins are defined. My stepper driver has four 'in' pins, which ones should I connect?

You need to connect alle four 'in' pins. MobaTools can be used with 2 pin drivers ( step/dir-driver ) or 4 pin drivers as with your motor. There are also examples for a 4-pin-stepper driver like the one for the 28BYJ-48 stepper. E.g. stepper_01.ino and stepper_02.ino. Unfortunately these examples are mainly commented in german, and the functionality is only summarized in english.

The main difference is only when creating the stepper object, and when attaching the pins:

2 pin (step/dir):

Stepper X(stepsPerRevolution, STEPDIR);  // create stepper with 2 pins ( step/dir-driver )
....
X.attach( steppin, dirpin );

4-pin:

Stepper X(stepsPerRevolution, FULLSTEP); // create stepper with 4 pins
....

X.attach( pin1,pin2,pin3,pin4 );

All other methods are the same for both types of steppers.

Hi, @methething

Can you please post a schematic of your project?

Can you please post some images of your project so we can see your project layout?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:
PS. I'm off to bed... :sleeping: :sleeping: :sleeping:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.