H2S blobs wipe by layer gcode instructions

We are trying to add a routine to automatically clean the nozzle during printing because filament tends to build up on the nozzle, which reduces print quality. Our plan was to use the built-in Bambu wipe command (G150.1), but only every 3 layers.

We tried the following code in Bambu Studio’s Custom G-code field:

{% if layer_num > 0 and layer_num % 3 == 0 %}
M400
G91
G1 E-0.4 F1800
G90
G150.1 F18000
G91
G1 E-0.6 F1800
G90
{% endif %}

Issues we are encountering:

  1. The code does not execute during printing.

  2. {% %} (Jinja templating) is not processed in this field by Bambu Studio.

  3. Layer-by-layer conditional actions (like every 3 layers) seem not possible in the standard Custom G-code field.

What we want to achieve:

  • Automatically clean the nozzle during the print, ideally at a set frequency (e.g., every 3 layers).

  • Use the built-in G150.1 wipe routine.

  • Minimize filament buildup and blobs that reduce print quality.

Questions for the community:

  • Is there another method to automatically clean the nozzle during printing, preferably using G150.1?

  • Are there any workarounds or slicer settings that can achieve the same effect?

1 Like

Are you an openclaw/AI agent?

2 Likes

No, I changed my 1XC for the H2S and in the meantime with other settings the blobs are minimised but still there. I believe that only extra cleaning of the nozzle should be a solution.

I found out that the gcode 150.3 moves the nozzle to the purge position and 150.1 executes the wiping/cleaning. We want to ad this after the layer change which can be found in the machine g-code “change layer”. But with the possibility to choose wich layer number should activate the cleaning.

Many thanks for your help.

If you are having nozzle buildup issues, you might look into the flow rate.

You might simply remove the condition and run it at every layer and see if that does the job.

This may help. I haven’t tested it yet myself, but the gcode looks reasonable and they took the time to share it so I would assume they did some testing.

1 Like

Thank you so much Cleavitt. With some tuning, this part of gcode solves the blob problem. I clean for instance each 20 layers and this depend of course how much material is spended for one layer. There is a code included to prime the nozzle. This code injects after cleaning an amount of fillament in the nozzle to compensate the loss during cleaning; 2mm is sugested. I did a lot of experiments en found that 0.95 was ideal for my fillamnent. To high makes blobs again, to less underextrudes the first few centimeters. Interesting is to start from the inside, the underextrusion is then invisibel. Also the temperature is a part of the tuning.

In case that more Bambu H2S users are suffering the same problem with blobs and want extra help to install this code, please let me know.

Thanks again Cleavitt it was a golden hint !

1 Like

Glad it helped. I would be interested in whatever you came up with. Feel free to share code if it makes sense.

1 Like

Hi Cleavitt,

This may be too much information, but I’m trying to be as thorough as possible.

I’ve done a lot of testing with standard PETG that tends to blob. As of today, no more prints are being ruined!

With this G-code, the retraction was initially 2 mm, and I adjusted it to 0.95 mm to properly refill the nozzle. This helps avoid under- or over-extrusion at the restart after cleaning. To test this, I printed a very small object (30 × 5 × 2 mm), standing on the 30 × 2 side, and triggered cleaning every 20 layers.

The temperature can also be lowered to further optimize results. I found that 245 °C works well.

To change how often cleaning occurs (number of layers), you’ll need to adjust this directly in the G-code where you’ve inserted it.

The original code was written by JK3D and can be found on MakerWorld—thanks to JK3D for this!

Once installed, the code will appear in the G-code list generated by the Bambu Lab slicer, where you can verify that it is present. The steps (1 to 4) guide you in replacing the existing G-code with the version below:

;============= H2S 20250611 =============

; layer num/total_layer_count: {layer_num+1}/[total_layer_count]

;### START: PETG NOZZLE WIPE SEQUENCE ###

; This logic handles nozzle cleaning at critical stages: Layer 2, every 5 layers, and the final layer.

{if (filament_type[initial_no_support_extruder] == “PETG”) && (layer_num > 0)}

; — LOGIC —
; Check if current layer is: Layer 2 OR every 20 th layer OR the very last layer

{if (layer_num == 2) || (layer_num % 20 == 0) || (layer_num == (total_layer_count - 1))}

M117 Nozzle Wipe Sequence (L:{layer_num})

M400 ; Finish all moves

G91 ; Relative positioning

G1 Z0.4 F1200 ; Z-Hop

M83 ; Relative extrusion

G1 E-2.0 F1800 ; Retract to prevent oozing

G90 ; Absolute positioning

G150.3 ; Move to trash bin area

G150.1 F8000 ; Wipe sequence 1

G150.1 F8000 ; Wipe sequence 2

G150.1 F8000 ; Wipe sequence 3

G1 E0.95 F1800 ; Prime nozzle was 2.0 to prevent oozing

G91 ; Relative positioning

G1 Z-0.4 F1200 ; Return Z to original height

G90 ; Absolute positioning

{endif}

{endif}

;### END: PETG NOZZLE WIPE SEQUENCE ###

; update layer progress

M73 L{layer_num+1}

M991 S0 P{layer_num} ;notify layer change



The modified G-code should now be visible after slicing:

NOTICE FOR BAMBU LAB DEVELOPERS:

This tool is extremely valuable because it prevents blobs, saves prints, and reduces frustration.

It would be greatly appreciated if you could implement a parameter based on time (e.g., every X minutes) or filament usage (e.g., every X grams consumed) to trigger each wipe sequence.


Kind regards,
And as always, please be careful when making changes—you do so at your own responsibility.

Ronny

1 Like

Thanks for sharing! I’ll give this a try in the next few weeks. It looks great.

I just started printing, and have been having issues with blobbing on large prints. with your g code do I just need to change to the material im using, which is PLA Matte, and the intervals I want the cleaning to happening?

If youre on discord let me know - id love to talk more into this.

Hi there,

The G-code only works when there is a layer change and when 100 is evenly divisible by the number you have entered. For example: 100/5 = 20, 100/10 = 10, or 100/20 = 5, etc.

That is all the G-code does, but it makes a significant difference in reducing blobs. For me, it works perfectly.

I have made some minor changes to the code: to avoid the silicone sock wearing out too quickly, I removed wipe sequence 3. I also set the prime nozzle value to 0.95 instead of 2, to avoid excess filament.

For my PETG filament, I set retraction to 0.4 and Z-hop to 0.4 as well, using the “spiral” Z-hop type.

The extra length on restart is set to -0.03 mm. Lowering the travel speed to 400 mm/s helps make the seam less visible.

So far, I am only printing with PETG which is more difficult than PLA.

I still hope that the engineers at Bambu Lab will implement a nozzle wipe based on time or filament volume.

Kind regards, Ronny