Stepper Motor Help (Gecko G201X + AccelStepper library)

Hi folks,

I’m really struggling to get this motor behaving properly with the Gecko G201X Motor Driver and the AccelStepper library. The motor I’m driving is an Anaheim 34Y004D-LW8

I have the motor wired as 4 lead bipolar (if you look at the link to the spec sheet you’ll see the wiring config im using on the second page)

I’m certain that I have the motor wired properly and I also feel confident that I have it connected to the Gecko properly - as well as having the Gecko wired to the Arduino properly.

Here’s a photo just in case…

I’ve had this motor working just fine with another motor driver (Rugged Circuits - Rugged Motor Driver).

My problem lies in controlling the motor with the AccelStepper library. I’ve seen so many examples with this library controlling various motors that i’ve gotten really confused. I’ve gotten the motor to spin at various speeds with the following code, but for the life of me can’t make the motor switch directions (CW / CCW) no matter what I try with methods from the library or other examples i’ve been looking at.

Here is my basic test code… please have a look to see if the AccelStepper constructor is correctly instantiated for my motor and wiring. This code does spin the motor and I am able to change the speed.

#include <AccelStepper.h>

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

void setup() {  

void loop() {

The Constructor has several different configurations… my best guess has been to use ‘AccelStepper::DRIVER’. Many examples i’ve seen use ‘AccelStepper::FULL4WIRE’ … which my motor does have 4 wires, but those four connect to the Gecko as winding pairs, leaving me with Step, Direction, and Enable wires connecting the arduino with the driver.

Link to the AccelStepper reference (constructor)

To make things more confusing many of the AccelStepper examples i’ve seen require that you define how many steps your motor has. Where do I define my number of steps (200) with my configuration?

I’m sorry if this is at all vague, i appreciate your patience. Please understand that I’m just confused by the number of options presented.

Thank you in advance :slight_smile:

From the AccelStepper documentation:

void AccelStepper::setSpeed ( float speed )
Sets the desired constant speed for use with runSpeed().

[in] speed The desired constant speed in steps per second. Positive is clockwise. Speeds of more than 1000 steps per second are unreliable. Very slow speeds may be set (eg 0.00027777 for once per hour, approximately. Speed accuracy depends on the Arduino crystal. Jitter depends on how frequently you call the runSpeed() function.
ConstantSpeed.pde, and ProportionalControl.pde.
References DIRECTION_CCW, DIRECTION_CW, and speed().

Have you tried a negative value for speed?

The Gecko just needs step and direction signals from the Arduino and for that you use the DRIVER option of accelstepper.

A wiring diagram is much clearer than a photo. You don’t seem to have a GND connection between your Arduino and the Gecko.

If you set the pins correctly this simple test code should make the motor move

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds

void setup() 

  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);
    digitalWrite(ledPin, !digitalRead(ledPin));

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
    digitalWrite(ledPin, !digitalRead(ledPin));

void loop() 



Thanks Robin / all.

I'm a total hammer-head. I didn't have the ground wire connected to the Gecko :frowning:

Everything works perfectly now.. negative values spin the motor CCW :slight_smile:

Please stay tuned to this thread and I'll post a video of what I'm doing with the motor - it's a wireless EEG headset paired with a Raspberry Pi, communicating through serial to an Arduino, running lights and the motor.

This is just a component of an elaborate art project involving the occult :wink:

best, Garth

Summoning up the devil would be a novel Arduino project 8-O

Summoning up the devil would be a novel Arduino project 8-O

S/He's already here in the guise of the new Forum :slight_smile: