// Coil Winder Sketch 39 AWG, 150 winds per layer. 1:10 ratio, 1:1:10 ratio.
//Define pin connections & motor's steps per revolution
const int stepPinX = 2; // motor X step pin
const int dirPinX = 3; // motor X direction pin
const int enableX = 4; // motor X enable pin
const int stepPinY = 5; // motor Y step pin
const int dirPinY = 6; // motor Y direction pin
const int enableY = 7; // motor Y enable pin
const int buttonPin1 = 8; // pin connected to the buttonPin1 switch
const int homeSwitch = 9; // Pin connected to Home Switch to ground
const int buttonPin2 = 10; // pin connected to the buttonPin2 switch
const int stepsPerRevolution = 200; //number of steps per revolution in motorloop
int Layers; // a layer should be a change of direction
void setup() {
Serial.begin(115200);
pinMode(stepPinX, OUTPUT);
pinMode(dirPinX, OUTPUT);
pinMode(stepPinY, OUTPUT);
pinMode(dirPinY, OUTPUT);
pinMode(enableX, OUTPUT);
pinMode(enableY, OUTPUT);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(homeSwitch, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
Serial.println("Homing (press HOME limit button)");
home(); // move X toward home switch
}
void loop() {
if (!digitalRead(buttonPin1) || !digitalRead(buttonPin2)) {
delay(200); // debounce the limit switches
digitalWrite(dirPinX, !digitalRead(dirPinX)); // make direction opposite of previous direction
Serial.print("DIR:");
Serial.print(digitalRead(dirPinX));
Serial.print(" LAYER: ");
Serial.println(++Layers);
}
for (int i = 0; i < 3; i++) // counting...
StepMotorY(); // three Y steps
StepMotorX(); // one X xtep
}
void StepMotorX() {
digitalWrite(stepPinX, HIGH); //One step X motor
delay(2);
digitalWrite(stepPinX, LOW);
delay(2);
}
void StepMotorY() {
digitalWrite(stepPinY, HIGH); //One step Y motor
delay(2);
digitalWrite(stepPinY, LOW);
delay(2);
}
void home() {
// Start Homing procedure of X axis Stepper Motor at startup
digitalWrite(dirPinX, LOW); // (HIGH = anti-clockwise / LOW = clockwise) WHICH IS LEFT/RIGHT?
while (digitalRead(homeSwitch) == HIGH) // Do this until the switch is not activated
{
digitalWrite(stepPinX, HIGH);
delay(2); // Delay to slow down speed of Stepper
digitalWrite(stepPinX, LOW);
delay(2);
}
digitalWrite(dirPinX, HIGH);
Serial.println("press appropriate limit switch - B1 or B2");
}
B1
home
B2