Hi people. This might be nothing new, but if it can help running 3D-printers and CNC-Routers even on the smallest Arduinos.

Check it out.

#######################################

/*

This is the simplest way I could find to run multiple Steppers simultaneously

with different speeds and diffenrent directions with no lost steps on even

the smallest Arduino availible.

use:

void Multi_Step(

float Time, <-- Time to run the motors (same time for all)

unsigned long int Steps_X, <-- Steps for X-Axes

unsigned long int Steps_Y, <-- Steps for Y-Axes

unsigned long int Steps_Z, <-- Steps for Z-Axes

unsigned long int Steps_A <-- Steps for A/E-Axes

){

Multi_Step(1000,100,200,300,400) will run

100 steps on X-Motor &

200 steps on Y-Motor &

300 steps on Z-Motor &

400 steps on A/E-Motor

within 1000 miliseconds (one second)

Down't forget to set the pins for directions, before running the motors.

*/

unsigned int Xstep=1;

unsigned int Xdir=2;

unsigned int Ystep=3;

unsigned int Ydir=4;

unsigned int Zstep=5;

unsigned int Zdir=6;

unsigned int Astep=7;

unsigned int Adir=8;

unsigned int Amp=9;

void setup() {

pinMode(Xstep, OUTPUT);

pinMode(Xdir, OUTPUT);

pinMode(Ystep, OUTPUT);

pinMode(Ydir, OUTPUT);

pinMode(Zstep, OUTPUT);

pinMode(Zdir, OUTPUT);

pinMode(Astep, OUTPUT);

pinMode(Adir, OUTPUT);

pinMode(Amp, OUTPUT);

digitalWrite(Amp, 1);

digitalWrite(Xdir, 0);

digitalWrite(Ydir, 0);

digitalWrite(Zdir, 0);

digitalWrite(Adir, 0);

}

void Multi_Step(

float Time,

unsigned long int Steps_X,

unsigned long int Steps_Y,

unsigned long int Steps_Z,

unsigned long int Steps_A

){

unsigned long int Loops=Time*float(6.5);// use 6.5 on 16Mhz
boolean XS=1;
boolean YS=1;
boolean ZS=1;
boolean AS=1;
float DividerX=float(float(Loops)/float(Steps_X*4));

float DividerY=float(float(Loops)/float(Steps_Y

*4));*

float DividerZ=float(float(Loops)/float(Steps_Z4));

float DividerZ=float(float(Loops)/float(Steps_Z

float DividerA=float(float(Loops)/float(Steps_A*4));

unsigned long int V2X;

unsigned long int V2Y;

unsigned long int V2Z;

unsigned long int V2A;

unsigned long int VX=0;

unsigned long int VY=0;

unsigned long int VZ=0;

unsigned long int VA=0;

for (unsigned long int T=0;T<=Loops;T++){

V2X=T/float(DividerX);

V2Y=T/float(DividerY);

V2Z=T/float(DividerZ);

V2A=T/float(DividerA);

if (V2X!=VX){

digitalWrite(Xstep, XS);

XS=XS xor 1;

}

if (V2Y!=VY){

digitalWrite(Ystep, YS);

YS=YS xor 1;

}

if (V2Z!=VZ){

digitalWrite(Zstep, ZS);

ZS=ZS xor 1;

}

if (V2A!=VA){

digitalWrite(Astep, AS);

AS=AS xor 1;

}

VX=V2X;

VY=V2Y;

VZ=V2Z;

VA=V2A;

}

}

//run some example-turns

void loop() {

Multi_Step(5000,1600,800,400,200);

Multi_Step(4000,1600,800,400,200);

Multi_Step(3000,1600,800,400,200);

Multi_Step(2000,1600,800,400,200);

Multi_Step(3000,1600,800,400,200);

Multi_Step(4000,1600,800,400,200);

Multi_Step(5000,1600,800,400,200);

Multi_Step(4000,1400,1000,200,400);

Multi_Step(3000,1200,1200,400,200);

Multi_Step(2000,1000,1400,200,400);

Multi_Step(3000,800,1600,400,200);

Multi_Step(4000,600,1800,200,400);

}