Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Switch Wiring #96

Open
tklus opened this issue Jan 18, 2017 · 338 comments
Open

Limit Switch Wiring #96

tklus opened this issue Jan 18, 2017 · 338 comments

Comments

@tklus
Copy link

tklus commented Jan 18, 2017

Good Morning all,
Would it be possible for someone to add a page to the Wiki that explains the correct way to wire NC limit switches. maybe with a schematic drawn up. I have been confused about this for some time and there is limited info out there that I have seen that shows how to properly connect NC limit switches to GRBL. also it would be nice to know what resistors are required as well. and what GRBL settings need to change.

I had limit switches set up NO and had nothing but problems with false triggers. I would like to get limit switches working in the NC setup.

Thanks!
Tim

@chamnit
Copy link
Contributor

chamnit commented Jan 18, 2017

@tklus : I'd like to see this as well, but I'm not an electrical engineer and don't want to give bad advice.

@f0m3
Copy link

f0m3 commented Jan 18, 2017

Well. i just connected my switches between the pin 9 ,10,12 and ground. No resistor needed because off the internal pullup. Maybe the switch is false triggered because of motor wire induction. I soldered in some small capacitor to handle this.

@tklus
Copy link
Author

tklus commented Jan 18, 2017

and where did you install the small cap? schematic?

@f0m3
Copy link

f0m3 commented Jan 18, 2017

I think i did it somehow like this (i cannot go to my nc right now to check it ):

All you need to do for 100% perfect limit switch operation with Zero false triggers is: 3 small capacitors.
For each capacitor, connect the negative leg to the ground rail, and the positive to one of the limit sense pins on the controller. On an arduino running GRBL these are pins 9,10, &11/12 (depending on grbl version).
For Shapeokos I have found that a .47uf is perfect in all instances.

source: http://www.instructables.com/id/End-Stop-Limit-Switch-Problems/?ALLSTEPS#intro

@f0m3
Copy link

f0m3 commented Jan 18, 2017

BTW: some people add the capacitor close to the switch, which is useful to debounce the switch. I would prefer to have it close to the arduino to reduce noise AND to debounce. Whenever the switching wires are running close to the motor wires they will pick up some induction and this might be large enough to trigger the limit pin.

@tklus
Copy link
Author

tklus commented Jan 18, 2017

something like this?
limit switches

@luben111
Copy link

The best solution is to add opto couplers (like TLP185 http://uk.farnell.com/toshiba/tlp185-y-se/optocoupler-phototrans-3-75kv/dp/2524262):

  • the processor pin is not anymore connected galvanically to the end switches (no ESD noises can affect the processor)
  • the opto couplers suppress high frequency noises
    Here is the schematic of my Arduino Uno shield.
    arduino grbl v2 schematic_page_1
    arduino grbl v2 schematic_page_4
    arduino grbl v2 schematic_page_5

@langwadt
Copy link

capacitor close to the MCU pin, series resistor to the switch, it offers a bit of protection against ESD and makes a lowpass with capacitor. A pullup sized so that the switch current at least a few mA, the low impendance is less senstitive to interference and most switches need a minium current to be reliable

@gerritv
Copy link

gerritv commented Jan 18, 2017

You might want to read this about debouncing: http://www.labbookpages.co.uk/electronics/debounce.html
Also:

@tklus
Copy link
Author

tklus commented Jan 18, 2017

@luben111, that is a nice shield. are they available for sale?

@luben111
Copy link

luben111 commented Jan 19, 2017

@tklus, I could organize some small production of these modules. Let me know do you have interest, I'll calculate what I could achieve as price for assembled module and for a kit.

This is not the last version of the board. The new version has hardware ENABLE protection - after power up the Enable signal stays non active for 1.5s (independently from Arduino board) to avoid spontaneous motor movement. Sometimes after power up you can hear the machine with GRBL to make short noise like "grrr" which can burn your drivers (caused by the initial floating of the pins of the controller after power up) - after adding hardware to hold ENABLE in non active state for 1.5s things are OK.

@luben111
Copy link

BTW, some thoughts about capacitors in parallel to switches:

  1. Adding large capacitor in parallel to the switch contacts is a bad idea - in long term you'll experience malfunction of the switches. The reason is that when the switch is opened the capacitor charges to power supply (5V) and when the switch closes large currents pass through the contacts (peak current could exceed 10-20A for couple of uS). Usually the small switches are rated for lower currents and in combination with moisture the life of the switch may be strongly reduced. If adding capacitors in parallel to switches it should be 10-100nF ceramic, X7R grade.

  2. The electrolitic capacitor has large internal induction so all high frequency noises could not be suppressed by electrolitic capacitor. You can notice that in all power supplies parallel to electrolitic capacitors they put some ceramic ones for suppressing the high frequency noises. So adding electrolitic capacitor on digital inputs has no suppressing effect on high frequency noises.

  3. Microcontroller pins doesn't have Schmitt trigger inputs and by adding large capacitors the voltage level will move slowly. When the voltage is passing slowly through the 0-1 threshold the microcontroller current may increase significantly and some internal high frequency oscillations inside the silicon may occur. This could result in hanging the controller and will make the design more vulnerable to noises.

@parnz
Copy link

parnz commented Jan 19, 2017

@luben111 , maybe add a resister in series to limit the hi current when a cap is discharge?

@usbcnc
Copy link

usbcnc commented Jan 19, 2017

Old dot matrix has limit switch parallel with 103 small capacitor. Having large capacitor is not good to reduce noise.

@luben111
Copy link

luben111 commented Jan 19, 2017

@parnz - adding serial resistor will increase the life of the switch and reduce the noises but will make much worse the problem with slow moving voltage levels on digital pins without Schmitt trigger. When the voltage changes slowly while passing the 0-1 threshold the inpur works as good analog amplifier (will amplify all high frequency noises around) plus the current consumption of controller jumps.

Also not on last place you'll get delay in switches reaction, for high speeds it might be a problem.

I would not recommend adding resistors on large electrolytic capacitors.

@electrokean
Copy link

@luben111 actually the ATmega328 does have schmitt trigger on all digital inputs, but I agree that the capacitors should definitely not be electrolytic, but ideally ceramic with a value in the order of 100nF.
Anything significantly larger being required means you need to be implementing other noise reduction techniques, such as lower value pullup resistors, cable ferrites, shielded cables, star grounding, and even optoisolation.
BTW, your shield looks really nice :)

@luben111
Copy link

@electrokean - I'm not sure that Atmel I/O have Schmitt triggers (except for TWI CLK and DATA)
http://www.avrfreaks.net/forum/inputs-gpios-avr32-family-have-schmitt-trigger-feature

I used to work many years in Atmel developing their capacitive sensors and we relied on the absence of Schmitt trigger on the inputs to get the QTouch technology running.

In the data sheet you can see the gap between low and high input levels - this is not the Schmitt hysteresis but exactly the dangerous area where the input works as analog amplifier. You need to see explicitly Schmitt trigger features listed for the pin.

There in one more reason to believe there is no Schmitt trigger on inputs - Atmel silicons are very fast (20MHz) and Schmitt trigger design is not compatible with high speed architecture because of different delays on falling/rising edges

@electrokean
Copy link

@luben111 OK, but that link is related to AVR32 which is a different class of mcu.
I'll admit the Atmel data is a bit unclear, and I wasn't sure a while back, but take a look at the current version of the ATmega328P complete datasheet (as used by Arduino Uno for a typical grbl usage example)
http://www.atmel.com/Images/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf
See section 18.2 - Figure 18-2 shows a schmitt trigger buffer, and it is described in the text 18.2.5 regarding sleep mode. Same in Figure 18-5. There is a "bow tie" transmission gate shown before the schmitt trigger buffer, but that is effectively an analog switch.
Finally Figures 33-25 thru 33-27 show the I/O pin thresholds and hysteresis.
The datasheet specifically mentions the "Hysteresis of Schmitt Trigger Inputs" in Table 32-10 related to the TWI characteristics, but all the above still seems to indicate schmitt trigger inputs on all digital inputs to me.
If you can show something to the contrary I'd be happy to be corrected.

@luben111
Copy link

@electrokean I have to agree with you that Atmega328 has Schmitt triggers inside - Figure 33-27 is related to the Schmitt characteristics (the hysteresis).

@Lemonhawk
Copy link

Wasn't the original question about connecting up the limit switches using the NC pole in order to eliminate all the noise and adding caps and resistor? Also seems that you get a little more protection against broken wires. So where is the discussion about connection of limit switches using NC technique and what's the set up in GRBL.

@f0m3
Copy link

f0m3 commented Jan 20, 2017

chamnit created a caption in the wiki for limit switch wiring. Maybe some of the experts here could help to make a (or some options) description to make a good limit switch wiring?
https://github.com/gnea/grbl/wiki/Wiring-Limit-Switches

@tklus
Copy link
Author

tklus commented Jan 20, 2017

@Lemonhawk, thanks for getting this back on subject.

As I understand it, you wouldn't need capacitors and resistors in a normally closed system. And grbl has settings to run in a normally closed system.

I would like to know how this should be wired and what settings should be changed in grbl.

Thanks!
Tim

@tbfleming
Copy link

NO vs NC doesn't reduce noise, it just changes what the noise causes. With NO, noise sometimes makes the switch look like it's pushed with it's not. With NC, noise sometimes makes the switch look like it's not pushed with it is.

@vMeph
Copy link

vMeph commented Jan 20, 2017

i use to have alot false triggers, I dont know how you guys have wired but i have my NC switches with the internal pullup and a external pullup with 1k resistor conected to the arduino IOREF pin and a capacitor betwen the arduino swuitchitcitch pin and GND and never had false triggers again

@vMeph
Copy link

vMeph commented Jan 20, 2017

But like @tklus asked would be nice to have this type off information on wiki page with the correct schematics for NC switches.

@tklus
Copy link
Author

tklus commented Jan 20, 2017

@vMeph, is yours hooked up like the schematic I posted above? although I don't have the resistors drawn in.

@vMeph
Copy link

vMeph commented Jan 20, 2017

@tklus your schematic shows wired to NO Switch

i have set all machine with shielded cables and i have wired my switches has NC like this, and on grbl settings changed like $5=1, never add problems again with false triggers

nc switch

One off the reasons i changed to NC switches was cause the noise issues and also cause it seems to me that NC switches are a better choise, cause lets supose a switch goes bad if they wired in NC the machine will stop, if is with NO machine will not stop

i would agree with what @chamnit saied " but I'm not an electrical engineer and don't want to give bad advice"

Would be great to have someone that is a electrical engineer and undestands what would be the better choise for plug in NC switches and provide information with clear schematics on wiki page, cause it seems that there is alot debates on this subject and some says is like this and other says is like that, and becomes a litle unclear in what to do

@tklus
Copy link
Author

tklus commented Jan 20, 2017

@vMeph just for clarification and learning, see the attached markup of your pic
schematic markup

@Lemonhawk
Copy link

VMeph, I don't think you need the resistor or cap in your diagram. The limit switch ports are set to use the internal pullup and in normal operation the pin is held to ground, thus preventing noise triggering the limit actuation. If all we need is to set $5=1 then we're done. I think we're all looking for agreement on this. I would really be weary of putting a 47uf cap on one of the Arduino pins - I think one of the above diagrams showed 0.47 uf, but typical noise caps would be 0.01 or 0.001 to kill HF noise. With an NC I think the caps are worthless.

@tklus
Copy link
Author

tklus commented Jan 20, 2017

@Lemonhawk, that is what I was hoping for as well.

@RubenvdM
Copy link

RubenvdM commented Oct 3, 2020

Thanks @ukprinter,

But the board was designed by @luben111 and he did an awesome job. I just produce them and sell them. I have been selling the boards now since 2017 and have had no issues. I get regular orders from a guy that sells huge machines running with this board.

Only issue is that shipping from South Africa is quite expensive.

Welcome to visit the website to place an order, just let me know your shipping address and I will get a quote for you.

YRCNC.com

Ruben

@ukprinter
Copy link

ukprinter commented Oct 3, 2020 via email

@ukprinter
Copy link

Thanks @ukprinter,

But the board was designed by @luben111 and he did an awesome job. I just produce them and sell them. I have been selling the boards now since 2017 and have had no issues. I get regular orders from a guy that sells huge machines running with this board.

Only issue is that shipping from South Africa is quite expensive.

Welcome to visit the website to place an order, just let me know your shipping address and I will get a quote for you.

YRCNC.com

Ruben

I already have 3 brands of CNC shields mate but cant find out the connections as they documentation is very very limited.

It might well be something for the future but for now I am confused enough with what I already have lol.

The main issue I have is finding out how to connect NC limit switches using the protoneer 2.60 board with the raspberry Pi.

If I am forced to switch to Arduino completely I will bear you in mind.  what sort of documentation come with your boards??

@MechaSteve
Copy link

MechaSteve commented Oct 3, 2020

For each axis you will connect the NC limit switches to the limit switch terminal for that axis and the GND terminal
If you are just using the header on the 2.6 board, this will mean you will have three ground wires connected to the End Stop GND terminal and then on on each of X, Y, and Z:
End Stop X Terminal -> (NC Terminal) [X Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal
End Stop Y Terminal -> (NC Terminal) [Y Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal
End Stop Z Terminal -> (NC Terminal) [Z Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal

image

@ukprinter
Copy link

For each axis you will connect the NC limit switches to the limit switch terminal for that axis and the GND terminal
If you are just using the header on the 2.6 board, this will mean you will have three ground wires connected to the End Stop GND terminal and then on on each of X, Y, and Z:
End Stop X Terminal -> (NC Terminal) [X Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal
End Stop Y Terminal -> (NC Terminal) [Y Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal
End Stop Z Terminal -> (NC Terminal) [Z Axis Limit Switch] (COM Terminal) -> End Stop GND Terminal

image

Cheers mate. Thats the way I assumed it should work but I was not sure if it could work with NC switches as the wiki says its NO switches 👍

https://wiki.protoneer.co.nz/Raspberry_Pi_CNC#Wiring_Diagram

see the section on end stops. Its so frustrating that the basics are not even updated. :(

@MechaSteve
Copy link

MechaSteve commented Oct 3, 2020

You will need to invert the limit pins.

$5 - Limit pins invert, boolean
By default, the limit pins are held normally-high with the Arduino's internal pull-up resistor. When a limit pin is low, Grbl interprets this as triggered. For the opposite behavior, just invert the limit pins by typing $5=1. Disable with $5=0. You may need a power cycle to load the change.

NOTE: For more advanced usage, the internal pull-up resistor on the limit pins may be disabled in config.h.

Because the NC switch connects the input to GND when not triggered, it will be normally low.

@jcalcote
Copy link

jcalcote commented Dec 10, 2020

Hi - I've implemented the limit switch opto-isolation circuit shown here: https://github.com/gnea/grbl/wiki/Wiring-Limit-Switches. My switches are held normally closed. I've added an LED "activation" indicator to the circuit. I've tested this circuit on a breadboard and it works - when the "switch" is opened (by pulling a wire out of the ground bus on the breadboard), the led lights. I'm wondering if any of you electronics geniuses out there have any advice for me on potential issues with this design before I commit it to a pcb:

image

Note that the 1K pull up is acting as the current limiter on the LED, so it's not quite a bright as it would be with a 220-470 ohm resistor, but hey - beggers can't be choosers. :)

One potential problem I noticed was that without the LED, the voltage drop between the output pin and ground is what you'd expect - 5 volts. But with the LED in place, the voltage drop becomes something closer to 2V - that is the LED is sucking the other three. Now, normally, the output pin is feeding voltage into the circuit as well if it's being held high as the grbl docs state, which makes me wonder if, when this is hooked up to an arduino, we'll be drawing current through both the 1K and the internal pull-up. It's more complicated than I originally thought. Gonna have to consider this more...

@gojimmypi
Copy link

@jcalcote what's the design goal? fwiw - I think you may be using an opto-isolator as a switch, but not really isolated.

image

I think a genuine isolation circuit would use separate power supplies and not share the resistors.

Also as a reminder, this won't be a debouncer.

@jcalcote
Copy link

@gojimmypi you are correct of course. There's no true electrical isolation here and that was never the point, as the rest of this thread states in many comments. The point is, however to effectively debounce the switch in hardware. The combination of the optical connection, which has been shown to be slow enough to lose the noise, and a normally closed end stop solution is supposed to accomplish that.

The point of my post was to get advice on how to add an LED indicator to the circuit, but I've since realized the only good way to accomplish this without a fair amount of extra hardware is to use the NO contact on the switch as several other designs do. Sadly, this requires me to run another wire to the switches which I really don't want to do, so I've given up on the idea for now.

@lalo-uy
Copy link

lalo-uy commented Dec 11, 2020 via email

@lucky62
Copy link

lucky62 commented Dec 11, 2020

Also the LED current may be insufficient.
But in principle the circuit can work, if the LED voltage will be higher than the low limit for "logical 1" and the current 2-3 mA will be enough for acceptable LED brightness.

@langwadt
Copy link

modern LEDs are usually quite bright at 3mA and the Vf of a blue LED is well above the Vih threshold (typical 2.6V @ 5V)

@gojimmypi
Copy link

@jcalcote sorry, I didn't mean to be discouraging.

I agree it would be best to use a normally closed switch, and to not run any additional wires to the switch.

Debounce: depending on the specific software, this may be irrelevant. I learned on my tiny 3080 desktop that once the switch is triggered, the software is locked until reset. That makes sense, as once an undesired limit is breached, the only course is manual adjustment, and then the software has lost track of where the cutting tool is located. I'm not very well versed in CNC machines in general; I don't know how the full size ones act.

If you really wanted just a clean on/off, perhaps a latching flip-flop that is cleared with the same reset button that resets the software?

Isolation: I do however - think it would be best to actually have the opto-isolator actually doing isolation. Maybe this could be effectively accomplished with another wall-wart power supply?

Interesting that you wanted the opto-isolator to work slowly. This stackexchange thread mentions a PS2506 with a whopping 100us rise and fall time! (although I wonder if the output continues to move in the original direction if the input is still changing)

Indicator LED: In any case, the LEDs in your circuit could be driven by transistors. The ULN2064B is one possible option: quad darlingtons in a single through-hole 16 pin package. This would separate and serve to supply more consistent current to each illuminated LED. (although as @langwadt noted, modern LEDs can be crazy bright with just a little current).

@ecncshopInd
Copy link

ecncshopInd commented Aug 31, 2021

In GRBL mega : M7 is turning on pin D9 and M8 is turning on pin D8.
But M9 is turning off both pins.
Is there any command to switch off only D9 ?
Is there any command to switch off only D8 ?

@JayPerez1
Copy link

JayPerez1 commented Aug 31, 2021 via email

@ecncshopInd
Copy link

@JayPerez1
We are planning to use as general io , not for coolant purpose, so need independent on off control.
Or is there any other way I can get some more output pins in mega grbl which I can control by m codes ?

@terjeio
Copy link

terjeio commented Sep 1, 2021

Or is there any other way I can get some more output pins in mega grbl which I can control by m codes ?

You can implement M62-M65. Perhaps there is a Mega port available that supports those M-codes? There are 32-bit ports that does.

FYI coolant prins can be controlled individually with real-time commands (toggle only).

@MechaSteve
Copy link

MechaSteve commented Sep 8, 2021

@JayPerez1
We are planning to use as general io , not for coolant purpose, so need independent on off control.
Or is there any other way I can get some more output pins in mega grbl which I can control by m codes ?

So, a kinda gross solution is to switch both off and immediately switch on the one you want to keep on.
If you are controlling something real like a relay or an indicator it should be fine.
Theoretically there should be zero time between the Off and On command, but there will be a tiny amount.
If it is controlling something that will see a very short off pulse, it could cause a problem.

M7 (Flood on)
M8 (Mist On)
(doing some stuff)
M9 (both off)
M7 (Flood Back on, Mist Off)
(keep doing stuff)

@Kamoba
Copy link

Kamoba commented Sep 17, 2021

Hello guys, this place may be the better place to ask help. Any idea on my issue?

@iscorporacion
Copy link

Hello I must say that I am not an expert in electronics, apologies in advance for my lack of knowledge.

I have made a DIY CNC and I am using an Arduino uno with cnc shield, I started perfectly when I already had the kinematics ready, I connected everything and managed to make it work, when I began to arrange my cables to do this in an orderly manner I realized that my limit switches are blocked and do not allow movement, investigating I came to the conclusion that apparently noise is filtering since I put all the cables together to remove them so that they looked organized, I bought the module

Module 817

i tried to connect it directly, but obviously this didn't work, could someone help me with a connection diagram, i think i must power it somehow, but i'm not an expert in electronics

@MechaSteve
Copy link

MechaSteve commented Jul 20, 2023 via email

@iscorporacion
Copy link

very happy, i got it using this reference, basically i circulated 5V taken from the CNC Shield in the limit switches and it works, now my ends are stable

schematic

@dougmake
Copy link

Good day all, please help with a couple of questions. Can I use the setup as shown in this pic with a V3.00 shield and grbl 1.1h? Would the blue, orange and pink wires connect to the X+, Y+ and Z+ terminals leaving all the other connections as shown? Could the frame of the machine be used for a ground or should all the switches be wired back to the shield black strip.
Thanks, Doug
(https://github.com/gnea/grbl/assets/123429986/e029d577-8d85-4bb6-ad98-e99bcd0553cb)

@MechaSteve
Copy link

Generally, it is best to have a dedicated ground wire for each signal path. So the best is to have each switch pair have a ground wire back to the control board, with the capacitor and resistor near the control board.

Grounding the machine frame, as well, is good; but generally should not be used as the primary signal path.

@dougmake
Copy link

dougmake commented Sep 25, 2023 via email

@MechaSteve
Copy link

Yes, the other wire from the switches would go to the x/y/z terminals on the shield.

@lalo-uy
Copy link

lalo-uy commented Sep 25, 2023 via email

@dougmake
Copy link

dougmake commented Sep 25, 2023 via email

@dougmake
Copy link

dougmake commented Sep 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests