I am using the V3 stepper CNC shield on an arduino mega. Here. I have atteched limit switches as shown in the picture below and they work correctly when the arduino is turned on, but when the shields power supply is on the switches always read as turned on.
The code is ridiculously long and I cant share it all but EVERY relevant piece is here.
//...
//Limit Switch Pins and values
//The positive and negative limits have the same pin definition
const int limZ=11;///"Z"
const int limC=10;//"y"
const int limX=9;//"x"
//...
void setup(void) {
//Limit Switch Pins
pinMode(limX, INPUT_PULLUP);
pinMode(limZ, INPUT_PULLUP);
pinMode(limC, INPUT_PULLUP);
//...
}
void loop(void) {
nexLoop(nex_listen_list); //This is the arduino listening for a button to be pressed
if(digitalRead(limX)==LOW){//used for debugging putpose to test lim switch connection. Will alway go off if motor power supply is on so only test with arduino power supply
Serial.println("Found limX");
}
if(digitalRead(limZ)==LOW){
Serial.println("Found limZ");
}
if(digitalRead(limC)==LOW){
Serial.println("Found limC");
}
}
//...
In case it is needed my limit switches used are HERE
Thank you for the links. I am not using GRBL at the moment for the purposes of this project.
Once i eventually track down some capacitors I will be attempting this filtering but in connection to the CNC shield.
You can still INVERT the triggering aspect in your own code too.
HIGH and LOW are just swapped over.
However if you still have issues then chances are you have noise on the switch part of the circuit which needs to be filtered out.
I often scrounge components from old electronics and old TV's, Hi-Fi's, Radios etc. are fantastic for that aspect.
wjgirard:
they work correctly when the arduino is turned on, but when the shields power supply is on the switches always read as turned on.
That does not sound like a filtering problem to me. It seems more like existence of pullup resistors. Some testing with a multimeter should establish that.
However the piece I have quoted is not very clear. When you say "Arduino is turned on" do mean the Arduino only and without the shield power supply connected. And when you say "shields power supply is on" do you mean BOTH the shield and the Arduino or only the shield?
Ill retype that to try to say it better.
When the arduino power supply is on and the shield's power supply is off the limit switches work as expected, meaning they activate the serial printing shown in the code when pressed. When the Arduino's power and the shield's power are both on the switch reads as constantly activated whether it is pressed down or not.
I have attempted switching from high to low to make sure I'm not doing anything dumb, but it has produced the same result. I'm going to switch the high/low assignment and whether its push or pullup, just incase I lost track of something last time I tested this.
For now I am going to do the testing just mentioned, and make the filtering once I get the resistors and capacitors.
wjgirard:
Ill retype that to try to say it better.
Thanks that's now clear.
See if you can find a link to the schematic for the CNC shield, and if you do please post the link. It will be much more productive to study the schematic BEFORE you start adding components.
Make sure you have nothing connected to the TX and RX on the shield itself.
This is to ensure you are not seeing false triggering with some loopback effect.
I cannot replicate the issue here on my boards btw but I don't use the TX,RX pins for anything.
Also remove the shield and place a piece of insulation take across the top of the USB connector to ensure you are not grounding out as some shields have shorter pins than others and that too can be an issue.