Bug running AccelStepper

Hi all,

I'm currently experimenting with some VID-023 instrument stepper motors running of a VID 6606 driver.

For now I've wired up a single servo to my Teensy 3.2, and have it moving along nicely using this test code. I have wired up the servo as shown:

https://guy.carpenter.id.au/gaugette/2017/04/29/switecx25-quad-driver-tests/:

/*
  X12.017 Quad Driver Test
  Drive the motor forward and backwards through 270 degrees
  at constant speed.
 */

//const int LED = 13;
const int DIR_A = 11; // pin for CW/CCW
const int STEP_A = 10; // pin for f(scx)
const int RESET = 12; // pin for RESET
const int DELAY = 250; // μs between steps
const int ANGLE = 270; // of 315 available
const int RANGE = ANGLE * 3 * 4;
int steps = 0;
bool forward = true;

// pull RESET low to reset, high for normal operation.

void setup() {
  pinMode(DIR_A, OUTPUT);
  pinMode(STEP_A, OUTPUT);
  //pinMode(LED, OUTPUT);
  pinMode(RESET, OUTPUT);

  digitalWrite(RESET, LOW);
  //digitalWrite(LED, HIGH);
  digitalWrite(STEP_A, LOW);
  digitalWrite(DIR_A, HIGH);
  delay(1);  // keep reset low min 1ms
  digitalWrite(RESET, HIGH);
}

// The motor steps on rising edge of STEP
// The step line must be held low for at least 450ns
// which is so fast we probably don't need a delay,
// put in a short delay for good measure.

void loop() {
  digitalWrite(STEP_A, LOW);
  delayMicroseconds(1);  // not required

  steps++;
  if (steps > RANGE) {
    forward = !forward;
    steps = 0;
    digitalWrite(DIR_A, forward ? LOW : HIGH);
    //digitalWrite(LED, forward ? HIGH : LOW);
  }

  digitalWrite(STEP_A, HIGH);
  delayMicroseconds(DELAY);
}

I have heard that the AccelStepper library is good for driving this items and has some powerful functions, so I'd like to give it a try.

I have tried a super simple example using this code, but the servo is not moving at all... Am I missing something obvious?

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper(AccelStepper::FULL2WIRE, 10, 11);


void setup()
{  

}

void loop()
{
    if (stepper.distanceToGo() == 0)
    {
  // Random change to speed, position and acceleration
  // Make sure we dont get 0 speed or accelerations
  delay(1000);
  stepper.moveTo(rand() % 200);
  stepper.setMaxSpeed((rand() % 200) + 1);
  stepper.setAcceleration((rand() % 200) + 1);
    }
    stepper.run();
}

AccelStepper is for working with stepper motors, not servos. The two are not even close to the same things.

Sorry my bad, this is a stepper I'm working with. It has a 315 degree travel and 12 steps per degree = 3780 steps for full range of movement...

You have a 3780-step range and are only moving within a 200-step window? That's not much motion.

It looks like you are using a "Step and Direction" driver and that would be the type DRIVER, not FULL2WIRE.

Fantastic thanks John well spotted - I will try this...

Dammit... Still no movement... Any ideas?

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper(AccelStepper::DRIVER, 10,11);
const int RESET = 12; // pin for RESET
void setup()
{  
  pinMode(RESET, OUTPUT);
  digitalWrite(RESET, LOW);
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    // Change direction at the limits
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}

If the RESET line is Active Low then your driver would be held in reset. Check the device datasheet.

Well spotted thank you John! I have got it working, and wired it up to a 10k potentiometer to test its operation. I need it to move fast so have run the speed up to 7000 steps per second and acceleration right up to about 10000, but this makes it a bit jittery so I've averaged the analogue signal over 50 samples, and rounded that to the nearest 100 steps. It seems quite good now but is this the best way to smooth the stepper actuation?

Thanks again!