Problem with speed control and accelstepper

OK so first off I started with an A4988 driver and a small NEMA 11-size hybrid bipolar stepping motor has a 1.8° step angle (200 steps/revolution). Each phase draws 670 mA at 3.5 V. Bought everything from Pololu and used this Getting started guide To wire and test the code, driver and motor.
That all worked very well and by changing the values in the test code I could speed up or slow down the motor. but I wanted/ need acceleration.

I’ve been reading the AccelStepper info and testing code. The only thing that I want is for the motor to accelerate up to the running speed and keep going forever. MoveTo is not wanted.

I tried this:

#include <AccelStepper.h>
#define enablePin 4
AccelStepper stepper(1, 2, 3);

void setup() {
  // put your setup code here, to run once:
 pinMode(enablePin, OUTPUT); 
stepper.setMaxSpeed(800);
stepper.setSpeed(500);
stepper.setAcceleration(200);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(enablePin, LOW);
stepper.runSpeed();
}

But no matter what I changed the setSpeed to the motor would run at a 3RPM or there abouts.

I also tried this:

#include <AccelStepper.h>

int motorSpeed = 9600; //maximum steps per second (about 3rps / at 16 microsteps)
int motorAccel = 80000; //steps/second/second to accelerate

int motorDirPin = 3; //digital pin 3     
int motorStepPin = 2; //digital pin 2

//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper stepper(1, 2, 3);
void setup() {
  // put your setup code here, to run once:
stepper.setMaxSpeed(1000);
 stepper.setSpeed(250);
 stepper.setAcceleration(175);
}

void loop() {
  // put your main code here, to run repeatedly:
 stepper.run();

But the motor would do nothing. I did not set the enable pin in the code, i just held it low the same way as the MS1,2 and 3 by connecting them to ground.

What have I missed?

1 Like