Go Down

Topic: Problem with changing direction - stepper motor (Read 1 time) previous topic - next topic

le-vi

Hello,

I'm having an issue with a stepper motor setup. I have an Arduino Mega 2560 and a Super Electric Slo M092-FF-409 Stepper Motor. The motor is connected to an older Geckodrive 210.

My problem is: I can smoothly operate the motor, in one direction (clockwise), using one of the examples from the stepper motor library. However, when I input a negative number of steps to move counterclockwise, the motor's motion is not smooth. It hesitates, going clockwise first, before proceeding to somewhat smoothly go counterclockwise.

I have the pins for both step and direction connected from my board to the Geckodrive. The problem seems to occur when the direction pin is connected to the Arduino. If I remove it, the motor operates perfectly but it cannot rotate counterclockwise. I'm not sure what's going on with the direction pin so if there is any remedy to the problem, please let me know.

If a picture of the setup is needed, I can provide soon. I don't have the setup at hand right now but I'll get those pictures up as soon as possible. I'm a complete beginner to stepper motors, but I'm willing to accept any critiques and advice.

Thank you.

Robin2

You have not posted your program so all I can do is guess ...

The standard stepper library is not really suitable for a stepper driver that uses step and direction signals. The AccelStepper library is much more comprehensive.

...R
Stepper Motor Basics
Simple Stepper Code

Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

For a large stepper like that (its a NEMA34 from what I can gather), speed ramping is essential, not
optional.  AccelStepper library gets my vote too.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

le-vi

Thanks for the replies.

Here is a picture of my setup. I have not tried AccelStepper library yet but will.

Could there be something wrong with my wiring? And yes, the motor is a NEMA34.

Robin2

Image from Reply #3 so we don't have to download it. See this  Simple Image Guide



...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

I find it impossible to be certain how things are connected based on a photo of the hardware. Make a simple pencil drawing showng how everything is connected and post a photo of the drawing.

The program code is just as important as the drawing.

But be sure to try the AccelStepper library before replying to this as it may do what you need.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

le-vi

#6
Aug 11, 2018, 03:51 am Last Edit: Aug 11, 2018, 03:52 am by le-vi
Sorry about that. Hopefully this diagram helps out.

I tried the AccelStepper Library and I run into the same problem. The motor jerks in the opposite direction before moving in the desired direction and then repeats the same behavior if there's a command to change it's direction.

If I remove the direction pin connected to the Arduino, the motor operates smoothly but cannot change directions. I'm not sure if that bit of information helps


le-vi

Here is the simple code that I use to test rotation clockwise then counterclockwise

Code: [Select]
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution for your motor
int numberofsteps = 4; // number of rotations that we want to make


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(100);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {

 
  if (numberofsteps > 0)
  {
    // step one revolution  in one direction:
    Serial.println("clockwise");
    myStepper.step(stepsPerRevolution);
    delay(200);
 
    // step one revolution in the other direction:
    Serial.println("counterclockwise");
    myStepper.step(-stepsPerRevolution);
    delay(200);
    numberofsteps -= 1;
  }
}



Robin2

#8
Aug 11, 2018, 10:03 am Last Edit: Aug 11, 2018, 10:04 am by Robin2
Here is the simple code that I use to test rotation clockwise then counterclockwise
Please post the AccelStepper version.

Have you tried the simple code in the link in Reply #1 - it uses no library so it puts you in complete control.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

le-vi

Here is the code that I use from the AccelStepper Library. This one also runs into the same problem of switching directions.

The simple code that you showed me actually works very well. I'm wondering what could be the differences this and the ones used for AccelStepper.

Since I'm using this in conjunction with LabVIEW's LIFA library to simultaneously control the stepper and collect data, could I simply adjust the corresponding functions in the AccelStepper library from which LIFA incorporates in order to use this simpler code?

Thanks again for the reply and your patience.

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps


void setup() {

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

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

void loop() {
}

Robin2

Here is the code that I use from the AccelStepper Library. This one also runs into the same problem of switching directions.
Sorry, but you posted the wrong code by accident.

Quote
The simple code that you showed me actually works very well. I'm wondering what could be the differences this and the ones used for AccelStepper.
That is good to know because it proves that the motor can be controlled.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up