<p>For the X/Y/Z axes, you can use <code>M92</code> 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 <code>M92 X-160</code> will invert all of its movements.</p>
<p>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.</p>
<p>For the extruder, I'm not aware of any method to invert its direction with G-code.</p>

CC BY-SA 3.0
2017-08-05T21:00:30.017Z
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
CC BY-SA 4.0
2021-11-26T14:38:10.110Z
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
CC BY-SA 4.0
2021-12-30T14:37:20.587Z
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
CC BY-SA 4.0
2021-12-31T09:07:30.820Z
@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
CC BY-SA 4.0
2024-05-06T03:25:42.990Z
For future readers, I would not recommend trying this. Perhaps it worked at one time, but was probably a bug. On Marlin 1.19 I tried setting negative X steps, which DID initially work to reverse the motor, however, X homing did not work, the toolhead hit the end stop forcefully and caused the servo to jump/skip (luckily not causing any damage). So it seems that negative steps reverse the motor direction but at the cost of broken X homing. I mechanically reversed the motor by flipping the connector, re-set positive steps, and it worked fine.
BetterSense
CC BY-SA 4.0
2017-08-03T07:36:51.330Z
2021-12-31T09:08:04.010Z
2021-12-31T09:08:04.010Z
Tom van der Zanden
<p>You cannot use <code>M92 E-</code> on Marlin (anymore).</p>
<p>The right solution nowadays is taking the wires out of the plug of the stepper motor connector using a prying tool and switching them all totally the flipped way around. That way the motor gets the signals the other way round.</p>

CC BY-SA 4.0
2023-06-13T18:54:06.073Z
2023-06-13T19:16:25.353Z
2023-06-13T19:16:25.353Z
robertovm
<p>Is there a way to change the direction a motor goes with G-code instead of reconfiguring Marlin firmware?</p>

CC BY-SA 3.0
2017-07-16T20:48:52.880Z
I 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
CC BY-SA 3.0
2017-07-17T21:56:22.013Z
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
CC BY-SA 3.0
2017-07-19T15:52:34.603Z
So, you dont need to invert mootor direction for that porpuse, you need to indicate homing inverted.
Fernando Baltazar
CC BY-SA 3.0
2017-07-20T16:45:14.507Z
Yes, thank you, that makes sense. Is there a way do do that with a GCode command instead of editing the firmware?
jbiondo
<marlin><firmware><stepper>
Is there a way to invert motor direction with G-code instead of Firmware in Marlin
jbiondo
# Is there a way to invert motor direction with G-code instead of Firmware in Marlin

(Asked by: username_0 on 2017-07-16)

Is there a way to change the direction a motor goes with G-code instead of reconfiguring Marlin firmware?

**Tags:** marlin, firmware, stepper
> **Comments:**
> **username_1**: I 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.  
> **username_0**: 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.  
> **username_1**: So, you dont need to invert mootor direction for that porpuse, you need to indicate homing inverted.  
> **username_0**: Yes, thank you, that makes sense. Is there a way do do that with a GCode command instead of editing the firmware?  

---

## 2 answers

### Answer by username_2 on 2017-08-03. Score: 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.

> **Comments:**
> **username_0**: 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.  
> **username_3**: 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!  
> **username_4**: 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'.  
> **username_2**: @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.  
> **username_5**: For future readers, I would not recommend trying this. Perhaps it worked at one time, but was probably a bug. On Marlin 1.19 I tried setting negative X steps, which DID initially work to reverse the motor, however, X homing did not work, the toolhead hit the end stop forcefully and caused the servo to jump/skip (luckily not causing any damage). So it seems that negative steps reverse the motor direction but at the cost of broken X homing. I mechanically reversed the motor by flipping the connector, re-set positive steps, and it worked fine.  

---

### Answer by username_6 on 2023-06-13. Score: 1

You cannot use `M92 E-` on Marlin (anymore).

The right solution nowadays is taking the wires out of the plug of the stepper motor connector using a prying tool and switching them all totally the flipped way around. That way the motor gets the signals the other way round.


---

