Stepper motor works - but not with AccelStepper

Hello,

I’ve got an Arduino Uno, a stepper motor driver (SilentStepStick with Trinamics TMC2100) and a small stepper motor. The motor works with a small test script, that sets the step pin manually to LOW and HIGH. But when I try to use the AccelStepper Library, it doesn’t work and I can’t figure out why.

Here’s the “manual” code, works really well:

#define EN_PIN    11 //enable (CFG6)
#define DIR_PIN   9 //direction
#define STEP_PIN  10 //step
#define CFG1_PIN  13

void setup()
{
  pinMode(EN_PIN, OUTPUT);
  digitalWrite(EN_PIN, HIGH); //deactivate driver (LOW active)
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(DIR_PIN, HIGH); //LOW or HIGH
  pinMode(STEP_PIN, OUTPUT);
  digitalWrite(STEP_PIN, LOW);
  pinMode(CFG1_PIN, OUTPUT);
  digitalWrite(CFG1_PIN, HIGH);
  
  digitalWrite(EN_PIN, LOW); //activate driver
}

void loop()
{
  //make steps
  digitalWrite(STEP_PIN, HIGH);
  delayMicroseconds(2000);
  digitalWrite(STEP_PIN, LOW);
  delayMicroseconds(2000);
}

Now here’s the AccelStepper script:

#include <AccelStepper.h>

#define DIR_PIN 9
#define STEP_PIN 10
#define EN_PIN 11
#define CFG1_PIN 13

AccelStepper stepper(1, STEP_PIN, DIR_PIN);

void setup() {
  pinMode(CFG1_PIN, OUTPUT);
  digitalWrite(CFG1_PIN, HIGH);
  stepper.setPinsInverted(false, false, true);
  stepper.setEnablePin(EN_PIN);
  stepper.setSpeed(200);

}

void loop() {
    stepper.runSpeed();

}

The stepper motor is powered, but it just doesn’t move at all. I tried varying speeds, inverted pins, etc. Nothing seems to work …

Maybe someone of you has a suggestion.

Thanks in advance,

  • Bas3008

In the working program you have ENABLE pulled LOW - but not in the other version ?

More likely, in the AccelStepper program you have no moveTo() to tell it how many steps to take.

...R

In the AccelStepper code, I set it to LOW via stepper.setEnablePin(EN_PIN) and setPinsInverted(...). The stepper motor blocks, so it's definitely enabled.

I added stepper.moveTo(32000) to the setup, but still nothing moves :confused:

Call run() in loop and moveTo() at the end of setup.

Also you haven't called setMaxSpeed() or setAcceleration() in setup(), do so.

Hi Bas3008,

Have you managed to get it moving by the end of the day? Can please you give your final scratch? I’m experiensing the same problem.

Janus2006:
Hi Bas3008,

Have you managed to get it moving by the end of the day? Can please you give your final scratch? I'm experiensing the same problem.

You have re-awakened a Thread that is nearly 2 years dead.

Post your program.
Provide details of your stepper motor and stepper motor drivers
Provide details of your motor power supply (volts and amps)
Provide a clear diagram showing how YOU have everything connected.

...R
Stepper Motor Basics
Simple Stepper Code