bblanchon / ArduinoContinuousStepper

An Arduino library to spin stepper motors in continuous motions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need a way to invert the logic state of the Enable pin

guillaume-dorczynski opened this issue · comments

Hello,

Please could you add an option to invert the Enable pin

My problem is with A4988 driver, the Enable pin is active LOW so using powerOn() doesn't work because it's setting the pin HIGH :)

For now, a workaround is to not use the enablePin parameter in begin() and handle the pin manually

Hi Guillaume,

Please test the setEnablePin() it added in the "issue6" branch.
I currently don't have the required hardware setup in place, so I could not test.
I'm waiting for your feedback before merging this branch.

Best regards,
Benoit

Merci

On line : https://github.com/bblanchon/ArduinoContinuousStepper/blob/issue6/ContinuousStepperBase.h#L42

I think it would be better to start with the Enable pin disabled, and let user call powerOn() later. Currently the motor is immediately powered on when begin() is called, which I believe is not what most people expect

which I believe is not what most people expect

I'm glad to get your opinion on this.
I thought that, on the contrary, people would be surprised if calling spin() wouldn't start the motor immediately.

Sorry for yet another problem, I should have tested your changes more carefully

In previous version, in begin() you called powerOn(), which sets _status = WAIT to allow motor to move. But now you removed powerOn() from begin(), so _status is not set correctly and the motor will not move, until powerOn() is called by user, even after setEnablePin() was called or if the enable pin is not connected to the arduino (so that it's enabled by the driver board)

So basically, this problem made your library work as I expected : the motor doesn't move if powerOn() was not called by user - except that the motor is enabled, which is exactly what I didn't want :D

I made another example, it's almost the same code as my previous example, but now I included the code of your library directly so you can modify it and do live testing to solve the issue(s). See the comment in setup() :

https://wokwi.com/projects/345591766472196690

I just (forced-) pushed the fix for the _status = WAIT and added a third parameter to setEnablePin() so you can control the initial state:

stepper.setEnablePin(10, LOW, false);

I can see the changes to setEnablePin (thanks!), but no changes of _status in begin() so there is still a problem if user doesn't use setEnablePin (for example if he didn't connect the Enable pin to the arduino)

OK, this is a complete disaster.
I removed the changes from the master branch and will take the time to work on this correctly.
Sorry about that; it really is not representative of how I usually work.

I agree, need to think of a better way to do this. You can't just initialize _status to WAIT, or powerOn() will be useless because of the condition if (_status != OFF) return;

Yes, I use your awesome ArduinoJSON library, I know you can do better than that :D

The new (tested) version is available on the master branch.
Note that I didn't restore the three-parameters version of setEnablePin(); instead, you must call powerOff() first.
For example:

stepper.begin(10, 11);
stepper.powerOff();
stepper.setEnablePin(12, LOW);  // set pin 12 to HIGH

Please give it a try.
I'll publish a new release as soon as you confirm it works.