Move after initial stop

47 views
Skip to first unread message

Declan C

unread,
Jun 21, 2025, 8:01:17 AMJun 21
to accelstepper
I "runSpeed();" until input from a IR sensor.
This works great.
Once the stepper has stopped, I must run the stepper for a few steps.
I have tried the following, but it does not work:

  stepper23.setCurrentPosition(0);
  stepper23.setMaxSpeed(10000);
  stepper23.setSpeed(-3000);
  stepper23.moveTo(100);
  stepper23.runSpeedToPosition();

Jim Larson

unread,
Jun 21, 2025, 3:51:23 PMJun 21
to accelstepper
There are four potential problems I see. Without seeing the rest of your code, here is what I see.
1. The runSpeedToPosition() function is just like runSpeed() and run(). It must be called frequently in the loop(). It does NOT block. I can't tell if it's in a loop or not, I'm guessing not.
2. The moveTo() function commands a move to a specific absolute position. Based on your description, you may want to use move() which moves relative to the current position. Then you don't need setCurentPosition(0).
3. If you use either move() or moveTo(), you should note the following caution from the Missing Manual : "Caution: move() also recalculates the speed for the next step.  If you are trying to use constant speed movements, you should call setSpeed() after calling move()." The same is true of moveTo().
4. Your setting of the speed as -3000 is unnecessary. You could just use 3000, but call setSpeed() AFTER you call moveTo() or move().

if you are still having problems, please post all of your code, or all of an example that demonstrates the problem.

HTH
       -jim

Declan C

unread,
Jun 22, 2025, 1:50:37 AMJun 22
to accelstepper
This is my code, which works great:
void loadLabels() {
  irPinStatus = analogRead(irPin);
  digitalWrite(enable23, LOW);  // Enable Stepper23
  if (irPinStatus > 30) {
    // timeBegin = millis();// For later use
    timeBegin = millis();
    do {
      irPinStatus = analogRead(irPin);
      stepper23.setMaxSpeed(10000);
      stepper23.setSpeed(-3000);
      stepper23.runSpeed();
    } while (irPinStatus > 30);

  } else if (irPinStatus < 30) {
    timeEnd = micros();
    pushLabel();
    loadingLabels = false;

  }
  // unsigned long duration = timeEnd - timeBegin; // For later use
  lcd.clear();
  lcd.print("Loading Complete");
  // lcd.setCursor(2, 1); // For later use
  // lcd.print(duration);
  // delay(2000);
  // backExit();
}

Jim Larson

unread,
Jun 22, 2025, 3:19:23 PMJun 22
to accelstepper
So I am assuming that the code you originally posted is to go in the pushLabel() function. You might try this:
void pushLabel() {
  stepper23.setCurrentPosition(0);
  stepper23.moveTo(100);
  stepper23.setSpeed(-3000);
  do {
    stepper23.runSpeedToPosition();
  } while (stepper23.distanceToGo() != 0);
}
Note that you have already called setMaxSpeed().

    -jim

Declan C

unread,
Jun 23, 2025, 1:52:50 AMJun 23
to accelstepper
Nope, this does not work 

void pushLabel() {
  stepper23.setCurrentPosition(0);
  stepper23.moveTo(1000);
  stepper23.setSpeed(-3000);
  do {
    stepper23.runSpeedToPosition();
  } while (stepper23.distanceToGo() != 0);
}

Jim Larson

unread,
Jun 23, 2025, 9:05:16 PMJun 23
to accelstepper
Normally, I would try this out on my own set up and see what's wrong. Unfortunately, I'm leaving on vacation tomorrow and will be gone for about a month!
In the mean time, I suggest you experiment. Use the reporting functions (see the Missing Manual) to find out what AccelStepper thinks it's trying to do. A few experiments should help you untangle things - especially since you have some code that works.

Sorry I can't help more.

                -jim
Reply all
Reply to author
Forward
Message has been deleted
0 new messages