Is there a way to change the direction a motor goes with G-code instead of reconfiguring Marlin firmware?
Asked
Active
Viewed 2.8k times
10
-
2I don't understand the purpose of your question, but you can try to invert wiring of step motors instead creating another G-code or modifying the firmware. – Fernando Baltazar Jul 16 '17 at 20:48
-
The purpose of inverting a motor's direction in software would be to home to a switch placed in the opposite direction of the usual one, so as to use the homing routine as a Z probe. – jbiondo Jul 17 '17 at 21:56
-
So, you dont need to invert mootor direction for that porpuse, you need to indicate homing inverted. – Fernando Baltazar Jul 19 '17 at 15:52
-
Yes, thank you, that makes sense. Is there a way do do that with a GCode command instead of editing the firmware? – jbiondo Jul 20 '17 at 16:45
1 Answers
12
For the X/Y/Z axes, you can use M92
to change the axis steps per unit to a negative value, which causes it to move in the opposite direction. I.e. if normally your X axis has 160 steps per mm, using M92 X-160
will invert all of its movements.
However, this is more of a hack than a real, intended solution. It would be better to (if you are concerned with the homing direction) change the configuration to have the printer home in the other direction. Unfortunately, this can only be done by changing the firmware and not through G-code.
For the extruder, I'm not aware of any method to invert its direction with G-code.

Tom van der Zanden
- 14,588
- 2
- 33
- 60
-
What a brilliant and creative answer! That worked perfectly. I can now use the Z-MAX input as a Z probe, which allows me to probe in the down direction, and I can home in the up direction using the Z-MIN input, just by changing the axis steps to negative or positive as you described. – jbiondo Aug 05 '17 at 21:00
-
This is also helpful, inverting the `M92` number, for when you are trying out different extruders that may be driving from different sides of the filament. Thank you for this tip! – T Newcomb Nov 26 '21 at 14:38
-
How do I do this on an Extruder Motor? I've upgrade to a geared extruder so it was turning in the opposite way. I tried the solution listed above, causing the extruder motor to engage but not turn. I used 'M92 E-420.00'. – Liam Willey Dec 30 '21 at 14:37
-
@LiamWilley I just checked the marlin source code, and apparently there is an undocumented "feature" which causes marlin to - specifically for the E axis - interpret values smaller than 20 (including all negative values) as a "scaling factor" of sorts rather than as a steps/mm value to ensure compatibility with netfab. This means this solution can only be used with the X/Y/Z axes. – Tom van der Zanden Dec 31 '21 at 09:07