Help with proper use of ENA or enable pin

101 views
Skip to first unread message

ACME Corp

unread,
Mar 4, 2025, 12:48:15 AMMar 4
to accelstepper
Greetings- 

I am working on a winding machine. I am trying to use 'enable' as a brake release. I am trying to figure out the preferable methodology and execution. I am stuck and gotten confused trying to read the docs. 

Concept: When the gadget is on, with no step/dir signals being issued, enable function engaged, the motor spindle is locked. 

I want to wire in a simple momentary switch so that pressing it will release the spindle and allow it to be turned by hand. This is not meant to be an e-stop type function. Seems simple enough, but I am at a loss as to how to best control it.  This is where I need guidance and some help. 

I have come up with 2 options-

1. I can hotwire the enable pin on the stepper driver to an NO switch and +5V and completing the circuit would change the state of ENA and free the spindle.  I would then only use the 2pin definition of AccelStepper to control the motor.  Crude, simple but likely effective. Does not have safety of debounce checking. 

2. Define an enable pin as part of AccelStepper definition,  define an input pin for the switch and an output pin to control enable with software. Seems safer and more like the proper way to do it. But now I am stuck with proper AccelStepper definition and where to insert the release command in my code. 

Can anyone offer advice on which way is preferable? 

Other pertinent info- Nema17 motor, Arduino UNO,  stepstick like A4988 or DRV8825 for now. I might upgrade to a larger motor and something like a TB6600 later.

I have tried reading the docs at  https://www.airspayce.com/mikem/arduino/AccelStepper/ and the missing manual at hackaday. 

I cant find a FULL3WIRE coding example- I only see references to it as a Hard Disk Spindle motor control. Do I assume that it will default to motor pins (1, 2, 3) and then (STP, DIR, Pin3)? 

AccelStepper definitions. This is where I am stuck. The default arguments for the function are
Pin1 -->  Step input to the driver. 
Pin2 -> Direction input to the driver
Pin3: -> motor pin 3. 
Pin4: -> motor pin 4. 

But what are the motor pin 3 and 4 definitions? 
If I define Pin3 as the EN function, then what about Pin4? What do I do with that?  
Does it have to get assigned? Make it SLP or RST as a placeholder and just forget about it?  

Thanks in advance.

Dennis

gjgsm...@gmail.com

unread,
Mar 4, 2025, 9:37:02 PMMar 4
to accelstepper
I have used Option 1. Works for me.
A normal toggle switch is ok, no debounce required. Do not connect anything to the EN on driver other than your switch, most drivers by default are enabled. You only need worry about DIR and PUL (STP)
```
// Define Stepper PINS (Your choice)

#define DIR_A 32
#define PUL_A 33

#define DIR_B 16
#define PUL_B 17

AccelStepper stepperA(AccelStepper::DRIVER, PUL_A, DIR_A);                    // Assign Pins
AccelStepper stepperB(AccelStepper::DRIVER, PUL_B, DIR_B);
```

ACME Corp

unread,
Mar 6, 2025, 8:45:29 PMMar 6
to accelstepper
gigsm...-

thanks for the reply. I appreciate you sharing your experience and support of Option 1.  I will try it. 

I am still trying to learn about the differences between the different pre-defined configurations. Can you help me find direction on that? 
99% of the examples are written like this
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5


and I understand that pin1 and pin2 are Step and Direction. 

Then what about the implementations of pin definitions 3 & 4? 

I have yet to find any examples that explicitly define and use them. 

How do we use them? 

Jim Larson

unread,
Mar 6, 2025, 11:16:44 PMMar 6
to accelstepper
You will find some explanation and examples in the Missing Manual.
HTH
              -jim

gjgsm...@gmail.com

unread,
Mar 7, 2025, 1:13:18 AMMar 7
to accelstepper

Below is an explanation of the various MotorInterface types and an 'enable' pin,  including the use of an H Bridge type driver. Typically, most stepper motors are bi-polar, meaning they have two coil windings and four wires so, the most commonly used MotorInterface types  used would be ‘DRIVER’ (as in the example I gave) and the other probably FULL4WIRE most likely used in conjunction with an H Bridge to handle the power requirement.
SEE full explanation below:


DRIVER

  • What It Is:
    This mode is used when your stepper motor is paired with a dedicated driver module (for example, the A4988 or DRV8825) that accepts simple “step” and “direction” inputs.
  • How It Works:
    Instead of directly controlling the motor coils, you send two signals: one pulse tells the driver to move one step, and a second signal sets the rotation direction. The driver module (which includes its own internal H Bridges) handles the detailed coil switching.
  • In Simple Terms:
    It’s like hiring a skilled driver who only needs to know “go” and “turn,” while all the complex gear shifting happens behind the scenes.

Example for DRIVER Interface

In DRIVER mode, you only need to supply a step pin and a direction pin to the constructor. Then you define the enable pin using the setEnablePin() method.

#include <AccelStepper.h>

// Define the pins for the step/direction driver

#define STEP_PIN  2

#define DIR_PIN  3

#define ENABLE_PIN  4     // Pin used to enable/disable the driver. If you have no need to enable/disable the stepper then this is not needed and can be ignored.

 

// Create an AccelStepper object for a DRIVER type motor

AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

 

void setup() {

  // Set the enable pin; the library will handle setting this pin as an output

//  If you have no need to enable/disable the stepper then this is not needed and can be ignored.

  stepper.setEnablePin(ENABLE_PIN);

 

  // Optionally, enable the outputs (this may also depend on your specific driver logic)

//  If you have no need to enable/disable the stepper then this is not needed and can be ignored.

  stepper.enableOutputs();

}

void loop() {

  // Your stepper control code goes here

}

Explanation:

  • DRIVER Mode: You’re interfacing with a driver module (which already includes the H Bridge circuitry) that accepts a step pulse and a direction signal.
  • Enable Pin: The setEnablePin() method tells the library which Arduino pin controls whether the driver outputs are active. This lets you disable the motor outputs when not in use.


FULL2WIRE

  • What It Is:
    This mode is for motors that have been designed to work with just two wires.
  • How It Works:
    The motor’s internal wiring lets the two provided signals fully energize its coils in a proper sequence.
  • In Simple Terms:
    Think of it as a simple remote with just two buttons that still manages to get the motor moving reliably.

FULL3WIRE

  • What It Is:
    This mode suits motors that use three wires—often because one wire acts as a common connection (like a shared ground or center tap).
  • How It Works:
    One of the wires remains a constant connection while the other two receive alternating signals to energize the coils in the correct sequence.
  • In Simple Terms:
    Imagine a three-way control system where one element is always “on,” and you simply control the other two to move the motor in full steps.


FULL4WIRE

  • What It Is:
    A common configuration for stepper motors, especially bipolar types, using four separate wires (each connected to one end of the two coils).
  • How It Works:
    The library sends signals to each wire in a precise sequence. This allows you to control the energizing of each coil directly, ensuring full, powerful steps.
  • In Simple Terms:
    Think of it as having two pairs of independent switches—by flipping them in the right order, you guide the motor through its steps.

Example for FULL4WIRE Interface

In FULL4WIRE mode, you control each of the four wires (typically used for bipolar motors) directly.

The enable pin is set separately.

#include <AccelStepper.h>

// Define the pins for a full 4-wire configuration

#define MOTOR_PIN_1  5

#define MOTOR_PIN_2  6

#define MOTOR_PIN_3  7

#define MOTOR_PIN_4  8

#define ENABLE_PIN   9      // Pin used to enable/disable the motor outputs

 

// Create an AccelStepper object for a FULL4WIRE motor

AccelStepper stepper(AccelStepper::FULL4WIRE, MOTOR_PIN_1, MOTOR_PIN_2, MOTOR_PIN_3, MOTOR_PIN_4);

 

void setup() {

  // Define the enable pin for the motor controller

  stepper.setEnablePin(ENABLE_PIN);

 

  // Enable the outputs so the motor can be driven

  stepper.enableOutputs();

}

void loop() {

  // Your stepper control code goes here

}

Explanation:

  • FULL4WIRE Mode: This mode is used when you’re controlling each of the four wires of a bipolar stepper motor directly, allowing for full or half-step sequencing.
  • Enable Pin: Similar to the DRIVER mode, the enable pin is used to switch the motor outputs on or off, protecting your motor when it’s not needed.


HALF3WIRE

  • What It Is:
    Similar to FULL3WIRE but designed for half-step operation.
  • How It Works:
    By alternating between full steps and intermediate positions using three wires (one common and two active), the motor moves in half-steps for smoother motion.
  • In Simple Terms:
    It’s like climbing stairs but sometimes taking half-steps to achieve a smoother ascent.

HALF4WIRE

  • What It Is:
    This mode applies to four-wire stepper motors that you want to run in half-step mode.
  • How It Works:
    With all four wires available, the library alternates between states where one coil is fully energized and states where both coils share the load. This yields additional step positions, offering smoother and more precise control.
  • In Simple Terms:
    Imagine a finely tuned control panel where you can command not only full “big steps” but also finer “small steps” in between.

H Bridge Type Driver

  • What It Is:
    An H Bridge is a specific electronic circuit used to control the direction of current flowing through a motor’s coil. It is particularly essential for bipolar stepper motors, where you need to reverse current flow to move the motor in both directions.
  • How It Works:
    An H Bridge consists of four switching components (transistors or MOSFETs) arranged in an “H” shape. By controlling which switches are on, the circuit can apply voltage in either polarity to the motor coil.
    • Using a Module:
      Many integrated driver modules (like A4988 or DRV8825) contain built-in H Bridges. In these cases, you only need to supply a “step” pulse and a “direction” signal—the module’s H Bridges handle the polarity switching internally.
    • Direct Control:
      If you’re building your own H Bridge circuits to drive a bipolar stepper motor (using two H Bridges—one for each coil), you must control four outputs directly. In this scenario, you’d typically use a configuration like FULL4WIRE (or HALF4WIRE if half-stepping) in the Accelstepper library to manually sequence the signals for both coils.
  • Which MotorInterface Type to Use:
    • Using a Ready-Made H Bridge Module:
      When your H Bridge is part of an integrated driver board that accepts step and direction signals, choose the DRIVER interface type. This simplifies control because the complex switching is managed within the module.
    • Using Custom H Bridge Circuits:
      If you’re wiring up your own H Bridges to control the motor’s coils directly, you would generally select the FULL4WIRE (or HALF4WIRE for half-step control) interface type, because you’ll be individually controlling each coil’s signal.
  • In Simple Terms:
    Think of an H Bridge driver as a “translator” that converts simple commands (like “step” and “direction”) into the precise electrical switching needed to run your motor. If you’re using an H Bridge module with built-in circuitry, it makes things very simple—just use the DRIVER mode. If you’re handling the H Bridge design yourself, you’ll need to use one of the multi-wire modes (typically FULL4WIRE) to control everything manually.


Each MotorInterface type in the Accelstepper library is designed to match a different hardware wiring and control scenario. Whether you’re using a dedicated step/direction driver module (which often incorporates H Bridges internally) or directly managing the energizing of the motor coils with custom circuits, choosing the correct interface type is key to ensuring smooth and accurate motor movement.

This explanation should help clarify not only the various MotorInterface types but also where an H Bridge type driver fits into the picture.

ps -  For expediency, ChatGPT may have been involved in this answer.

Reply all
Reply to author
Forward
0 new messages