Using ENA+ and ENA-

192 views
Skip to first unread message

Ralph Hulslander

unread,
Feb 26, 2022, 3:28:25 PM2/26/22
to accelstepper
Would someone please post some working code that uses ENA+ and ENA-.

I "had" some working code but I have lost it and I have not been able to reconstruct it.

It was real simple code but I am lost.

Ralph

Ralph Hulslander

unread,
Feb 27, 2022, 3:34:24 PM2/27/22
to accelstepper
Here is my poor attempt at utilizing the ENA- and ENA+ on my Microstep stepper Driver:

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;

int Limit_1 = 11;
int ENA = 4;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   //myStepper.setSpeed(50);           // runSpeed() will run the motor at this speed - set it to whatever you like.
   myStepper.setSpeed(4000);   // [12495 works with METRO 12500 does not work]
    //pinMode(Limit_1,INPUT_PULLUP);      // sets the digital pin 11 as input
    pinMode(Limit_1,INPUT);
    pinMode(ENA, OUTPUT);    // sets the digital pin 4 as onput
     
}

void loop()
{  
  if (digitalRead(Limit_1 == LOW))
  {
    digitalWrite(ENA, HIGH);
    Serial.print("++++");      
    Serial.println(ENA);
  }
if (digitalRead(Limit_1 == HIGH))
  {
    digitalWrite(ENA, HIGH);      
    Serial.print(HIGH);
    Serial.print("-----");
    Serial.println(ENA);
  }
   myStepper.runSpeed();   // This will run the motor forever.
   
   //val = digitalRead(ENA);   // read the input pin
   //digitalWrite(ledPin, val);  // sets the LED to the button's value
}

The first thing is that none of Serial.print() appear.
The code appears to be ignored.
The Limit_1 button is a NO (Normally Open) momentary switch wired to GRN.
I have a LED wired with the switch which lights so Limit_1 is definitely going LOW.

Ralph

Mike McCauley

unread,
Feb 27, 2022, 3:40:00 PM2/27/22
to accels...@googlegroups.com
HEllo

this code is very wrong:
if (digitalRead(Limit_1 == LOW))
it will evaluate (Limit_1 == LOW) and use the result (0 or 1) as the pin
number to read.

You probably mean
if (digitalRead(Limit_1) == LOW)

Cheers.
--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Ralph Hulslander

unread,
Feb 27, 2022, 3:47:12 PM2/27/22
to accels...@googlegroups.com
Thanks Mike, 
I tried your suggested change:   (digitalRead(Limit_1) == LOW)

UnoAccelStepper_ConstantSpeed:26:35: error: expected primary-expression before ')' token

   if (digitalRead(Limit_1) == LOW))

                                   ^

UnoAccelStepper_ConstantSpeed:32:34: error: expected primary-expression before ')' token

 if (digitalRead(Limit_1) == HIGH))

                                  ^

Using library AccelStepper in folder: C:\Users\Ralph\Documents\Arduino\libraries\AccelStepper (legacy)

exit status 1

expected primary-expression before ')' token

Ralph

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/2619084.mvXUDI8C0e%40zulu.

Ralph Hulslander

unread,
Feb 27, 2022, 4:02:37 PM2/27/22
to accelstepper
Found my error:
if (digitalRead(Limit_1) == LOW))

But still nothing shows up with Serial.print().

Oh and did I mention I am not a programmer?

Ralph

Mike McCauley

unread,
Feb 27, 2022, 4:06:36 PM2/27/22
to accels...@googlegroups.com
Hello,

On Monday, 28 February 2022 06:47:01 AEST Ralph Hulslander wrote:
> Thanks Mike,
> I tried your suggested change: (digitalRead(Limit_1) == LOW)

Yes, thats what I wrote.

>
> UnoAccelStepper_ConstantSpeed:26:35: error: expected primary-expression
> before ')' token
>
> if (digitalRead(Limit_1) == LOW))

But thats not what you have.
Note the double close parens at the end of the line?

Perhaps you need to think more carefully about your code before asking for
help.

Jan (ftjuh)

unread,
Feb 27, 2022, 6:08:33 PM2/27/22
to accelstepper
Ralph, you just forgot to open the serial port in your setup. And one of the "HIGH"s in your two digitalWrite(ENA, HIGH);  should probably be a LOW.

As you stated yourself that you are a beginner, I suggest you start with a couple of more basic excercises and examples to get the knack of things.
Cheers, Jan

Ralph Hulslander

unread,
Feb 27, 2022, 8:53:43 PM2/27/22
to accelstepper
Jan, what do you mean "open the serial port"?
Should I be using RX and TX?

I had similiar code running but I can no longer find that code.
I did not use the serial port.

How much more basic is reading some pins and writing some pins?

You see why I asked if any one had working code.

Ralph

Peter Wright

unread,
Feb 27, 2022, 9:04:33 PM2/27/22
to accels...@googlegroups.com
Just click on the serial port icon near the top right hand of the Arduino screen


Sent from my iPad

On 28 Feb 2022, at 12:53 pm, Ralph Hulslander <rhuls...@gmail.com> wrote:

Jan, what do you mean "open the serial port"?

Jim Larson

unread,
Feb 27, 2022, 9:50:43 PM2/27/22
to accelstepper
Ralph - Regarding opening the serial port, you need a statement like
Serial.begin(115200);
Put that in setup() and the other Serial statements should work.

    -jim

Ralph Hulslander

unread,
Feb 28, 2022, 2:38:48 PM2/28/22
to accelstepper
Here is my current code:

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;

int Limit_1 = 11;
int ENA = 4;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
  Serial.begin(115200);

   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   //myStepper.setSpeed(50);           // runSpeed() will run the motor at this speed - set it to whatever you like.
   myStepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]

    //pinMode(Limit_1,INPUT_PULLUP);      // sets the digital pin 11 as input
    pinMode(Limit_1,INPUT);
    pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
     
}

void loop()
{  
  if (digitalRead(Limit_1) == LOW)
  {
    //digitalWrite(ENA, HIGH);
    digitalWrite(ENA, LOW);
    Serial.print("++++");      

    Serial.println(ENA);
  }

   myStepper.runSpeed();   // This will run the motor forever.
   
}

Thanks Jim Larsen for the motor run code.
I have ENA+ to 5v+

Now here is the problem, it does not work with my code.
Isn't that what the code should do, ground ENA- when Limit_1 is thrown?

With the motor running if I connect ENA- to pin 4 the motor stops with out touching the limit switch.
The motor coils are still energized, I cannot manually turn the motor.
With the hard wired method when the motor stops I can manually turn the motor. 
So with ENA- to pin 4 the motor coils are still engaged.

Thanks everyone for your help.

Ralph Hulslander

unread,
Feb 28, 2022, 2:58:43 PM2/28/22
to accelstepper
Well now that  Serial.begin(115200); the Serial Monitor is working I see another problem.

++++4
++++4
++++4
++++4
++++4
++++4
++++4
++++4

ENA is not being set LOW 

Serial.println(ENA); is showing the pin number! I was expecting 0.
digitalWrite(ENA, LOW); is not working
I tried digitalWrite(ENA, 0); but still get the same ++++4. 

I put my multimeter on GRN and pin 4 and I see -5 volts.
I guess that is why connecting ENA- to pin 4 would stop the motor.

Damm, it sure would be simpler to just modify someone else's working code.

Ralph

Ralph Hulslander

unread,
Feb 28, 2022, 3:33:52 PM2/28/22
to accelstepper
I don't "think" I want to use digitalWrite(ENA, LOW);

//ENA = LOW;
    ENA = HIGH;
    Serial.print("++++");
    Serial.println(ENA);

This now is giving me ENA high or low not the pin number!

But the motor still dies when I connect ENA- to pin 4.

Ralph

Jim Larson

unread,
Feb 28, 2022, 5:25:47 PM2/28/22
to accelstepper
Ralph -
Here's what I think is happening:
ENA is your enable pin control from the Arduino. You have defined it as 4. Anytime you refer to it, the value will be 4. That won't change. So if you do Serial.print(ENA), you will always print 4.
If you want the value of the enable pin, then you must read it, or keep track of what you set it to. So to print the value of the pin, use Serial.print(digitalRead(ENA)). To set the enable pin to a value, you must use digitalWrite like this: digitalWrite(ENA,HIGH) or digitalWrite(ENA,LOW);

Now the actual use of the enable signal by your motor controller. Since I don't have one of your controllers to test, all I can do is speculate - I use the term "think" to signal that. So, I think that you can use either the ENA+ input or the ENA- input. I don't think you want to try using them both. I think that the ENA+ line needs to be high to enable your controller, or that ENA- needs to be low to enable the motor. Remember, don't use them both. Leave the unused one unconnected to any signal.

If you are at all concerned about this working, then your scheme of tying the limit switch directly to the ENA (either + or -_) is a good one. You can also have the signal go to an input on the Arduino so you know it's state and can react if the limit switch is tripped - but your system will be protected no matter what.

HTH
       -jim

Ralph Hulslander

unread,
Feb 28, 2022, 8:00:08 PM2/28/22
to accels...@googlegroups.com
Thanks Jim, If I remove ENA+ to 5v+ the motor does not stop when I throw the limit switch.
My current code "should" be making ENA LOW but it does nothing when I engage the switch.

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;

int Limit_1 = 11;
int ENA = 4;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
  Serial.begin(115200);

   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   myStepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]

    pinMode(Limit_1,INPUT);
    //pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
   
    ENA = LOW;
    //ENA = HIGH;                  

}

void loop()
{  
  if (digitalRead(Limit_1) == LOW)
  {
    //ENA = LOW;
    ENA = HIGH;
    Serial.print("++++");
    Serial.println(ENA);
  }
   myStepper.runSpeed();   // This will run the motor forever.

++++1
++++1
++++1
++++1
++++1
++++1
++++1
++++1
++++1
++++1

I am throwing the switch but ENA never becomes LOW (0).

At least the hardwired switch is working so I could use that and not use the Arduino except to run the motor.
I wanted the Limit switch to disable the motor coils and after I manually backed the carriage off the limit switch
the carriage would return to Start (0).

Ralph

Jim Larson

unread,
Feb 28, 2022, 9:02:43 PM2/28/22
to accelstepper
Let me try again, Ralph. I didn't notice that you defined ENA as an int and therefor changeable.

ENA = HIGH changes the value of ENA from 1 to 4. You don't want to do that. You should define ENA as
const int ENA = 4.;
 ENA is then defined as 4. That's all it will ever be! You just have to use ENA as a pin number.

You need the statement (it's commented out)
pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
That configures ENA properly so you can set it.

Don't use either of these!!
ENA = LOW;
    //ENA = HIGH;
To set ENA low, use digitalWrite(ENA, LOW) or digitalWrite(ENA, HIGH).

Finally, to see the value ENA is set to, use
Serial.print(digitalRead(ENA));

Sorry for the confusion about ENA in my last post.

          -jim

gjgsm...@gmail.com

unread,
Feb 28, 2022, 9:10:14 PM2/28/22
to accelstepper
Jim is correct about the polarity of the driver ENA.
What follows may not be relevant to the discussion but may be of interest to some...

I don't know what driver is being used BUT, reading the user_manual/data_sheet of a typical driver it states...

Enable signal: This signal is used for enabling/disabling the drive. High level +5V (NPN control
signal) for enabling the drive and low level for disabling the drive. PNP and Differential control
signals are on the contrary, namely Low level for enabling.
By default it is left UNCONNECTED (ENABLED).

Ralph Hulslander

unread,
Mar 1, 2022, 2:45:37 PM3/1/22
to accelstepper
Getting close??

The tone of the motor changes when I press the Limit_1 button.
But the motor does not stop
At least I am seeing something from the button press, my previous attempts had no effect on the motor.
Either the motor would not run (without any button press) or the motor would run ignoring the button press.

Motor "tone" changes on switch press. Kinda annoying turn your volume down.

I moved the switch to A5 and incorporated Jim's suggestions.

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;
const int ENA = 4;
//int Limit_1 = 11;
int Limit_1 = A5;
//int ENA = 4;


AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
  Serial.begin(115200);

   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   myStepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]

    pinMode(Limit_1,INPUT_PULLUP);

    //pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
    //digitalWrite(ENA, HIGH);
    //digitalWrite(Limit_1, HIGH);

}

void loop()
{  
 
  if (digitalRead(Limit_1) == LOW)
  //if (digitalRead(Limit_1) == HIGH)
  {

    digitalWrite(ENA, LOW);
    //ENA = LOW;
    //ENA = HIGH;
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    //Serial.println(ENA);
    Serial.println(digitalRead(ENA));

  }
   myStepper.runSpeed();   // This will run the motor forever.
}

Ralph

Ralph Hulslander

unread,
Mar 1, 2022, 2:55:01 PM3/1/22
to accelstepper
I "think" this (if (digitalRead(Limit_1) == LOW)) is being ignored.
I am not getting any Serial.print() output.
But it is changing the tone of the motor.

if (digitalRead(Limit_1) == LOW)
  //if (digitalRead(Limit_1) == HIGH)
  {
    digitalWrite(ENA, LOW);
    //ENA = LOW;
    //ENA = HIGH;
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    //Serial.println(ENA);
    Serial.println(digitalRead(ENA));
  }

Ralph

Jim Larson

unread,
Mar 1, 2022, 3:30:10 PM3/1/22
to accelstepper
Yes, it's being ignored. You MUST initialize ENA as an output. Uncomment the line:

//pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
Otherwise, ENA will always be an input and reading it won't be accurate.

         -jim

Ralph Hulslander

unread,
Mar 1, 2022, 3:39:30 PM3/1/22
to accelstepper
If I use  pinMode(ENA, OUTPUT); the motor does not run!

Ralph

Ralph Hulslander

unread,
Mar 1, 2022, 3:46:23 PM3/1/22
to accelstepper
Using pinMode(ENA, OUTPUT); makes ENA HIGH which is why the motor does not run!
I have a LED wired in line with pin 4 ENA and the LED lights up with ENA OUTPUT.

Ralph

Jim Larson

unread,
Mar 1, 2022, 8:51:41 PM3/1/22
to accelstepper
The logic of the if (digitalRead(Limit_1) == LOW) clause implies that the motor stops if ENA goes low. But you say that the motor stops if ENA is high. Which way is it? You should set it correctly so the motor runs right after the pinMode statement in setup(). Then set it to dis-enable in the if (digitalRead(Limit_1) == LOW) clause in loop() Make sense?
    -jim

Ralph Hulslander

unread,
Mar 1, 2022, 9:49:26 PM3/1/22
to accelstepper
The motor does not STOP it never runs if ENA is high which is what happens if I use  pinMode(ENA, OUTPUT);

I am getting confused I want ENA HIGH in order to switch it LOW but if ENA is HIGH the motor does not run.

I had code that worked perfectly for a while but then after two or three days stopped working so I did 
not save the code. 

Tomorrow I am going to try using ENA+ on the Driver that at least will run with ENA HIGH.
But of course so far Limit_1 is being ignored.

Ralph

Ralph Hulslander

unread,
Mar 2, 2022, 1:37:51 PM3/2/22
to accelstepper
Does anyone have some working code that utilizes  setEnablePin()?

Possible that is what I need to set ENA- LOW.
Well I also need to set it HIGH first.

Ralph

Jim Larson

unread,
Mar 2, 2022, 3:43:53 PM3/2/22
to accelstepper
Using the setEnablePin() and associated command is explained in the Missing Manual

However, before you even mess with that, you need to sort out the control of you stepper driver. Which is it: HIGH or LOW to enable it? Have your Arduino drive the stepper continuously and try tying the ENA lines, one at a time high or low to see what it takes to make the driver stop the motor. If you don't know what level and signal to use, playing with the code won't help, IMHO.

           -jim

Ralph Hulslander

unread,
Mar 2, 2022, 3:50:19 PM3/2/22
to accels...@googlegroups.com
Thanks Jim, I know with a running motor (using your Constant Speed code) that I kill the motor with a switch to GRN.

I don't understand what I was getting with the ENA pin being high and killing the motor before it even ran.

But the switch definitely works.

I have not tried switching ENA+.

Ralph



Ralph Hulslander

unread,
Mar 2, 2022, 4:31:59 PM3/2/22
to accelstepper
I read the Missing Manual again.
But it is still over my head.

Does any of your example sketches use the setEnablePin()?

Ralph

Chris Toop

unread,
Mar 3, 2022, 11:38:44 AM3/3/22
to accelstepper
Hello Ralph

Been following this thread and thought I would post my version of your code that I run on my Teensy 4 using a 2100 SilentStepStick Driver.

#include <AccelStepper.h>

const int dirPin = 15;
const int stepPin = 14;
const int ENA = 4;
int Limit_1 = A5;

AccelStepper stepper (AccelStepper::DRIVER, stepPin, dirPin); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{  

   pinMode(Limit_1,INPUT_PULLUP); // Limit Switch needs to be 'pulled' LOW (connected to GND) to operate
   pinMode(ENA,OUTPUT); // ENA, enable pin is set to OUTPUT

   Serial.begin(115200);

   stepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   stepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]
   
   digitalWrite(ENA, LOW); // ENA pin is switched LOW, in code to initially stop the stepper from moving.
 
}

void loop()
{

  if (digitalRead(Limit_1) == LOW) // First 'if', Limit Switch is operated and pin input is grounded or LOW
  {

    digitalWrite(ENA, HIGH); // Switch ENA Pin High, Stepper Runs
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

  if (digitalRead(Limit_1) == HIGH) // Second 'if', Limit Switch is operated and pin input is 'PULLED UP' or HIGH. Basically not connected because you told the Limit-1 pin to be INPUT_PULLUP
  {

    digitalWrite(ENA, LOW); // Switch ENA Pin LOW Stepper Stops
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

   stepper.runSpeed();   // This will run the motor dependant on which 'if' statement is active.
 
}

I have added a second 'if' statement just so I could show that the Limit_1 and ENA pins change state and you can stop and start the stepper using the Limit_1 switch.

Hope that helps

Chris

Ralph Hulslander

unread,
Mar 3, 2022, 3:12:38 PM3/3/22
to accelstepper
Thanks Chris, I was hoping I wasn't boring any one.

Wow, your code almost works.

When I run the code the motor does not run but when press the button the motor runs.
At least I am finally seeing something happen from the button press.
Strange the Serial Monitor is showing:

1++++0
1++++0
1++++0
1++++0
1++++0
1++++0
1++++0
When the motor is not running.
Then when I press the button the previous results turn to:

0++++1
0++++1
0++++1
0++++1
0++++1
0++++1
0++++1

I do not get anything when Limit_1 has 5v+.

Thank you so much this is promising.

Ralph

Chris Toop

unread,
Mar 3, 2022, 4:55:05 PM3/3/22
to accelstepper
If you want the stepper to run when you load the code with the Limit_1 switch internally Pulled Up to 5V, not pressed in other words then just change the setup() statement  digitalWrite(ENA, LOW); to digitalWrite(ENA, HIGH);

then in the 'if statements change the first statement from if (digitalRead(Limit_1) == LOW)  to if (digitalRead(Limit_1) == HIGH) and the second from if (digitalRead(Limit_1) == HIGH)  to if (digitalRead(Limit_1) == LOW)


Chris..

Ralph Hulslander

unread,
Mar 3, 2022, 7:49:19 PM3/3/22
to accelstepper
This sketch is going to be added to Jim Larsen's great sketch he did for my motorized Z axis on my lathe.
This is for a Travel Limit switch to stop the Z axis motor. I have a heavy NEMA 34 motor on the Z axis and 
it could do a lot of damage if it uncontrollably hits my chuck or tailstock. I could use (stop) but with that
the coils are left energized and I want the coils to be deenergized.

Today I was looking at setEnablePin(); which appears would work if I was a programmer and knew how to use it.

I "think" I made your suggested changes but the motor does not run.

While the motor does not run Serial Monitor does reflect the button push:

1++++0
1++++0
1++++0
1++++0
1++++0
1++++0
1++++0

With button push becomes:
0++++0
0++++0
0++++0
0++++0
0++++0
0++++0
0++++0

#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;
const int ENA = 4;
int Limit_1 = A5;

AccelStepper stepper (AccelStepper::DRIVER, stepPin, dirPin); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{  

   pinMode(Limit_1,INPUT_PULLUP); // Limit Switch needs to be 'pulled' LOW (connected to GND) to operate
   //pinMode(Limit_1,INPUT); // Limit Switch needs to be 'pulled' LOW (connected to GND) to operate

   pinMode(ENA,OUTPUT);                  // ENA, enable pin is set to OUTPUT

   Serial.begin(115200);

   stepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   stepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]
   
   //digitalWrite(ENA, LOW);                   // ENA pin is switched LOW, in code to initially stop the stepper from moving.
   digitalWrite(ENA, HIGH);

}

void loop()
{

  if (digitalRead(Limit_1) == LOW) // First 'if', Limit Switch is operated and pin input is grounded or LOW
  {

    //digitalWrite(ENA, HIGH);            // Switch ENA Pin High, Stepper Runs
    digitalWrite(ENA, LOW);

    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

  if (digitalRead(Limit_1) == HIGH) // Second 'if', Limit Switch is operated and pin input is 'PULLED UP' or HIGH.
                                    // Basically not connected because you told the Limit-1 pin to be INPUT_PULLUP

  {

    digitalWrite(ENA, LOW);             // Switch ENA Pin LOW Stepper Stops
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

   stepper.runSpeed();   // This will run the motor dependant on which 'if' statement is active.
}

Chris Toop

unread,
Mar 4, 2022, 2:47:57 AM3/4/22
to accelstepper
Ooops!

One mistake that I made, try this corrected statement


  if (digitalRead(Limit_1) == HIGH) // Second 'if', Limit Switch is operated and pin input is 'PULLED UP' or HIGH.
                                    // Basically not connected because you told the Limit-1 pin to be INPUT_PULLUP

  {

    //digitalWrite(ENA, LOW);             // Switch ENA Pin LOW Stepper Stops
    digitalWrite(ENA.HIGH);               // This line changed

    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

I have changed one statement in the second 'if', not sure what happened there. Now it should run, for me this runs inverted i.e. when ENA is LOW it runs then when ENA is HIGH it stops which is the way my driver module operates.

You should see 1++++1 and 0++++0 within the Serial Monitor

Sorry for the mistake.

Chris..

Chris Toop

unread,
Mar 4, 2022, 3:25:07 AM3/4/22
to accelstepper
Regarding using setEnablePin(), enableOutputs() and disableOutputs() I think it only works when you have selected FULL4WIRE connectivity not when Step and Dir is used because it switches those 4 lines on or off
 Chris..

Ralph Hulslander

unread,
Mar 4, 2022, 2:04:58 PM3/4/22
to accelstepper
I see a simple conflict you are using  2100 SilentStepStick Driver which has a En pin.
I am using a  TB6600 Stepper Motor Driver which has ENA+ and a ENA- pins. 
I have been using ENA-. When hardwired ENA- to GRN stops the motor and disables the coils as desired.
I will experiment with ENA+ if nothing is working.

Ralph

Ralph Hulslander

unread,
Mar 4, 2022, 2:28:40 PM3/4/22
to accelstepper
It works!!
Not really sure why, as your latest was for the 2nd if but:

if (digitalRead(Limit_1) == LOW) // First 'if', Limit Switch is operated and pin input is grounded or LOW
  {
    digitalWrite(ENA, LOW);
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));
  }

IT WORKS!! 

I have a lot more to do so I will be posting my new questions back in my original

Thank you, Chris

Ralph

Ralph Hulslander

unread,
Mar 4, 2022, 2:54:58 PM3/4/22
to accelstepper
This is strange!!

I wondered why changing the 2nd if made the motor run?

Now if I comment out the 2nd if the motor does not run.

The motor does not run with this code:

void loop()
{

  if (digitalRead(Limit_1) == LOW) // First 'if', Limit Switch is operated and pin input is grounded or LOW
  {
    digitalWrite(ENA, LOW);
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));
  }

  /*


  if (digitalRead(Limit_1) == HIGH) // Second 'if', Limit Switch is operated and pin input is 'PULLED UP' or HIGH.
                                    // Basically not connected because you told the Limit-1 pin to be INPUT_PULLUP

  {

    //digitalWrite(ENA, LOW);            
    digitalWrite(ENA,HIGH);               

    Serial.print(digitalRead(Limit_1));
    Serial.print("++++");
    Serial.println(digitalRead(ENA));

  }

    */

   stepper.runSpeed();   // This will run the motor dependant on which 'if' statement is active.
 
}

Ralph

Ralph Hulslander

unread,
Mar 4, 2022, 3:07:21 PM3/4/22
to accelstepper
Duh, obviously I am not a programmer.

The first if fails so the 2nd if is looked at.
The 2nd if is True so it is executed.

tada it works.

Ralph

Jim Larson

unread,
Mar 5, 2022, 8:49:28 PM3/5/22
to accelstepper
Chris - You state that setEnablePin,() etc only works with FULL4WIRE. Not true - works with DRIVER also. However, you have to supply place holders for two additional pins. This could be fixed with a patch, I think. Anyway, have a ;ppl at the Missing Manual for details. Here:

         -jim

Chris Toop

unread,
Mar 6, 2022, 1:59:05 PM3/6/22
to accelstepper
Hello Jim, You are correct I misinterpreted the wording.

Chris..

Reply all
Reply to author
Forward
0 new messages