Ask GRBL for the limit switch status

How do I get the GRBL log to give me the status of the limit switches?

Send a question mark to the controller.
You’ll see a Pn: followed by the pressed switch. If no Pn: is in the status report, no switches are read as pressed.

2 Likes

I don’t see anything like that.

Here’s output from the the /? command, then a homing cycle, followed by output when I have deliberately sent the machine to the point where the limit switch is engaged. Am I missing something? Maybe there’s a setting I need to change to get that info? I found something about that online, but it didn’t work.

**OUTPUT FROM /? ***

gc_not_motion
___________? ___________
<Idle,MPos:-4.925,-5.002,-5.000,WPos:-4.925,-5.002,-5.000,Buf:0,RX:1,Ln:0,F:0.>
ok
gc_dwell
___________N0 G4P0.05 ___________
gc_get_offsets
___________$# ___________
[G54:0.000,0.000,0.000]
[G55:0.000,0.000,0.000]
[G56:0.000,0.000,0.000]
[G57:0.000,0.000,0.000]
[G58:0.000,0.000,0.000]
[G59:0.000,0.000,0.000]
[G28:0.000,0.000,0.000]
[G30:0.000,0.000,0.000]
[G92:0.000,0.000,0.000]
[TLO:0.000]
[PRB:0.000,0.000,0.000:0]
ok
gc_parser_state
___________$G ___________
[G1 G54 G17 G21 G90 G94 M0 M5 M9 T0 F100. S0.]
ok
<Idle,MPos:-4.925,-5.002,-5.000,WPos:-4.925,-5.002,-5.000,Buf:0,RX:0,Ln:0,F:0.>

OUTPUT FROM HOMING CYCLE (limit switch not engaged)*

SET MACHINE STATE: HOMING
gc_homing
___________$h ___________
<Queue,MPos:0.000,0.000,0.000,WPos:0.000,0.000,0.000,Buf:1,RX:0,Ln:-1,F:0.>
<Run,MPos:0.000,0.000,-0.150,WPos:0.000,0.000,-0.150,Buf:1,RX:0,Ln:-1,F:1000.>
<Run,MPos:0.000,0.000,-3.550,WPos:0.000,0.000,-3.550,Buf:1,RX:0,Ln:-1,F:1000.>
<Queue,MPos:0.000,0.000,-5.000,WPos:0.000,0.000,-5.000,Buf:1,RX:0,Ln:-1,F:0.>
<Run,MPos:-0.711,-0.704,-5.000,WPos:-0.711,-0.704,-5.000,Buf:1,RX:0,Ln:-1,F:1000.>
<Run,MPos:-3.100,-3.117,-5.000,WPos:-3.100,-3.117,-5.000,Buf:1,RX:0,Ln:-1,F:1000.>
ok
SET MACHINE STATE: JOGGING
<Idle,MPos:-5.005,-5.002,-5.000,WPos:-5.005,-5.002,-5.000,Buf:0,RX:0,Ln:0,F:0.>

OUTPUT SENDING SPINDLE TO X0 (set to where the limit switch is engaged)

gc_motion
___________N0G1X0.991F500.0 ___________
ok
gc_dwell
___________N0 G4P0.5 ___________
<Run,MPos:-3.582,-5.002,-5.000,WPos:-3.582,-5.002,-5.000,Buf:1,RX:0,Ln:0,F:500.>
<Run,MPos:-1.829,-5.002,-5.000,WPos:-1.829,-5.002,-5.000,Buf:1,RX:0,Ln:0,F:500.>
<Run,MPos:-0.127,-5.002,-5.000,WPos:-0.127,-5.002,-5.000,Buf:1,RX:0,Ln:0,F:500.>
<Idle,MPos:0.991,-5.002,-5.000,WPos:0.991,-5.002,-5.000,Buf:0,RX:0,Ln:0,F:0.>
ok
gc_get_offsets
___________$# ___________
[G54:0.000,0.000,0.000]
[G55:0.000,0.000,0.000]
[G56:0.000,0.000,0.000]
[G57:0.000,0.000,0.000]
[G58:0.000,0.000,0.000]
[G59:0.000,0.000,0.000]
[G28:0.000,0.000,0.000]
[G30:0.000,0.000,0.000]
[G92:0.000,0.000,0.000]
[TLO:0.000]
[PRB:0.000,0.000,0.000:0]
ok
gc_parser_state
___________$G ___________
[G1 G54 G17 G21 G90 G94 M0 M5 M9 T0 F500. S0.]
ok
<Idle,MPos:0.991,-5.002,-5.000,WPos:0.991,-5.002,-5.000,Buf:0,RX:0,Ln:0,F:0.>

Are you sure the switch is pressed? Just hold the switch down and send a ?

1 Like

I am sure the switch is pressed.

Hold it down and send ?.
Don’t mess with all the jogging and homing. The status reports in those cases may not show the Pn: as it may happen just before or after the switch is pressed.
If homing is working, your switches are working. What are you looking for?

1 Like

Seriously…it is pressed. I visually see it. It is pressed. Furthermore, if I try to home from there, it says the limit switch is hit. I am looking for it to tell me the status of the switches without my having to try to home.

I believe you. In my experience, if I send ? while the switch is pressed it will report that the switch is pressed. This is how grbl is supposed to work.
Are you sending the ?
What version of grbl are you using?

I did That. GRBL 0.9

Aah… I should’ve asked that question first.
What are your grbl settings?
Send $$

Anyway, change $10 from whatever it is to something greater than 15.
Send your ? again.
Version 0.9 uses a Lim:ZYX
In place of the ZYX will be 0 for not pressed, and 1 for pressed.
Only X switch pressed would give you:
Lim:001

I tried changing that value before I posted this question. I had found this thread online (it appears under an XCarve topic, but I thought it was worth a try):

[Guide] Using Grbl to debug your homing switches - Troubleshooting - Inventables Community Forum

This suggested $10=19. That didn’t give me anything that I could interpret as switch status. This is what I was referring to when I said:

> "Maybe there’s a setting I need to change to get that info? I found something about that online, but it didn’t work."

Unfortunately, it still doesn’t work. When I change from $10=255 (the apparent default) to $10=19, there is only one significant difference in the output:

With $10= 19, I get this line:

<Idle,MPos:-5.000,-5.000,-5.000,WPos:-5.000,-5.000,-5.000,Ln:0,F:0.>

With $10=255, I get this line:

<Idle,MPos:-5.000,-5.000,-5.000,WPos:-5.000,-5.000,-5.000,Buf:0,RX:0,Ln:0,F:0.>

I don’t know what Buf and RX are, but their reported values don’t change when the x limit switch is pressed, so that does not seem to be the value I’m looking for. I will try others when I have a few minutes.

The trial and error method is not ideal, but I can live with it if I get what I need. Better would be to have a reference that explains GRBL settings in CM. Perhaps there is one?

OK, Your status reports are not standard for grbl 0.9. Did you compile it yourself or use a source from C3D. My best guess at this point is that the grbl configuration enabled a compile time option to report the the Line numbers and the realtime feed rate.

Maybe those options cause a memory issue and limit pins aren’t reported. Nope

A few things:
Which 0.9 version do you have?
Can I ask why you need the switch pin status?
Can you just upgrade to grbl 1.1?
If you want to stay at 0.9, can you flash a version that works for what you want?
Are you comfortable editing the grbl config source to match what you want?

@TheWoodNymph

You’re on an old version of 0.9 (probably 0.9g). Still a customized config version.
Get a newer version if you want the limit switch status to show up in the report.

The wiki on grbl’s github site is pretty thorough. The problem is that the documentation updates with version improvements. You’re running a version that’s 4 or 5 years old.

Thank you for your help on this.

I’m using grbl 0.9g. I haven’t updated or customized anything so I’m using the software that was available when I got my SO3 a couple of years ago.

I was thinking about upgrading to CM4 and GRBL 1.1, but I’m leaning heavily toward not. It seems CM4 has the table values hard-coded, and I would end up losing some usable area. GRBL 1.1 is not compatible with CM3, so no.

I currently have the table X set such that I can use the entire width of the machine. I used a feeler gauge to get about 0.1 mm from the left hard stop, and I used the limit switch on the right. Getting the switch status via GRBL would make it much easier. I resorted to using MDI to sneak up on the value; I had to send $h to know if the switch was engaged. It was tedious. I still need to do this with the table Y.

I know that kind of precision is overkill, and probably not actually accurate, but I’m a total nerd (and a little bit OCD).

If there’s a version that would give me the switch status, I absolutely would go with it. Do you have any suggestions? Can you point me in the right direction?

I see this whole thing as an opportunity to learn something. Somebody made a comment somewhere on this site that expresses my personal philosophy perfectly: “If I’m not learning something new, I’m wasting oxygen.”

I’ll try anything once, but I would have no idea where to start.

I’d suggest at least going to .9f, or just changing senders to something like UGS and grbl 1.1. I have no idea where to get .9f, but maybe a quick email to support@carbide3d.com would turn it up.

I’d suggest going with the latest release of 0.9, which is 0.9j.
Here’s a link to the hey files for previous versions … Scroll to the last one.

How are you planning to flash the controller?

I’m not sure if CM needs the line number and other non-default report options, but they will not be enabled in the downloaded hex.
I can point you in the right direction if you (CM) need those features.

Edit: Oops… Link

1 Like

Sorry for the long delay. I had a veterinary emergency that took up most of the last week. I think I am going to put off upgrading for now. The reason I wanted switch status was to save time and hassle for one relatively short task. It is clear to me now that I won’t save any time going down this road.

Thanks for your help neilferreri and mikep. I learned some things.

@TheWoodNymph I’m sorry about the vet emergency.
I’m still not sure I understand why you are jogging to the limit switches. How does that help use the entire machine. Your limit switches represent machine zero. They will always be machine zero.