Trouble with AccelStepper Library

I'm currently working on a robot that runs on three stepper motors through an Arduino Uno and the CNC shield. I want to control the position of all three at the same time wile using speed and acceleration control. Through my research I found that the AccelStepper Library was my best option.
I installed the library, added the zip file, opened the ConstantSpeed example, and set AccelStepper stepper(AccelStepper::DRIVER, 2, 5); (2 is my step pin and 5 is my direction pin). But the stepper won't even turn on. I know the setup I have now works because I've tried different code with it and the stepper runs. So I narrowed it down to a software issue.
I've included the code: did I miss something?

// ConstantSpeed.pde
// -- mode: C++ --
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 5); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{

stepper.setMaxSpeed(1000);
stepper.setSpeed(50);

//Setup terminal
Serial.begin(9600);
}

void loop()
{

stepper.runSpeed();

//Debugging
Serial.print("Running");
Serial.print("\n");
}

The enable pin of the stepper drivers is pulled high by the CNC shield by default. You need to enable the steppers by setting pin 8 LOW.

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.
Code will look like this:

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 2, 5); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
const byte enablePin = 8;  // ***** pin 8 is the enable pin

void setup()
{
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);
   pinMode(enablePin, OUTPUT); // **** set the enable pin to output
   digitalWrite(enablePin, LOW); // *** set the enable pin low
   //Setup terminal
   Serial.begin(9600);
}

void loop()
{
   stepper.runSpeed();

   //Debugging
   Serial.print("Running");
   Serial.print("\n");
}

Code works as tested with my Uno, CNC shield and stepper on X axis.

Ahh! Thank you so much! I just couldn't figure out how to set the enable pin. Will defiantly look at those guidelines, thanks for the tip, sorry for the poor formatting (first post) :grinning:

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