Notifications
Clear all
My Heavily Commented Custom G-code
I've gone through my Custom G-code and heavily commented it to remove some of the mystery. I thought I'd share it. Be aware that this customized for my nozzle wiper
Start G-code
; ═══════════════════════════════════════════════════════════════
; Prusa CORE One - Start G-Code (Custom)
; ═══════════════════════════════════════════════════════════════
; ── Startup & Hardware Checks ───────────────────────────────────
M17 ; enable stepper motors
M862.1 P[nozzle_diameter] A{(filament_abrasive[0] ? 1 : 0)} F{(nozzle_high_flow[0] ? 1 : 0)} ; verify nozzle diameter, abrasion resistance, and flow rate
M862.3 P "COREONE" ; verify correct printer model
M862.5 P2 ; verify G-code level compatibility
M862.6 P"Input shaper" ; verify firmware supports input shaper
M115 U6.4.0+11974 ; verify minimum firmware version
; ── Custom Hotend PID (Copper Block) ────────────────────────────
; Tuned PID values for copper heater block.
; P=proportional, I=integral, D=derivative gain.
M301 P25.03 I2.06 D76.09
; ── Print Area Definition ───────────────────────────────────────
; Bounding box with small margin to ensure MBL covers the full first layer.
M555 X{(min(print_bed_max[0], first_layer_print_min[0] + 32) - 32)} Y{(max(0, first_layer_print_min[1]) - 4)} W{((min(print_bed_max[0], max(first_layer_print_min[0] + 32, first_layer_print_max[0])))) - ((min(print_bed_max[0], first_layer_print_min[0] + 32) - 32))} H{((first_layer_print_max[1])) - ((max(0, first_layer_print_min[1]) - 4))}
; ── Motion & Extrusion Mode ─────────────────────────────────────
G90 ; absolute positioning for X/Y/Z
M83 ; relative positioning for extruder
; ── Vent Control & Initial Bed Temperature ──────────────────────
; Chamber filaments (ABS/ASA/PC/PA): close vent to trap heat, raise bed
; to 115°C to bring chamber up to temp faster.
; All others: open vent for airflow, use standard bed temp.
{if chamber_minimal_temperature[initial_tool]!=0}
M870 C ; close chamber vent to retain heat
M140 S115 ; elevated bed temp to accelerate chamber heating
{else}
M870 O ; open chamber vent for airflow
M140 S[first_layer_bed_temperature] ; standard first layer bed temp
{endif}
; ── Nozzle Preheat for Homing ───────────────────────────────────
; Heat nozzle to safe probing temp before homing.
; Logic: MBL160 note→160°C | HT_MBL10 note→first layer-10°C
; PC/PA→first layer-25°C | FLEX→210°C | default→170°C
M109 R{((filament_notes[0]=~/.*MBL160.*/) ? 160 : (filament_notes[0]=~/.*HT_MBL10.*/) ? (first_layer_temperature[0] - 10) : (filament_type[0] == "PC" or filament_type[0] == "PA") ? (first_layer_temperature[0] - 25) : (filament_type[0] == "FLEX") ? 210 : 170)}
M84 E ; turn off extruder motor to prevent heat creep
; ── Home All Axes ───────────────────────────────────────────────
G28 ; home X, Y, Z (no mesh leveling yet)
; ── Chamber Heating (if required) ───────────────────────────────
; Only runs for filaments with a minimum chamber temp set.
; Parks printhead at front-right to maximise chamber airflow,
; then blocks until chamber reaches minimum temp.
{if chamber_minimal_temperature[initial_tool]!=0}
M104 S{idle_temperature[initial_tool]} ; set nozzle to idle temp while waiting
G1 Z10 F720 ; lower bed to allow airflow
G1 X242 Y-9 F4800 ; park printhead for chamber circulation
M191 S{chamber_minimal_temperature[initial_tool]} ; block until chamber reaches minimum temp
M141 S{chamber_temperature[initial_tool]} ; set chamber to nominal temp (non-blocking)
M107 ; turn off part cooling fan
M140 S[first_layer_bed_temperature] ; set bed to first layer target temp
{else}
M141 S{chamber_temperature[initial_tool]} ; set chamber temp (no wait required)
{endif}
; ── Bed Fan Assist (low temp beds only) ─────────────────────────
; Run part cooling fan at low speed to help distribute heat evenly
; across beds at 60°C or below before probing.
{if first_layer_bed_temperature[initial_tool]<=60}M106 S70{endif}
; ── Position & Wait for Bed Temperature ─────────────────────────
G0 Z40 F10000 ; raise Z to prevent nozzle heat soak
M104 T{initial_tool} S{if is_nil(idle_temperature[initial_tool])}100{else}{idle_temperature[initial_tool]}{endif} ; nozzle to idle temp
M190 R[first_layer_bed_temperature] ; block until bed reaches target temp
M107 ; turn off part cooling fan
; ── Bed Heat Soak ───────────────────────────────────────────────
; Allow bed to thermally stabilize before MBL so the mesh reflects
; the bed's true expanded state.
;
; Tuning variables:
; heat_soak_area — area threshold in mm² (default 100×100mm = 10,000mm²)
; small_print_dwell — dwell time in seconds for small prints
;
; Small prints don't need full stabilization — bed expansion under a
; Benchy-sized footprint is negligible. Large prints spanning more of
; the bed benefit from the full G29 G wait.
{local print_w = first_layer_print_max[0] - first_layer_print_min[0]}
{local print_h = first_layer_print_max[1] - first_layer_print_min[1]}
{local heat_soak_area = 10000} ; threshold: 100×100mm
{local small_print_dwell = 10} ; short dwell in seconds for small prints
{if print_w * print_h < heat_soak_area}
G4 S{small_print_dwell} ; small print — short dwell sufficient
{else}
G29 G ; large print — full bed stabilization wait
{endif}
; ── Nozzle Heat for MBL ─────────────────────────────────────────
; Reheat nozzle to probing temp. Same logic as initial preheat above.
M109 R{((filament_notes[0]=~/.*MBL160.*/) ? 160 : (filament_notes[0]=~/.*HT_MBL10.*/) ? (first_layer_temperature[0] - 10) : (filament_type[0] == "PC" or filament_type[0] == "PA") ? (first_layer_temperature[0] - 25) : (filament_type[0] == "FLEX") ? 210 : 170)}
M302 S155 ; lower cold extrusion limit to 155°C for retraction during MBL
; ── Pre-MBL Retraction ──────────────────────────────────────────
; Retract to prevent ooze dragging across bed during probing moves.
; FLEX uses longer retraction due to elastic nature.
{if filament_type[initial_tool]=="FLEX"}
G1 E-4 F2400 ; retract 4mm (flexible filament)
{else}
G1 E-2 F2400 ; retract 2mm (standard filament)
{endif}
M84 E ; turn off extruder motor before wipe
; ── Nozzle Wipe ─────────────────────────────────────────────────
; Wipe nozzle across purge brush to remove ooze before probing.
M117 Wiping Nozzle
G0 X249 Y-17 Z5 F5000 ; approach wipe start, Z raised
G0 X211 Y-19 Z2 F5000 ; pass 1 left
G0 X211 Y-17 Z2 F5000 ; pass 1 adjust Y
G0 X249 Y-19 Z2 F5000 ; pass 2 right
G0 X211 Y-17 Z2 F5000 ; pass 3 left
G0 X211 Y-19 Z2 F5000 ; pass 3 adjust Y
G0 X249 Y-17 Z2 F5000 ; pass 4 right
G0 X249 Y-17 Z2 F5000 ; pass 4 hold
G0 X211 Y-19 Z2 F5000 ; pass 5 left
G0 X211 Y-17 Z2 F5000 ; pass 5 adjust Y
G0 X249 Y-18 Z2 F5000 ; pass 6 right
G0 X211 Y-19 Z2 F5000 ; pass 7 left
G0 X211 Y-19 Z2 F5000 ; pass 7 hold
G0 X249 Y-17 Z5 F5000 ; move away, raise Z to clear wiper
; ── Purge Zone Pre-probe (disabled) ─────────────────────────────
; Purge zone is now covered by G29 P1 X150 below.
;G29 P9 X208 Y-2.5 W32 H4
; ═══════════════════════════════════════════════════════════════
; Mesh Bed Leveling (MBL)
; ═══════════════════════════════════════════════════════════════
M84 E ; turn off extruder motor
G29 P1 ; invalidate existing mesh and probe print area
G29 P1 X150 Y0 W100 H20 C ; probe additional points near purge line area
G29 P3.2 ; interpolate missing probe points
G29 P3.13 ; extrapolate mesh outside probed area
G29 A ; activate mesh bed leveling compensation
; ═══════════════════════════════════════════════════════════════
; Purge Line
; ═══════════════════════════════════════════════════════════════
; ── Final Nozzle Heatup ─────────────────────────────────────────
M104 S{first_layer_temperature[0]} ; start heating to print temp (non-blocking)
G0 X200 Y-2.5 Z15 F4800 ; move to purge position while nozzle heats
M109 S{first_layer_temperature[0]} ; wait for nozzle to reach print temp
G92 E0 ; reset extruder position
M569 S0 E ; set extruder to spreadCycle mode
M591 S0 ; disable filament stuck detection during purge
; ── Filament Monitor Reset ──────────────────────────────────────
; Reset and enable monitor before purging so it starts tracking
; from a clean state at the beginning of the print.
G92 E0 ; reset extruder position
M118 A1 filmon:reset ; reset filament monitor counters
M118 A1 filmon:enable ; enable filament monitor
; ── Extrude Purge Line ──────────────────────────────────────────
; Purges old filament and primes nozzle. Speed ramps up gradually
; to build pressure and ensure consistent flow before printing.
G1 E{(filament_type[0] == "FLEX" ? 4 : 2)} F2400 ; de-retract (recover pre-MBL retraction)
G0 E5 X186 Z0.2 F500 ; purge — slow initial bead
G0 X176 E4 F500 ; purge — continue slow
G0 X166 E4 F650 ; purge — ramp speed
G0 X156 E4 F800 ; purge — full speed
G0 X153 Z0.05 F8000 ; wipe — drop Z to cut string
G0 X150 Z0.2 F8000 ; wipe — lift Z and move away
; ── Post-Purge Restore ──────────────────────────────────────────
M591 R ; restore filament stuck detection
G92 E0 ; reset extruder — print starts from zero
M221 S100 ; reset flow rate to 100%
End G-code
; ═══════════════════════════════════════════════════════════════
; Prusa CORE One - End G-Code (Custom)
; ═══════════════════════════════════════════════════════════════
; ── Filament Monitor ────────────────────────────────────────────
M118 A1 filmon:disable ; disable filament monitor — print complete
; ── Raise Print Head ────────────────────────────────────────────
; Move nozzle up 1mm above the print (capped at max print height)
; to clear the part before moving to park position.
{if layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+1, max_print_height)} F720{endif} ; raise nozzle above print
; ── Shutdown ────────────────────────────────────────────────────
M870 C ; close chamber vent
M104 S0 ; turn off nozzle heater
M140 S0 ; turn off bed heater
M141 S0 ; disable chamber temperature control
M107 ; turn off part cooling fan
; ── Park & Power Down ───────────────────────────────────────────
G1 X242 Y211 F10200 ; park printhead at rear-right
G4 ; wait for moves to complete
M572 S0 ; reset pressure advance to 0
M84 X Y E ; disable X, Y, and extruder motors (keep Z to hold bed)
; ── Debug Info ──────────────────────────────────────────────────
; max_layer_z = [max_layer_z] ; final layer height logged for reference
Before layer change G-code
; ═══════════════════════════════════════════════════════════════
; Before Layer Change
; ═══════════════════════════════════════════════════════════════
;BEFORE_LAYER_CHANGE ; slicer marker — do not remove
; ── Filament Monitor ────────────────────────────────────────────
; Arm the filament monitor on layer 2 (layer_num==1 is zero-indexed).
; Arming after the first layer avoids false triggers during the
; slower, higher-extrusion first layer moves.
{if layer_num==1}M118 A1 filmon:arm{endif}
; ── Reset Extruder ──────────────────────────────────────────────
G92 E0.0 ; reset extruder position to zero before each layer
;[layer_z] ; slicer token — outputs current layer Z height
; ── Dynamic Acceleration Scaling ────────────────────────────────
; Above 150mm, reduce X/Y acceleration progressively to limit
; oscillation and ringing on tall prints where the part is more
; susceptible to momentum-induced wobble.
;
; Acceleration table (mm/s²):
; 0 –150mm → 7000
; 150–200mm → 7000→4000 (linear ramp down)
; 200–270mm → 4000→2000 (linear ramp down)
; 270mm+ → 2000
{if layer_z > 150}
M201 X{interpolate_table(layer_z, (0,7000), (150,7000), (200,4000), (270,2000))} Y{interpolate_table(layer_z, (0,7000), (150,7000), (200,4000), (270,2000))} ; scale acceleration for current layer height
{endif}
Posted : 27/02/2026 12:29 am
1 people liked
RE: My Heavily Commented Custom G-code
Very nice.
You have put down a LOT of work in this.
Thanks for sharing.
---
Gert
Posted : 27/02/2026 6:21 am