Stepper Speed Control with Potentiometer / Rotation Direction

2,994 views
Skip to first unread message

Ali

unread,
Oct 25, 2014, 7:26:31 PM10/25/14
to accels...@googlegroups.com
Hi everyone,

I want to control a stepper motor with an Arduino mega 2560 and accelstepper library. I want to be able to control the speed of the motor with a potentiometer. The stepper has 200 steps/rev. I tried to modify the ConstantSpeed example in the library, but I end up getting weird results. 
If I change the speed in the code (hard coding the speed!), everything's fine. But when I try to change the speed with the pot, I end up getting speeds that are ((0.5)^n)*MaxSpeed. I used the map function for changing the pot value and map it into the my speed range.
another thing that I've noticed, is that I can't change the rotation direction with trying a negative value in setSpeed function. The only thing that happens when I set a negative value for the speed, is that the speed goes crazy! +3200 rotates at exactly 1 rev/sec while -3200 gives something about 2 rev/sec! Another thing is the speed itself! Why should the motor function in 1/16 steps mode when I haven't changed anything in the driver! My initial thought was that I should get 1 rev/sec with setSpeed(200) since my motor is 200 steps/rev. But as I mentioned, that's not the case.

Any help or suggestion would be much appreciated!

Oh, BTW here's the code:


#include <AccelStepper.h>


AccelStepper stepperRot(AccelStepper::FULL4WIRE, 2, 3, 9, 8);

int potPin = A1;
void setup()
{  
     pinMode(potPin, INPUT);

     stepperLin.setMaxSpeed(10000);
     stepperLin.setSpeed(3000);
     stepperRot.setMaxSpeed(10000);
   
}

void loop()
{  
  int potValue = analogRead(potPin);
  int stepSpeed = map(potValue, 0, 1023, 0, 6400);
  stepperRot.setSpeed(stepSpeed);
  stepperRot.runSpeed();
}


To add to that, I found that when I change the position of the first two pins in the stepper construction, I end up getting the reverse direction!

Thanks folks.

Mike McCauley

unread,
Oct 25, 2014, 10:17:12 PM10/25/14
to accels...@googlegroups.com
Hello,

analogRead is quite slow. You should not call slow things every time through
the main loop. It slows down the main loop too much. Try sampling the pot
every 200ms or so.

Cheers.
--
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

Brian Schmalz

unread,
Oct 26, 2014, 8:52:46 AM10/26/14
to accels...@googlegroups.com
Ali,

Look at Example #5 on this page : http://www.schmalzhaus.com/EasyDriver/Examples/EasyDriverExamples.html

It might give you some ideas.

*Brian
________________________________________
From: accels...@googlegroups.com [accels...@googlegroups.com] on behalf of Mike McCauley [mi...@airspayce.com]
Sent: Saturday, October 25, 2014 9:17 PM
To: accels...@googlegroups.com
Subject: Re: [accelstepper] Stepper Speed Control with Potentiometer / Rotation Direction

Hello,

Cheers.

--
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.

Jon Magill

unread,
Oct 26, 2014, 10:52:38 AM10/26/14
to accels...@googlegroups.com
And to answer your question about 1/16th steps, you didn't tell us what driver you're using.

The Big Easy Driver defaults to 1/16th steps, while the Pololu drivers default to full steps. You have to read the specs for the driver you're using and tie the MS0, MS1, MS2, etc. HI or LOW electrically, or with pins and code, to change the step size.

--Jon

Reply all
Reply to author
Forward
0 new messages