Skip to content

Instantly share code, notes, and snippets.

@trecno
Created October 12, 2023 21:52
Show Gist options
  • Save trecno/59eca43d10d3485f51606efe14a3bfa3 to your computer and use it in GitHub Desktop.
Save trecno/59eca43d10d3485f51606efe14a3bfa3 to your computer and use it in GitHub Desktop.
CNC Shield Test
const int StepX = 2;
const int DirX = 5;
const int StepY = 3;
const int DirY = 6;
const int StepZ = 4;
const int DirZ = 7;
const int StepA = 12;
const int DirA = 13;
void setup() {
Serial.begin(9600); // Initialize hardware serial for debugging
pinMode(StepX, OUTPUT);
pinMode(DirX, OUTPUT);
pinMode(StepY, OUTPUT);
pinMode(DirY, OUTPUT);
pinMode(StepZ, OUTPUT);
pinMode(DirZ, OUTPUT);
pinMode(StepA, OUTPUT);
pinMode(DirA, OUTPUT);
}
void loop() {
// Motor X
digitalWrite(DirX, LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 800; x++) {
digitalWrite(StepX, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepX, LOW);
delayMicroseconds(700);
}
delay(1000); // One second delay
digitalWrite(DirX, HIGH);
for(int x = 0; x < 800; x++) {
digitalWrite(StepX, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepX, LOW);
delayMicroseconds(700);
}
delay(1000);
// Motor Y
digitalWrite(DirY, LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 800; x++) {
digitalWrite(StepY, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepY, LOW);
delayMicroseconds(700);
}
delay(1000); // One second delay
digitalWrite(DirY, HIGH);
for(int x = 0; x < 800; x++) {
digitalWrite(StepY, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepY, LOW);
delayMicroseconds(700);
}
delay(1000);
// Motor Z
digitalWrite(DirZ, LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 800; x++) {
digitalWrite(StepZ, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepZ, LOW);
delayMicroseconds(700);
}
delay(1000); // One second delay
digitalWrite(DirZ, HIGH);
for(int x = 0; x < 800; x++) {
digitalWrite(StepZ, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepZ, LOW);
delayMicroseconds(700);
}
delay(1000);
// Motor A
digitalWrite(DirA, LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 800; x++) {
digitalWrite(StepA, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepA, LOW);
delayMicroseconds(700);
}
delay(1000); // One second delay
digitalWrite(DirA, HIGH);
for(int x = 0; x < 800; x++) {
digitalWrite(StepA, HIGH);
delayMicroseconds(700); // by changing this time delay between the steps we can change the rotation speed
digitalWrite(StepA, LOW);
delayMicroseconds(700);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment