Dual Endstops: Adding Home Offsets to firmware

Hi,
I just finished squaring my lovely new MPCNC, but instead of adding “M666 X1” (for 1mm home offset on X1 stepper) to the g-code every time, I would like to put it in the firmware as Ryan suggests. I just do not seem to be able to find where to put it. I searched configuration.h for keywords like offset, etc., but did not figure out which part of the code to edit. Could someone give me a hint what / where I need to change something to give X1 a default offset of 1mm?

If your eeprom works, you can do this to save it:

M666 X1
M500

2 Likes

If for some reason you CAN’T save with M500, there is a way to enable the EEPROM, but I can’t recall. Google should sort it out pretty quick.
The part of the code you’re looking for is the dual endstop offset. Just search for “Offset” in config_adv (or was it config?) and you’ll find it. I like to update the value there in case I want to reflash later.

1 Like

Hmm, Ryan said to edit configuration.h, but I checked configuration_adv.h now and I think now I found the section about dual endstops. The comment in code says Use X_DUAL_ENDSTOP_ADJUSTMENT to adjust for mechanical imperfection. After homing both motors this offset is applied to the X2 motor. , but I want to add one mm to X1. I guess in that case I would have to move the physical endstop of X2 back one tooth on the belt (x = -2mm) and change X_DUAL_ENDSTOP_ADJUSTMENT 0 to X_DUAL_ENDSTOP_ADJUSTMENT 1 to get the same result (1 mm offset between X1 and X2, where the X position of X2 is that of X1 plus 1mm), right? Yeah instead of typing all this I could as well try I guess. I will do that, draw a square and report if that worked.

Yeah, that seems better. You can only offset the second motor of a pair. Makes adjustments simpler by having few options.

1 Like

So, that worked! The physical endstop stays where it is though, so there must be something wrong with my reasoning, but the bottomline is that it works now. Thanks Jeffeb3 & Tony!

3 Likes

Maybe it’s too late at night, but I’m not seeing where to insert the adjustment value. I see X_DUAL_ENDSTOP_ADJUSTMENT mentioned in the description, but I do not see the actual line of code to edit. Do I manually add the parameter and value?

No practical knowledge, but poking around a bit I think you are looking for this _DUAL_ENDSTOP_ADJUSTMENT values in configuration_adv.h. Here is the section copied:

**
 * Dual Steppers / Dual Endstops
 *
 * This section will allow you to use extra E drivers to drive a second motor for X, Y, or Z axes.
 *
 * For example, set X_DUAL_STEPPER_DRIVERS setting to use a second motor. If the motors need to
 * spin in opposite directions set INVERT_X2_VS_X_DIR. If the second motor needs its own endstop
 * set X_DUAL_ENDSTOPS. This can adjust for "racking." Use X2_USE_ENDSTOP to set the endstop plug
 * that should be used for the second endstop. Extra endstops will appear in the output of 'M119'.
 *
 * Use X_DUAL_ENDSTOP_ADJUSTMENT to adjust for mechanical imperfection. After homing both motors
 * this offset is applied to the X2 motor. To find the offset home the X axis, and measure the error
 * in X2. Dual endstop offsets can be set at runtime with 'M666 X Y Z'.
 */

#define X_DUAL_STEPPER_DRIVERS
#if ENABLED(X_DUAL_STEPPER_DRIVERS)
  #define INVERT_X2_VS_X_DIR true   // Set 'true' if X motors should rotate in opposite directions
  #define X_DUAL_ENDSTOPS
  #if ENABLED(X_DUAL_ENDSTOPS)
    #define X2_USE_ENDSTOP _XMAX_
    #define X2_ENDSTOP_ADJUSTMENT  0
  #endif
#endif

#define Y_DUAL_STEPPER_DRIVERS
#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
  #define INVERT_Y2_VS_Y_DIR true   // Set 'true' if Y motors should rotate in opposite directions
  #define Y_DUAL_ENDSTOPS
  #if ENABLED(Y_DUAL_ENDSTOPS)
    #define Y2_USE_ENDSTOP _YMAX_
    #define Y2_ENDSTOP_ADJUSTMENT  0
  #endif
#endif

Thank you, but that is the same section I pasted in above. The thing is, I don’t see a line specifically for X_DUAL_ENDSTOP_ADJUSTMENT.

You are absolutely right. Sorry. According to the comment, the adjustment is made relative to the X motor. So the X position is considered the base position, and X2 is then adjusted. Considering that the M666 g-code does not allow you to specify X1 or X2, I’m assuming that it is adjusting X2. Anyway, you can try it. If it is backwards, you can set X2_ENDSTOP_ADJUSTMENT to -1 instead.

Just to end this with some clarity, the issue I was having is the parameter X_DUAL_ENDSTOP_ADJUSTMENT is used in the description (line 543 in Configuration_adv.h), but that parameter doesn’t exist in the actual code. It’s a case of poorly updated Marlin code: X2_ENDSTOP_ADJUSTMENT is the replacement parameter. I didn’t find this information anywhere in the forum, so it may be useful for someone in the future.

Also, M666 will reflect any value used with this parameter. So, for example, if you use X2_ENDSTOP_ADJUSTMENT 1.0, M666 will show X1.00.

3 Likes