Arduino Stepper Library Working/AccelStepper Not Working

594 views
Skip to first unread message

James Pistorino

unread,
Apr 26, 2016, 2:18:03 PM4/26/16
to accelstepper
Complete noob here so be gentle.

I am trying to control a 24V NEMA23 stepper motor using an ArduinoMega 2560 (R3).
I am using an ST-M5045 driver.

When I use the default Arduino Stepper library, the motor runs fine.
I am using pin 31 for the steps and pin 30 for the direction.
My code looks like:

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution

void setup() {
  pinMode(30,OUTPUT);
  pinMode(31,OUTPUT);
  digitalWrite(30,LOW);
  digitalWrite(31,LOW);
}

void loop() {
  digitalWrite(31,HIGH);
  digitalWrite(31,LOW);
}

Now, I want to operate the same motor using AccelStepper but can't get any response.
My code looks lie:

#include <AccelStepper.h>

AccelStepper stepper3(1, 31, 30);

void setup()

    stepper3.setMaxSpeed(400.0);
    stepper3.setAcceleration(100.0);
    stepper3.moveTo(100000);
}

void loop()
{
    stepper3.run();
}

Any idea on why this is not working?
I have tried several variations here with no luck.

Thanks in advance for any help.

Regards,
James

James Pistorino

unread,
Apr 28, 2016, 1:04:24 PM4/28/16
to accelstepper
I now know what is happening. 
The maxspeed was set way too low here. 
I increased it to 4000, and now I can see the motor turning (though still very slowly). 
I just need to play around with the speed until I get what I want.
Reply all
Reply to author
Forward
0 new messages