Controlling multiple stepper motor using arduino

Hi,
I am new to Arduino Environment and wanted to get some help with my project.
First of all about my project:
I am using Arduino Uno to drive multiple stepper motors, say around 4 NEMA 17 motors.
I am using the DRV2285 driver module which requires STEP and DIR pin from Arduino.
I know the basics of the stepper motor but my project requires some complicated stuff.

I don't want any particular code, I just want to understand the concept so that I can write code myself.
So my concern is as follows:
As I want is to drive multiple stepper motors I can't use the delay function as it would drive one stepper at a time, but I want all to drive them simultaneously at different speeds and different intervals. So I did some googling and found out about MILLIS() function. I tried writing code using that but I am unsuccessful.

As you know to drive a stepper motor we drive STEP Pin high and low(ie. give pulse) with some interval between them. The code is as follows:

digitalWrite(stepPin, HIGH);
delayMicroseconds(300);
digitalWrite(stepPin, LOW);
delayMicroseconds(300);

So I am unable to figure out how to implement this using millis() function? Please explain to me with some examples.

Also, I don't know Object-oriented programming that much but I have seen people creating classes for basic stepper movement and then call out in the main loop? How to do that, please help me in layman's terms I am new to this.
I am attaching a photo that roughly gives the idea of how will the steppers moving simultaneously.
Any help would be appreciated. Thanks

Starting point is AccelStepper which allows non-blocking control of steppers -
use setMaxSpeed() and setAcceleration() in setup(), call run() frequently (ie
in the loop() function), and whenever you want to start a movement call move()
or moveTo() functions - make sure run() is called repeated and often (dont use
delay() anywhere, basically).

AccelStepper has various examples, some are non-blocking and some are blocking.

For concerted movement of multiple steppers there's the MultiStepper library
that builds on AccelStepper, or for move advanced stuff GRBL is worth looking at.

If you want to program it yourself, still start by studying these libraries.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.