Go Down

Topic: Why is there a Stepper constructor with 4 pins...? (Read 1 time) previous topic - next topic

giovanniguerra

The stepper library has various constructors. I can understand the 2 pin version (direction and step) but why is there a 4 pin version?

I could not find an answer here after some searching...




Southpark

The stepper library has various constructors. I can understand the 2 pin version (direction and step) but why is there a 4 pin version?

I could not find an answer here after some searching...
A stepper motor is often considered as a motor having two main coils. Each coil has 2 terminals (for the bipolar stepper motor). So two coils means 4 terminals.

giovanniguerra

A stepper motor is often considered as a motor having two main coils. Each coil has 2 terminals (for the bipolar stepper motor). So two coils means 4 terminals.
Hmm. So the 2 pin constructor is when you have a electronic driver between the Arduino and the stepper? Presumably the driver converts from PULSE and DIR into the 4 signals required by the actual electomechanics of the stepper?


Southpark

Hmm. So the 2 pin constructor is when you have a electronic driver between the Arduino and the stepper? Presumably the driver converts from PULSE and DIR into the 4 signals required by the actual electomechanics of the stepper?
Yeah.... I think so Giovanni. I think the reduction to 2 pins could be based on a general driving method, where the terminal voltages of a single coil are always opposite of each other. So the software (and hardware) driving method can just take our 'high level' language (eg. step and direction), and it will handle the setting of the polarity etc for us.

But when you mention '2 pin constructor', I'm thinking you may have meant 'two parameter constructor'. So the two parameters will be : to step....and which direction to step, which is 2 parameters.

giovanniguerra

Yeah.... I think so Giovanni. I think the reduction to 2 pins could be based on a general driving method, where the terminal voltages of a single coil are always opposite of each other. So the software (and hardware) driving method can just take our 'high level' language (eg. step and direction), and it will handle the setting of the polarity etc for us.

But when you mention '2 pin constructor', I'm thinking you may have meant 'two parameter constructor'. So the two parameters will be : to step....and which direction to step, which is 2 parameters.
Ok. I'm slowly getting the idea.

I said 2 pin constructor because it was a constructor with three parameters, two of which were pins. On a MakeBlock Orion (Uno compatible) I think, suppose, guess I can do this:

AccelStepper  StepperMotorA (AccelStepper::FULL2WIRE,10,11) ;

...?

Southpark

Ok. I'm slowly getting the idea.

I said 2 pin constructor because it was a constructor with three parameters, two of which were pins. On a MakeBlock Orion (Uno compatible) I think, suppose, guess I can do this:

AccelStepper  StepperMotorA (AccelStepper::FULL2WIRE,10,11) ;

...?

Oh yeah. True. You're right about that giovanni. It's 3 parameters.

Robin2

If you are using the AccelStepper library with a stepper driver that takes step and direction signals you should use the DRIVER option.

You need to specify the 4 pins if you want to drive the motor with a h-bridge such as an L298. I recommend that you don't do that.

You ALWAYS need some electronics between the Arduino and the stepper motor - except for some tiny motors used in automobile instruments.

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

giovanniguerra

If you are using the AccelStepper library with a stepper driver that takes step and direction signals you should use the DRIVER option.

You need to specify the 4 pins if you want to drive the motor with a h-bridge such as an L298. I recommend that you don't do that.

You ALWAYS need some electronics between the Arduino and the stepper motor - except for some tiny motors used in automobile instruments.

...R
Stepper Motor Basics

Many thanks for ALL that info. :)

giovanniguerra

Just in case this would help someone, this is an example of driving a stepper motor controlled with STEP and DIR pins.

Code: [Select]
// Controlling a stepper motor on the MakeBlock Orion with STEP and DIR pins, use AccelStepper::DRIVER

#include <AccelStepper.h>

// Define a stepper and the pins it will use
#define PORT1_DIR_PIN 11
#define PORT1_STEP_PIN 10
AccelStepper Port1Stepper (AccelStepper::DRIVER, PORT1_STEP_PIN, PORT1_DIR_PIN);

// This is what you'd do with the second port...
#define PORT2_DIR_PIN 3
#define PORT2_STEP_PIN 9
AccelStepper Port2Stepper (AccelStepper::DRIVER, PORT2_STEP_PIN, PORT2_DIR_PIN);

void setup()

}

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

MarkT

You ALWAYS need some electronics between the Arduino and the stepper motor - except for some tiny motors used in automobile instruments.

Even then you need 8 schottky diodes to prevent inductive kick-back damage...  Motors can never be
directly driven by a bare logic output
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up