Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stepper motor limit switches #444

Open
DarwinWasWrong opened this issue Nov 9, 2022 · 2 comments
Open

Stepper motor limit switches #444

DarwinWasWrong opened this issue Nov 9, 2022 · 2 comments
Labels
enhancement New feature or request open for vote Vote at https://wokwi.com/features

Comments

@DarwinWasWrong
Copy link

when coding for stepper motors, it would be very handy for have some form of limit switches logic.

Describe the solution you'd like
either two switches on the motor rotation able to be positioned in the 360 degrees
or
a attribute of switch 1 on/off at 3203 steps, switch 2 of/on at 10 steps

the you could code for like - home positioning or limits interrupts

@DarwinWasWrong DarwinWasWrong added the enhancement New feature or request label Nov 9, 2022
@urish urish added the open for vote Vote at https://wokwi.com/features label Nov 15, 2022
@urish
Copy link
Contributor

urish commented Nov 15, 2022

Thanks! opened this for voting

@drf5n
Copy link

drf5n commented Jan 17, 2024

You can simulate limit switches with a function in your code. If, for example, you were using AccelStepper to drive the steppers, maybe something like this:

void simLimitSwitches() {
  const byte lowLimitPin = 13;
  const byte highLimitPin = 12;
  static long lastPos = 0;
  static bool initialized = false;
  if(initialized == false){
    pinMode(lowLimitPin,OUTPUT);
    pinMode(highLimitPin,OUTPUT);
    initialized = true;
  }
  long nowPos = stepper.currentPosition();
  if (nowPos != lastPos) {
    lastPos = nowPos;
    digitalWrite(lowLimitPin, nowPos < 30 ? HIGH : LOW);
    digitalWrite(highLimitPin, nowPos > 3000 ? HIGH : LOW);
  }
}

I dropped that function into https://wokwi.com/projects/327381547863769683 and called it inside loop(), and it toggles the LED_BUILTIN appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request open for vote Vote at https://wokwi.com/features
Projects
None yet
Development

No branches or pull requests

3 participants