<p>There are three things to fix and one suggestion:</p>
<ul>
<li><p>Change follwing lines of <a href="https://marlinfw.org/docs/gcode/M109.html" rel="nofollow noreferrer"><code>M109</code></a>, using parameter <code>R</code> instead of <code>S</code>, because the latter is not waiting to cool down:</p>
<pre><code>M109 R160 ; Wait for 160C
...
M109 R110 ; Heat hotend to 110C
</code></pre>
</li>
<li><p>The behavior of <code>M420</code> will depend on type of bed leveling, saved mesh, etc. It is off topic to troubleshoot this. The printer operates 10 cm above the surface for this operation. <code>G28</code> disables bed leveling. Why do you need to re-enable it? Just remove this line:</p>
<pre><code>; M420 S1 - remove (or comment out)
</code></pre>
</li>
<li><p>Redefine maximum extrusion length in <em>Configuration.h</em> to allow for scripted long pull (<code>G1 E-430</code>), for example:</p>
<pre><code>#define EXTRUDE_MAXLENGTH 450
</code></pre>
</li>
<li><p><em>Suggestion:</em> Use relative mode for extrusion (<code>M83</code>) instead of absolute positioning (<code>M82</code>). It will simplify your code a lot. You just want to express the distance in <code>E</code> parameter. Then you will not have to reset position with <code>G92 E0</code> every now and then (do it just once on the start). (<em>I use this <a href="/a/15572/26170">Extrusion mode</a> also for slicing becuase it makes easier to re-start a print in case of failure</em>).</p>
</li>
</ul>

CC BY-SA 4.0
2021-02-08T08:23:15.233Z
[Note: 160 might be below the temperature that allows to move the extruder.](https://3dprinting.stackexchange.com/questions/15495/how-to-print-at-low-temperatures-filament-melting-at-about-70-c). Luckily OP included `M302 S105` before the cooldown.
Trish
CC BY-SA 4.0
2021-02-08T08:36:19.567Z
Yes, the script looks quite mature and consistent. Btw. I have added `#define  USER_DESC_7 "Allow cold extrusion"` `#define USER_GCODE_7 "M302 P1"` to my custom commands in *Configuration_adv.h* and used it quite often since then.
octopus8
CC BY-SA 4.0
2021-02-08T17:25:07.640Z
Thanks @octopus8. I use the factory firmware for my EryOne ER-20. As I see the Marlin FW development is Windows centrist. The flashing tool was even not working for me on Linux, I had to borrow a Windows machine to flash the printer with the new factory FW release.
Endre
CC BY-SA 4.0
2021-02-08T17:27:16.350Z
Maybe I'll try to set up some kind of serial debug logging (if it is possible), and I hope I'll get some meaningful error messages (like M302 is not supported by this config).
Endre
CC BY-SA 4.0
2021-02-08T17:47:44.923Z
But to change lines in G-code - as described in an answer - and possibly make you script work, you don't need to re-flash Marlin. Or do you, for any reason which I do not recognize? But for tunning custom menu, yes indeed.
octopus8
CC BY-SA 4.0
2021-02-08T17:51:17.107Z
Thanks for the "using parameter R instead of S" tip. Now I see the cool-down sequence. But no extrusion (pull) happens. Maybe it is just not enabled in the FW. Other annoying thing, that the bed leveling always happens. Is there any way to turn that off? As I remember when I worked on startup g-code for the Cura slicer, I had to figure out how to bed-level from the code. Now I have to figure out how to not bed-level :)
Endre
CC BY-SA 4.0
2021-02-08T18:28:26.070Z
`M302 S105` followed by `G1 E-1` works for me at 145 °C, I just checked it with PuTTY. *(Maybe you would like to try executing your script line by line, manually from terminal? Marlin is giving some valuable textual feedback, more debug details with `M111 S247`.)* As for the auto bed leveling I do not have a response at hand, I was too lazy so far to inspect all these settings in practice... but: maybe you didn't ever save the mesh to EEPROM after performing leveling, and thus it wants to re-do this process?
octopus8
CC BY-SA 4.0
2021-02-08T18:37:15.630Z
Hi, I guess I got it. I have checked the source of the Factory FW and I have seen that the maximum extrusion length is set to 200. So I divided my long one piece extrusion into 3 smaller and now the pull back is working.
Endre
CC BY-SA 4.0
2021-02-08T06:33:55.780Z
2021-02-08T18:45:34.940Z
2021-02-08T18:45:34.940Z
octopus8
<p>I have upgraded my ER-20 with a Bondtech dual gear feeder.
It is not or hardly possible to load/unload filament manually with this feeder, so some .gcode is needed to do it.
I wanted to implement something similar to the atomic cleaning method for unloading: <a href="https://ultimakernasupport.zendesk.com/hc/en-us/articles/115004187066-Atomic-Cleaning-Method" rel="nofollow noreferrer">https://ultimakernasupport.zendesk.com/hc/en-us/articles/115004187066-Atomic-Cleaning-Method</a></p>
<p>Here is my current <code>.gcode</code>:</p>
<pre><code>G21 ; Metric values
G90 ; Absolute positioning
M82 ; Extruder absolute mode
G28 ; Auto home
M420 S1
G1 X100 Y100 Z100 F1000
; M92 E415 ; 415 steps/mm
M302 S105 ; Allow extrusion above 105C
M109 S218 ; Heat hotend to 218C
M400
G92 E0 ; Reset extruder positioning
M104 S160 ; Start the cool down
M117 Extrude prime blob
G1 E10 F100 ; Extrude a short before unload to avoid blob forming
M109 S160 ; Wait for 160C
M104 S110
G92 E0
G1 E0.2 F100 ; Pressurize the hotend
M117 Pressurize hotend
M109 S110 ; Heat hotend to 110C
G92 E0 ; Reset extruder positioning
M117 Pull out slow
G1 E-3 F200 ; Pull back a bit, slow
M117 Pull out fast
G1 E-430 F2000 ; Pull back 43cm with 2000mm/min
G92 E0 ; Reset extruder positioning
M400 ; Wait for command finish
M117 Remove the filament now
; M400 ; Wait for command finish
M302 S170 ; Allow extrusion above 170C
M104 S0
</code></pre>
<p>It doesn't work:</p>
<ul>
<li>the auto bed leveling is always done, I don't know how to turn it off</li>
<li>when I see that the &quot;Extrude a short before unload to avoid blob forming&quot; event is happening, I also see the &quot;Pull out fast&quot; message on the display and the &quot;print&quot; process ends</li>
</ul>
<p>Could anyone take a look at this code please? Or <strong>is there any <code>.gcode</code> validator for Marlin somewhere</strong>?</p>
<p><strong>What I intend to do with this code:</strong></p>
<ul>
<li>heat up the hotend to 218 °C</li>
<li>extrude some material while a cool down to 160 °C is already started</li>
<li>when temp 160 °C is reached, start a cool-down process to 110 °C and push a little material to the feeder (pressurize)</li>
<li>when 110 °C is reached pull out some material from the hotend slow (maybe the feeder won't be enough strong to do it, but I have never reached this point to check)</li>
<li>then pull out the filament from the Bowden and feeder fast</li>
</ul>

<marlin><extruder><g-code>
Marlin firmware: unload filament with G-code
Endre
# Marlin firmware: unload filament with G-code

(Asked by: username_0 on 2021-02-07)

I have upgraded my ER-20 with a Bondtech dual gear feeder.
It is not or hardly possible to load/unload filament manually with this feeder, so some .gcode is needed to do it.
I wanted to implement something similar to the atomic cleaning method for unloading: https://ultimakernasupport.zendesk.com/hc/en-us/articles/115004187066-Atomic-Cleaning-Method
Here is my current .gcode:
G21 ; Metric values
G90 ; Absolute positioning
M82 ; Extruder absolute mode
G28 ; Auto home
M420 S1
G1 X100 Y100 Z100 F1000
; M92 E415 ; 415 steps/mm
M302 S105 ; Allow extrusion above 105C
M109 S218 ; Heat hotend to 218C
M400
G92 E0 ; Reset extruder positioning
M104 S160 ; Start the cool down
M117 Extrude prime blob
G1 E10 F100 ; Extrude a short before unload to avoid blob forming
M109 S160 ; Wait for 160C
M104 S110
G92 E0
G1 E0.2 F100 ; Pressurize the hotend
M117 Pressurize hotend
M109 S110 ; Heat hotend to 110C
G92 E0 ; Reset extruder positioning
M117 Pull out slow
G1 E-3 F200 ; Pull back a bit, slow
M117 Pull out fast
G1 E-430 F2000 ; Pull back 43cm with 2000mm/min
G92 E0 ; Reset extruder positioning
M400 ; Wait for command finish
M117 Remove the filament now
; M400 ; Wait for command finish
M302 S170 ; Allow extrusion above 170C
M104 S0

It doesn't work:

the auto bed leveling is always done, I don't know how to turn it off
when I see that the "Extrude a short before unload to avoid blob forming" event is happening, I also see the "Pull out fast" message on the display and the "print" process ends

Could anyone take a look at this code please? Or is there any .gcode validator for Marlin somewhere?
What I intend to do with this code:

heat up the hotend to 218 °C
extrude some material while a cool down to 160 °C is already started
when temp 160 °C is reached, start a cool-down process to 110 °C and push a little material to the feeder (pressurize)
when 110 °C is reached pull out some material from the hotend slow (maybe the feeder won't be enough strong to do it, but I have never reached this point to check)
then pull out the filament from the Bowden and feeder fast

**Tags:** marlin, extruder, g-code

---

## 1 answers

### Answer by username_1 on 2021-02-08. Score: 3 | Accepted answer

There are three things to fix and one suggestion:

Change follwing lines of M109, using parameter R instead of S, because the latter is not waiting to cool down:
M109 R160 ; Wait for 160C
...
M109 R110 ; Heat hotend to 110C


The behavior of M420 will depend on type of bed leveling, saved mesh, etc. It is off topic to troubleshoot this. The printer operates 10 cm above the surface for this operation. G28 disables bed leveling. Why do you need to re-enable it? Just remove this line:
; M420 S1 - remove (or comment out)


Redefine maximum extrusion length in Configuration.h to allow for scripted long pull (G1 E-430), for example:
#define EXTRUDE_MAXLENGTH 450


Suggestion: Use relative mode for extrusion (M83) instead of absolute positioning (M82). It will simplify your code a lot. You just want to express the distance in E parameter. Then you will not have to reset position with G92 E0 every now and then (do it just once on the start). (I use this Extrusion mode also for slicing becuase it makes easier to re-start a print in case of failure).

> **Comments:**
> **username_2**: [Note: 160 might be below the temperature that allows to move the extruder.](https://3dprinting.stackexchange.com/questions/15495/how-to-print-at-low-temperatures-filament-melting-at-about-70-c). Luckily OP included `M302 S105` before the cooldown.  
> **username_1**: Yes, the script looks quite mature and consistent. Btw. I have added `#define  USER_DESC_7 "Allow cold extrusion"` `#define USER_GCODE_7 "M302 P1"` to my custom commands in *Configuration_adv.h* and used it quite often since then.  
> **username_0**: Thanks @octopus8. I use the factory firmware for my EryOne ER-20. As I see the Marlin FW development is Windows centrist. The flashing tool was even not working for me on Linux, I had to borrow a Windows machine to flash the printer with the new factory FW release.  
> **username_0**: Maybe I'll try to set up some kind of serial debug logging (if it is possible), and I hope I'll get some meaningful error messages (like M302 is not supported by this config).  
> **username_1**: But to change lines in G-code - as described in an answer - and possibly make you script work, you don't need to re-flash Marlin. Or do you, for any reason which I do not recognize? But for tunning custom menu, yes indeed.  
> **username_0**: Thanks for the "using parameter R instead of S" tip. Now I see the cool-down sequence. But no extrusion (pull) happens. Maybe it is just not enabled in the FW. Other annoying thing, that the bed leveling always happens. Is there any way to turn that off? As I remember when I worked on startup g-code for the Cura slicer, I had to figure out how to bed-level from the code. Now I have to figure out how to not bed-level :)  
> **username_1**: `M302 S105` followed by `G1 E-1` works for me at 145 °C, I just checked it with PuTTY. *(Maybe you would like to try executing your script line by line, manually from terminal? Marlin is giving some valuable textual feedback, more debug details with `M111 S247`.)* As for the auto bed leveling I do not have a response at hand, I was too lazy so far to inspect all these settings in practice... but: maybe you didn't ever save the mesh to EEPROM after performing leveling, and thus it wants to re-do this process?  
> **username_0**: Hi, I guess I got it. I have checked the source of the Factory FW and I have seen that the maximum extrusion length is set to 200. So I divided my long one piece extrusion into 3 smaller and now the pull back is working.  

---

