Nema 17 + A4988 ramp speed without potentiometer

Hi,

I got a Nema 17 stepper motor witch I am running with a A4988 stepper motor driver.
My goal is to drive a large heavy axis with it and it kind of works all ready by slowly increase the speed manually until it gets momentum.

I just wanna hit a button and it slowly speeds up and then I'd like to have a continuous spin after reaching a certain speed. If I push the button again it slowly stops.

Is there a good way to do this easy? Is there any library out there for this?

Thanks for a good forum!

Like this but it does not work.

void loop()
{  

  unsigned long currentTime = millis();
  for (int i = 0; i <= 6000 ; i+=100) {
    Serial.println(i);
    spd = i;
    stepper.setSpeed(dirr * spd);
    stepper.runSpeed();
    delay(2000);

  }

}

Please read the How to Use this Forum instructions so that you can post properly formatted code using code tags.

Pleas post the code you are using with the potentiometer. Do you know what the potentiometer values are to get the stepper moving, and what you use for final speed?

Is there any library out there for this?

The AccelStepper library allows you to set the acceleration and max speed. The Bounce example shows how to set acceleration and max speed. Might be a place to start.

basekson:
Like this but it does not work.

The function runSpeed() does not use acceleration. You need to use the function run()

...R

Thanks alot for all the responses.

I manage to do about everything I needed with this code below - now i just want to speed up 50-100% if it is possible.

int dir = 0;
 
void setup()
{
  Serial.begin(9600);
  stepper.setAcceleration(50);
  Serial.println("Arduino rdy for (S)art or (B)reak input.");
}
 
void loop()
{
  char c;
  if (Serial.available()) {
   
    c = Serial.read();
   
    if (c == 's') {  // start
      dir = 80000;
      Serial.println("Engine Power: ON.");
    }
 
    if (c == 'b') {  // break
      dir = 0;
      Serial.println("Engine Power: OFF.");
    }
   
  }
 
  stepper.move(dir);
  stepper.run();
}
  stepper.move(dir);
  stepper.run();

When you have stepper.move() in loop() like this it will keep updating the destination and AFAIK that will not give run() a chance to work through its acceleration. I would only do stepper.move() when a new command is received.

...R

I have tried to read everthing there is and it seams that it won't work because I have to combine both
setSpeed() and speedRun() to get it two go higher speed and then I won't have the acceleration.

You have not used setMaxSpeed() in your sketch.

/// Sets the maximum permitted speed. The run() function will accelerate
/// up to the speed set by this function.
/// Caution: the maximum speed achievable depends on your processor and clock speed.
/// The default maxSpeed is 1.0 steps per second.
/// \param[in] speed The desired maximum speed in steps per second. Must
/// be > 0. Caution: Speeds that exceed the maximum speed supported by the processor may
/// Result in non-linear accelerations and decelerations.
void setMaxSpeed(float speed);

Take a look at the"Bounce" library example again.

Maybe just write your own acceleration code. It's not particularly difficult - have a look at this Simple acceleration code.

...R