Hi,
I'm beginning with Arduino but I've built a sort of CNC using the typical 3 axis (X,Y,Z).
I've uploaded grbllite into an arduino Uno and i'm controlling it with a Raspberry Pi (Rasbian)
Every axis is moving well, and when I press an endstop the axis stops. Good.
My problem is when homing :
When i send G28 X0 for example, the X axis hits the endstop, but then it stays in position and trigger it forever. I can't send another command.
What i need is when X hits the endstop, it goes back a little and stops. Then i would add G92 and have my 0.
I've searched the web for hours trying to copy paste every line including the endstop but i didn't find any explanation.
Endstops are mecanical, connected to the cnc shield on the X- Y- and Z- position.
Here is the code relative to the endstop:
const int X_END_STOP = 8;
const int Y_END_STOP = 9;
const int Z_END_STOP = 10;
int pin_ENDSTOP[3] = {9, 10, 11}; // les broches de endstop des moteurs X,Y,Z
const int APPUI = LOW; // s
pinMode(pin_ENDSTOP[X], INPUT_PULLUP); // met broche en entr�e avec rappel au + actif
pinMode(pin_ENDSTOP[Y], INPUT_PULLUP); // met broche en entr�e avec rappel au + actif
pinMode(pin_ENDSTOP[Z], INPUT_PULLUP); // met broche en entr�e avec rappel au + actif
digitalWrite(pin_ENDSTOP[X], HIGH); // met broche avec rappel au + actif
digitalWrite(pin_ENDSTOP[Y], HIGH); // met broche avec rappel au + actif
digitalWrite(pin_ENDSTOP[Z], HIGH); // met broche avec rappel au + actif
// lecture des endstops
if (digitalRead(pin_ENDSTOP[X]) == APPUI) {
Serial.println("Appui ENDSTOP X");
delay(100); // anti-rebond
} // fin si appui
if (digitalRead(pin_ENDSTOP[Y]) == APPUI) {
Serial.println("Appui ENDSTOP Y");
delay(100); // anti-rebond
} // fin si appui
if (digitalRead(pin_ENDSTOP[Z]) == APPUI) {
Serial.println("Appui ENDSTOP Z");
delay(100); // anti-rebond
} // fin si appui
// lecture des endstops
if (digitalRead(pin_ENDSTOP[X]) == APPUI) {
Serial.println("Appui ENDSTOP X");
delay(100); // anti-rebond
} // fin si appui
if (digitalRead(pin_ENDSTOP[Y]) == APPUI) {
Serial.println("Appui ENDSTOP Y");
delay(100); // anti-rebond
} // fin si appui
if (digitalRead(pin_ENDSTOP[Z]) == APPUI) {
Serial.println("Appui ENDSTOP Z");
delay(100); // anti-rebond
} // fin si appui
//---- G28 ---
void G28() {
Serial.println(F("G28"));
feedrate(frmax);// on utilise le feedrate rapide
int test = 0.0; // variable pour test
// -- axe X
test = parsenumber('X', -1); // nouvelle position X - on passe -1 en parametre - sera idem si pas present - note X seul idem X0
output("X :", test);
if (test != -1) { // si X : on va chercher le endstop X
searchEndstop(X); // fonction de recherche endstop
px = 0.0; // RAZ position X
} // fin if
// -- axe Y
test = parsenumber('Y', -1); // nouvelle position Y - on passe -1 en parametre - sera idem si pas present - note Y seul idem Y0
output("Y :", test);
if (test != -1) { // si Y : on va chercher le endstop Y
searchEndstop(Y); // fonction de recherche endstop
py = 0.0; // RAZ position Y
} // fin if
// -- axe Z
test = parsenumber('Z', -1); // nouvelle position Z - on passe -1 en parametre - sera idem si pas present - note Z seul idem Z0
output("Z :", test);
if (test != -1) { // si X : on va chercher le endstop X
searchEndstop(Z); // fonction de recherche endstop
pz = 0.0; // RAZ position X
} // fin if
} // fin G28
//--- fonction de recherche d'un endstop
void searchEndstop(int axisIn) {
int search = true;
while (search) {
onestep(axisIn, -1); // 1 pas en arriere
tick(); // delay de feedrate
if (digitalRead(pin_ENDSTOP[axisIn]) == APPUI) { // on teste le endstop
Serial.println("Appui ENDSTOP"); // debug
delay(100); // anti-rebond
search = false; // pour sortir du while
} // fin si appui
} // fin while
last_Dir[axisIn] = -1; // MAJ lastDir[axisIn]
} // fin searchEndstop
// d�tection des endstop de s�curit� - revoir pour d�tection tous les npas...
if (digitalRead(pin_ENDSTOP[x]) == APPUI) { // on teste le endstop x - si appui, on sort de la fonction line de mouvement
Serial.println("Appui endstop X : arret des mouvements");
return; // on sort de la fonction line
} // fin if endstop x
if (digitalRead(pin_ENDSTOP[y]) == APPUI) { // on teste le endstop y - si appui, on sort de la fonction line de mouvement
Serial.println("Appui endstop Y : arret des mouvements");
return; // on sort de la fonction line
} // fin if endstop y
} // fin for
} // fin if
Thanks for reading me and giving any advice.