I am building a 2-Axis gantry system to dispense some thermal paste on boards. I was given two stepper motors in order to do so along with a gantry already built that will arrive in two weeks. So basically I just need to figure out how to drive them on the software side. However the boss demands testable code to be finished by EOB tomorrow, despite the hardware not being here yet. So I drafted some quick code that should drive a stepper motor, it's an easy open loop system, but I'm struggling. The operator will home the gantry after each cycle so it's just a matter of getting the motors moving.

My method was as follows:

#include <Stepper.h>
*declaring the stepper and all that goes here*
void loop(){ etc.
   basic logic flow stuff
   stepper.step(20); // to move forward twenty steps 
   stepper.step(-20) // to move back twenty steps

However my boss says this is incorrect as I need to be giving the steppers both step and direction.

After some tenuous google searching he recommended I use the AccelStepper library to fix this problem. After looking through this library I'm unsure how this will give me anything I need (distances are so small acceleration is useless) and how I am not giving it both step and direction in my original example code, I give it steps (20) and a direction with my negative/positive coefficient.

Am I correct in my thinking? Is there a better solution neither of us have found? I'd love to understand not just that I'm wrong, but why I am.

  • 1
    Does your boss not realize that the polarity of the number is the direction? Jun 11, 2015 at 2:38
  • @IgnacioVazquez-Abrams thats what I responded with. He just seemed confused and said something about direct driving. I am not one to question him, he's been in the CNC business longer then I've been alive. I'll suggest this during our standup tomorrow morning.
    – John Ham
    Jun 11, 2015 at 2:47
  • You should read this: cncroutersource.com/cnc-control.html "First lets review how the computer or the stand alone user interface communicates to the controller. Most systems today operate on a step and direction format of command signals. Some higher end machines use a proprietary analog or digital signal, but it is usually a variation of the step and direction format." Probably your boss wanted to tell you that the protocol from the PC to Arduino (or standard CNC protocol) differs from the way the stepper library works
    – aaa
    Jun 11, 2015 at 7:54
  • Also, I'm guessing stepper motors have a rather tricky way of working, they use combinations of pins for rotating, in which forward differs from backward. Your boss might be talking about this, while you're using the arduino library which covers up all the direct hardware interfacing. You should tell him, or even better, show him with an image that you're using the arduino as a controller, which has software instructions that will drive the stepper.
    – aaa
    Jun 11, 2015 at 8:06
  • 1
    Sorry for all the commotion on your thread. It comes down to this: Your boss (probably) wants you to implement the driving off the stepper motors yourself, withouth using the arduino library. You should check some tutorials on stepper motors. And ask him if he wants you to drive the coil pairs 'manually' rather than using a library. He's most likely to say yes (as this is how the pro's do it? :D or how you should learn it.).
    – aaa
    Jun 11, 2015 at 8:19

1 Answer 1


I think there is some mis-communication between you and your boss. I do not think your boss is stupid, but I do think he's talking on a different level as you do. You're using arduino which covers up a lot of hardware-interfacing, especially with steppers. I suggest you check out this video: https://www.youtube.com/watch?v=bngx2dKl5jU (I haven't watched it, but It will help you get more into the ideas of your boss)

Now you understand your boss's view, you can try to show him your view. When talking about steppers/arduino and how you can put in negative steps, he might think you're talking trash, as steppers require different pairs of coils to be active depending on the direction. (which is all handled by arduino) The best way is to provide him a visual guidance, so that he can see the relation with his (hardware-view) on the issue and your software/arduino solution.

You could make something like the image below. I'm not sure if this is what you're trying to tell him. I guess you should mention/add that the software on the arduino takes integer values, with negative values being clockwise or such. And that the arduino will convert this to the right coil pairs or direction and step.

P.S:with direct driving, I think he meant toggling the right pins at the right moments so that the stepper will rotate, basically what the stepper library does for you. Maybe he wants you to implement something like the stepper library (is it an internship? so that you can learn?) I suggest you check some tutorials on how stepper motors work, and how you can drive them 'directly' withouth the use of libraries.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.