Hi,
Arduino-Code for possible arduino nano external auto-squaring:
boolean x1min = 0;
boolean x2min = 0;
boolean y1min = 0;
boolean y2min = 0;
boolean x1mot = 0;
boolean x2mot = 0;
boolean y1mot = 0;
boolean y2mot = 0;
boolean xendstop = 0;
boolean yendstop = 0;
void setup() {
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, LOW);
// delay(500);
x1min = digitalRead(2);
x2min = digitalRead(3);
if (x1min == HIGH && x2min == LOW) {
x1mot = HIGH;
x2mot = LOW;
xendstop = LOW;
}
else if (x1min == LOW && x2min == HIGH) {
x1mot = LOW;
x2mot = HIGH;
xendstop = LOW;
}
else if (x1min == LOW && x2min == LOW) {
x1mot = LOW;
x2mot = LOW;
xendstop = LOW;
}
else {
x1mot = HIGH;
x2mot = HIGH;
xendstop = HIGH;
}
digitalWrite(5, x1mot);
digitalWrite(6, x2mot);
digitalWrite(7, xendstop);
digitalWrite(13, HIGH);
// delay(500);
y1min = digitalRead(8);
y2min = digitalRead(9);
if (y1min == HIGH && y2min == LOW) {
y1mot = HIGH;
y2mot = LOW;
yendstop = LOW;
}
else if (y1min == LOW && y2min == HIGH) {
y1mot = LOW;
y2mot = HIGH;
yendstop = LOW;
}
else if (y1min == LOW && y2min == LOW) {
y1mot = LOW;
y2mot = LOW;
yendstop = LOW;
}
else {
y1mot = HIGH;
y2mot = HIGH;
yendstop = HIGH;
}
digitalWrite(10, y1mot);
digitalWrite(11, y2mot);
digitalWrite(12, yendstop);
}
Pin 13 is only set and reset to get an idea, of how fast the loop run through. With all those digitalRead and digitalWrite operations I’ve got a square signal of around 16kHz (60µs). That is sufficient fast for this kind of endstop scheme, I think. It could be fasted up, if interupts are used for one axis (Nano has two interupt inputs, e.g. X1 and X2) or with direct port manipulation. Only I’m a not nearly good enough programmer to get this code written.
I use an arduino mega with estlcam and wiring 5 DRV8825 directly to it. I’m planing to use the signals x1mot, x2mot, … and wire them to the enable pins of the DRV8825s.
Do you know “fritzing”? I have the wiring sketched up in this software.
@Dario,
mit dem CNC Shield und drei Treibern würde es trotzdem nicht wirklich funktionieren, weil man mit dem Arduino Nano eigentlich nur die Treiber “disablen” kann. Dazu bräuchte man aber 5 Treiber. Wenn man eine Art allpolig schaltendes Relais direkt in die Leitung vom Treiber zum Stepper setzt, wäre der Stepper, der den Endstop zuerst erreicht sofort komplett stromlos und würde evtl. unkontrolliert rumgeschoben werden, weil das Haltemoment fehlt. Alles keine wirkich gute Lösung.
Best regards,
brettbrn