laurb9 / StepperDriver

Arduino library for A4988, DRV8825, DRV8834, DRV8880 and generic two-pin (DIR/STEP) stepper motor drivers
MIT License
557 stars 228 forks source link

Stepper.Disable() Issue #114

Closed IAmOrion closed 1 year ago

IAmOrion commented 2 years ago

Is there a bug, or am I doing something wrong?

Here's a snippet of my code (I say snippet, as I'm only pasting the relevant stepper motor bits): Also, note my if statement in this example is psuedo code, since the problem is not with the if statement anyways

#define DIR 14
#define STEP 13
#define EN 12

#define MOTOR_STEPS 200
#define RPM 500
#define MICROSTEPS 16

#include "BasicStepperDriver.h"
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, EN);

void setup() {
  stepper.setEnableActiveState(LOW);
  stepper.begin(DEFAULT_RPM, MICROSTEPS);
}

void loop() {
    if (turn on motor) { 
        stepper.enable();
        stepper.startMove(1000 * MOTOR_STEPS * MICROSTEPS);
    } else if (turn off motor) {
        stepper.stop();
        stepper.disable();
    }
}

All my other code works perfectly, starting & stopping works perfectly, the only problem I have is that stepper.disable doesn't appear to disable the motor regardless of hardware being used

The problem I have is it's never it never disabling the motor to allow me to move it buy hand. It's always energised and remains energised despite calling stepper.disable.

I've tried with an Arduino Uno + CNC Shield, I've tried with Arduino Uno + single driver module, I've tried Raspberry Pico RP2040 + single driver board.

Anyone got any ideas!?

dpichevin commented 1 year ago

I had the same issue but looking through the code gave me a good hint. For things to work with my A4988 driver, I need to connect the RESET pin to 5V (otherwise the motor does not turn) and to not bridge SLEEP and RESET together, but connect SLEEP to a digital pin (7 in the case of my nano) and define it in the sketch, then use it in the stepper() call (see in the "non blocking" example). With this, disable() works for me, the motor is no longer locked, and it can cool down. For enable/disable to fully work, one has to use either the SLEEP pin, or the ENABLE pin.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.