Reversing Direction with runSpeed()

8,446 views
Skip to first unread message

Nelson Wang

unread,
Apr 21, 2014, 4:12:12 AM4/21/14
to accels...@googlegroups.com
Hey,

So I'm having an issue with reversing the direction using just runSpeed. I've looked through examples and questions, and it sounds like you can set speed to be a negative value for it to go CCW. However, when I tried that out, my motor still moves in the clockwise direction. I'm using a stepper motor from sparkfun with the bigeasydriver. Here's my code:

#include <AccelStepper.h>

const int stepsPerRevolution = 400;
const int microstep = 16;
int rpm = 2*60;
float sensorSpeed = 12800;

int motorDirPin = 10; //digital pin 2
int motorStepPin = 11; //digital pin 3

//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper sensor_motor(1, motorStepPin, motorDirPin); 

void setup()
{
  Serial.begin(115200);
  sensor_motor.setCurrentPosition(0);
  sensor_motor.setMaxSpeed(sensorSpeed);
  sensor_motor.setSpeed(-1*sensorSpeed);
}

void loop()
{
  sensor_motor.runSpeed();
}

Any advice?

Mike McCauley

unread,
Apr 21, 2014, 4:45:51 AM4/21/14
to accels...@googlegroups.com
Hi,

On Monday, April 21, 2014 01:12:12 AM Nelson Wang wrote:
> Hey,
>
> So I'm having an issue with reversing the direction using just runSpeed.
> I've looked through examples and questions, and it sounds like you can set
> speed to be a negative value for it to go CCW. However, when I tried that
> out, my motor still moves in the clockwise direction. I'm using a stepper
> motor from sparkfun with the bigeasydriver. Here's my code:

runSpeed steps the motor at a constant speed from its current position towards
the target position.

>
> #include <AccelStepper.h>
>
> const int stepsPerRevolution = 400;
> const int microstep = 16;
> int rpm = 2*60;
> float sensorSpeed = 12800;
>
> int motorDirPin = 10; //digital pin 2
> int motorStepPin = 11; //digital pin 3
>
> //set up the accelStepper intance
> //the "1" tells it we are using a driver
> AccelStepper sensor_motor(1, motorStepPin, motorDirPin);
>
> void setup()
> {
> Serial.begin(115200);
> sensor_motor.setCurrentPosition(0);
> sensor_motor.setMaxSpeed(sensorSpeed);
> sensor_motor.setSpeed(-1*sensorSpeed);
> }
>
> void loop()
> {
> sensor_motor.runSpeed();
> }
>
> Any advice?

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

Harrzack

unread,
Apr 28, 2014, 8:18:31 AM4/28/14
to accels...@googlegroups.com
The Big Easy Driver has a DIR pin - High one one, Low the other. You could keep your code 'direction independent' and just update DIR. I've done it while the motor is stepping! I think most driver boards/boxes offer this feature.

=Alan R.

M Fereidani

unread,
Aug 15, 2016, 11:59:56 PM8/15/16
to accelstepper
I have the same issue, I'm using easydrive, I tried to LOW/HIGH the direction pin on the driver but still there is no change in the direction, here's my code, thank you


#include <AccelStepper.h>

// Define two steppers and the pins they will use

AccelStepper stepperRA(1, 9, 8);

void setup()

   stepperRA.setMaxSpeed(1000);
   stepperRA.setSpeed(800);
 
}


void loop()
{
 digitalWrite(8,HIGH) //changing HIGH/LOW here makes no difference

  stepperRA.runSpeed();

gregor christandl

unread,
Aug 16, 2016, 2:18:03 AM8/16/16
to accelstepper
When using runSpeed(), stepper direction is controlled via the setSpeed() function. Set a positive speed for clockwise and a negative speed for counter clockwise rotation.

--
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.
For more options, visit https://groups.google.com/d/optout.

Andrei Dumitriu

unread,
Jan 4, 2019, 2:45:05 PM1/4/19
to accelstepper
Sure, but isn't setSpeed() calculated in moveTo()? Isn't that the point of moveTo(), in order for them to finish at the same time?

gregor

unread,
Jan 9, 2019, 2:54:52 PM1/9/19
to accelstepper
Do you mean AccelStepper or MultiStepper?

Andrei Dumitriu

unread,
Jan 10, 2019, 11:00:39 AM1/10/19
to accelstepper
I'm thinking of MultiStepper's moveTo(), which, from what I understand, calculates the speed for each stepper in order for them to reach the destination at the same time (so, theoretically, one call from moveTo() is enough?).

Accelstepper's moveTo() specifies that it only calculates the speed for the next step.

gregor

unread,
Jan 10, 2019, 11:37:09 AM1/10/19
to accelstepper
you are correct. my bad - I thought you were asking about AccelStepper.
Reply all
Reply to author
Forward
0 new messages