There has been discussion recently about noisy limit switches. GRemote did have a primitive form of debounce in the arduino code, but mDraw does not. Here is how to add debounce to the digitalReads.
Take a backup copy of xybot.ino.
open xybot.ino in the Arduino IDE
Add the following function between the line “#define SPEED_STEP 1” and the line “void doMove()”
int debouncePin(int pin)
{
int val1 = -1;
int val2 = 1;
int trys = 3;
while( val1 != val2 && trys)
{
val1=digitalRead(pin);
delayMicroseconds(5);
val2=digitalRead(pin);
--trys;
}
if( trys) return val1; // got the same reading
else return 0; // couldn't get the same reading in two goes, assume switch activated
}
Then wherever the code reads a limit switch, substitute debouncePin( for digitalRead(
for example, in the function echoEndStop, the revised lines will become
Serial.print(debouncePin(xlimit_pin1)); Serial.print(" ");
Serial.print(debouncePin(xlimit_pin2)); Serial.print(" ");
Serial.print(debouncePin(ylimit_pin1)); Serial.print(" ");
Serial.println(debouncePin(ylimit_pin2));
In the goHome() function similar substitutions need making.
After uploading the revised code to the plotter, start mDraw, once you have selected XY and connected to the port and seen the successful message, use the gear icon to get the Settings screen up, and press each limit switch in turn, making sure that the value shown for it changes from a 1 to a 0.
I chose 5 microseconds as an arbitrary value, prepared to increase it if I wasn’t getting reliable behaviour, but it does seem to be long enough.
ETA I set trys to three and returned 0 if it decremented to 0 on the basis that if there is that much noise that two successive tries fail to get a valid reading, you are best pretending a limit switch has activated and stopping anyway, otherwise the moving parts might start colliding with the static parts.