For a small home project I need to control four stepper motors individually. The Arduino UNO CNC shield looks perfect, it seems it can drive four stepper motors as it allows driving four stepper drivers. However, when looking at example code, e.g. link then I see only three stepper motors being driven (i.e. x y and z).
How is the fourth driver used?
Can it also fully drive a stepper motor as well? Referring to the fact that the CNC shield uses Arduino PWM ports of which the UNO only has three (and not four...)
Hi MicroBahner, thanks for replying. I got it, I mistakenly thought that the board was using PWM as the UNO's PWM pins were used. However, at closer inspection the PWM function of these pins isn't used, they are just used as normal digital pins.
By adding two jumpers (orange and green box) at the location shown in the picture the Driver A can be controlled by using pins 12 and 13.
You use the 4th motor (A) just like the other 3 except the step pin for the A is pin 12 and the dir pin is pin 13 once the jumpers are in place. That means that you no longer have the spindle enable or spindle direction control.
#define CW 0
#define CCW 1
const byte stepPin = 12; // x axis > 2, y axis > 3, z axis > 4 a axis > 12
const byte dirPin = 13; // x axis > 5, y axis > 6, z axis > 7 a axis > 13
const byte enablePin = 8; // enable on the CNC shield is held HIGH (disabled) by default
unsigned long stepTime = 2400;
void setup()
{
Serial.begin(115200);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW); // enable steppers
digitalWrite(dirPin, CCW);
}
void loop()
{
oneStep();
}
void oneStep()
{
static unsigned long timer = 0;
unsigned long interval = stepTime;
if (micros() - timer >= interval)
{
timer = micros();
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
}
}
If you need a limit (home) switch for the A axis (as well as x, y, z), you will need to use one of the analog pins for the sensor.