Problem with stepper motor and AccelStepper Library

Hi guys

I'm driving a Nema 17 stepper motor with the Sb6600 Driver. In my code I'm doing a homing of the motor in setup until an end switch gets activated. Strangely the homing worked, now suddenly the motor won't home anymore. I do get into the while (EndSwitch is HIGH). Everything else in the loop works just fine.
Does anyone have an idea?

#include <LiquidCrystal.h>
#include <AccelStepper.h>


LiquidCrystal lcd(8,9,4,5,6,7);

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

const int dirPin = 2;
const int stepPin = 3;
#define motorInterfaceType 1

AccelStepper myStepper(motorInterfaceType, stepPin, dirPin);

long int Pot = A0;
long int Pot2 = A1;
long int PotVal;
long int PotVal2;
long int Val;
long int Val2;
long int TargetStep;
int EndSwitch = 13;

void setup() {

pinMode(Pot, INPUT);
pinMode(Pot2, INPUT);
pinMode(EndSwitch, INPUT_PULLUP);
Serial.begin(9600);

  lcd.begin(16,4);

  lcd.setCursor(0,0);

  lcd.print("Homing Motor");

  myStepper.setMaxSpeed(1000);
  myStepper.setAcceleration(50);
  myStepper.setSpeed(100);

//int End = digitalRead(EndSwitch);

delay(50);

while(digitalRead(EndSwitch)){
  myStepper.move(-10000);
  myStepper.run();
  delay(5);

}

  delay(500);
  myStepper.setCurrentPosition(-2000);
  
lcd.setCursor(0,0);
lcd.print("Homing Complete!");

delay(1000);


}

In the way how you did it the motor will keep moving even when the switch is disconnected.

The switch should be normally closed.

Try this:

Make a test sketch exercising just the end switch. Measuring using a DMM could also work.

To achieve maximum security, yes. For this project, not the cause of the trouble.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.