G38.X support in Marlin

I’ve been playing around with making an aluminum Turners Cube on the MPCNC and found myself wanting a way to easily set the origin of the machine to the corner of the work. For this project I’m mounting the workpiece in a 3 inch vise. I replaced the metal vise jaws with 3d printed ones to avoid marring the aluminum. After squaring the stock, the Turners Cube requires making the same cut on all 6 sides of the cube. I realize that I could have mounted a stop on the vise to get repeatable clamping but what fun would that have been?

I started by trying to modify Ryan’s firmware by enabling G38_PROBE_TARGET, FIX_MOUNTED_PROBE, and Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PINwith no luck. I also saw elsewhere on the forums that some G38.Xwas broken for the firmware versions that most of us use. I ended up merging the latest bugfix-2.0 branch of Marlin into Ryan’s firmware and still had no luck. A couple of hours of debugging C++ macro hell later on my updated firmware (seriously, how anyone keeps up with the amount of preprocessing in marlin amazes me) I found that manually configuring Z_MIN_PROBE_PINfixed my issues. Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN seems buggy and doesn’t set the appropriate pin to be monitored by G38. Last of the nuts and bolts that I’ll mention is that for anyone wanting to dive any deeper into Arduino than modifying config values should consider setting up a proper IDE and tooling to make life easier. I took a step away from my usual linux dev tools and followed this guide to get going.

Enough blabbing. Here’s a clip: https://i.imgur.com/n90gSV8.mp4

It’d be cool to see this supported out of the box for MPCNC users. Is there anything keeping to to the version of marlin that Ryan ships his boards with?


I had played with Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN - had no luck. So you propose just assign same z min pin as probe pin and g38 begin to work?

Does side probing workable too (g38 x or g38 y)?

With newer builds of marlin, yes. The latest builds support manually setting the Z probe pin. Be sure to read through the docs before tweaking that setting.

Yeah, the imgur video in the first post shows using G38.2 for X, Y, and Z.

1 Like

Probably i was impatient and didn’t watch the video to x/y part, saw only z.

Ok, great. Then it looks like x/y probing also possible to be used in fusion 360 pp.

By the way, i had fixed marlin to support g54-g59. You may find in in my github.

Thank you for your post. It helped me some in configuring my own Probe sensor.
To help others with specifics, here is what I did.

  1. Download Marlin 2.0 from V1’s git listing with respect to your board.
  2. Down load the correct version of Aurdino need to compile it.
  3. Compile the software - as is - and get it flashed to the board.
  4. connect up motor to each XYZ and verify movement commands work.
  5. Check endstop status using the M119 command.
    If you have compiled this as is, it should only show 3 status
    X_min, Y_min and Z_min as open.
  6. Connect up what ever you are going to use (eg 2 wires) to the Z min end stop pins (Signal and Neg pins, do not connect the positive pin).
  7. Short them out. and repeat M119
    The Z_min should now show as triggered.
  8. connect the board back to your PC and the Arduino software.
  9. Open the configuration.h file.
    Disable/comment out the line #define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
  10. fine your board and open the file for your boards pins.h file. (for example for RAMPS 1.4 this is “pins_RAMPS.h” and locate the line where #define Z_MIN_PIN and copy that number.
  11. Back on configuration.h edit/enable the line #define Z_MIN_PROBE_PIN insert number from PIN.h
  12. find and enable the setting FIX_MOUNTED_PROBE
  13. Save configuration.h
  14. edit configuration_adv.h. Find and enable #define G38_PROBE_TARGET
    15 . Save
  15. compile and upload to the board.
  16. connect to the board and issue M119 command and you should now see
    Recv: Reporting endstop status
    Recv: x_min: open
    Recv: y_min: open
    Recv: z_probe: open
  17. Using your Z_MIN cables short them out and test M119 again and Z_Probe should trigger.
  18. (un-short the probe)
  19. Using a motor connected to the Z axis, make sure it moves (normal move commands)
  20. Enter the command G38.2 Z20 and after hitting return quickly short out your Z Probe cables and the motor should stop.
  21. Check all the other motors also work with the probe direction.

Been pondering doing this for a while, now I have to👍

Thanks for the write up

Just a quick question on the above,

A) Im using the archim board and #define Z_MIN_PROBE_PIN doesn’t appear in my firmware in the config.h file

B)Why do you comment out #define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN and then hard code it back again in point 11?

Ive re read the thread and found out my answer to the above :slight_smile:

More questions though

Im running 2.0 already

I have followed your instructions now and commented out


and tried to add in

#define Z_MIN_PROBE_PIN 32

Only when I come to compile I get an error stating

error “You must enable either Z_MIN_PROBE_ENDSTOP or Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN to use a probe.”

any ideas would be most useful :slight_smile:

A) Don’t know. I did this on the RAMPS board with Marlin 2.0.

However I browsed to the Archim Series 1 source (link provided in the V1 firmware page), and drilled down to Marlin > Src > pins > pins_ARCHIM1.h and the first page on this shows that it is
#define Z_MIN_PIN 31 // PA7 MIIN ES3

B) I don’t know. I documented what I did to get it working, I didn’t spend anytime under the hood about why I had to do it. Note: If I enabled B the probe stopped working on Z MIN

lastly - Dont know. Again. I did mine on the RAMPS 1.4 download. I don’t have your board to test/experiment with.

Sorry I can’t be or more help.

I searched the code for that error and I didnt find it. Can you quote exactly the error message you got?

And also which version exactly are you running?

This is the original firmware I used, this works as it is no edits for the G38

Marlin 2.0

This is my Edit that errors

#error “You must enable either Z_MIN_PROBE_ENDSTOP or Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN to use a probe.”

This it the error