Standard Stepper Program Working, Not the one using AccelStepper library

The following code runs fine.
It is in 1/16th for AN4988 board.

// defines pins numbers
const int stepPin = 5; 
const int dirPin = 4;

/*
hw134	
      g	    dir
	    vcc	  step
	    1E	  sleep
	    1A	  reset
	    2A	  S3
	    2E	  S2
	    g	    S1
	    vmot	E
*/

const int delayMicros = 100;
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}
void loop() {

  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 3200 pulses for making one full cycle rotation 1/16 microstepping
  for(long int x = 0; x < 6400; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(delayMicros); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(delayMicros); 
  }
  delay(1); // One second delay
  
  digitalWrite(dirPin,LOW); //Changes the rotations direction
  // Makes 400 pulses for making two full cycle rotation
  for(long int x = 0; x < 6400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(delayMicros);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(delayMicros);
  }
  delay(1);
}

However, the following code doesn't work. The stepper seems to be loaded but unable to peak the speed and doesn't move.

#include <AccelStepper.h>
AccelStepper stepper(1, 5,4);  // pin 5 = step, pin 4 = direction

void setup()
{  
  stepper.setMaxSpeed(150);
  stepper.setAcceleration(100);
}
 
void loop()
{    
  stepper.moveTo(6400);
  while (stepper.currentPosition() != 5000) // Full speed up to 300
    stepper.run();
  stepper.runToNewPosition(0); // Cause an overshoot then back to 0
}

What could be the reason?

"Doesn't work" contains no information.

Hi..
I mean to say that if the hardware confuration remains same and I see the steeper running fine using normal code.

When I say the library based code doesn't work, I mean to say that my motor doesn't rotate. What could be going wrong?

Is the code that I tested with Accelstepper library is wrong?

What am I missing?

I believe the pin configuration is correct.

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