Customizing Gcode

What is Gcode?

Whether printing from SD card or directly to the printer’s USB connection, Gcode is the programming language that is used to control and command the printer. Slicing software converts your 3D file into a long program which the printer follows to reproduce your part. There are specific Gcode commands for every type of action the printer can take, including changing temperatures, moving to a certain location, moving at a certain speed, extruding filament, etc.

For normal purposes most users won’t ever need to customize Gcode although advanced users might find benefits from doing so. Understanding Gcode can also be very helpful in diagnosing print errors to determine if they are hardware or software errors.


What can I customize?

It’s possible to use custom Gcode scripts to alter your printer’s startup procedure prior to prints, the end procedure following prints, to add custom functions between individual printed layers, to adjust retraction, to add special motions for multiple material printing, and more.

Not all slicing software will allow you to customize all of the Gcode scripting, and often it is hidden behind “advanced” settings when possible. In some cases different software allows for different variables and codes to be used for scripting so not all scripts will work in all slicers without some adjustment. For reference of program-specific Gcode scripts for your MAKEiT printer, please check the “Gcode Scripts for MAKEiT Printers” section below


Common Gcode Command Reference

Click here to download RepRap’s “GCode Cheat Sheet” with descriptions of many common commands as a viewable .pdf.

For a complete list and description of GCode commands please see this GCode reference list from the RepRap wiki.


GCode Scripts by Software

Starting Script

M106 S255 ;set fan to max
M117 Heating Bed  ;Display "Heating Bed" on screen
M140 S[bed0_temperature] ;set bed temperature to heat
M190 S[bed0_temperature] ;wait for bed to reach set temperature
M117 Heating Nozzles  ;Display "Heating Nozzles" on screen
M104 S[extruder0_temperature] T0 ;set nozzle 1 temp
M104 S[extruder1_temperature] T1 ;set nozzle 2 temp
M109 S[extruder0_temperature] T0 ;wait for N1 to reach temp
M109 S[extruder1_temperature] T1 ;wait for N2 to reach temp
M106 S[fan_speed_pwm] ;set fan speed for first layer
M117 Priming Nozzles ;Display "Priming Nozzles" on screen
G28 ;Home the extruder head on X-axis
G21 ;Metric Values
G90 ;Set Absolute Positioning
M82 ;Set extruder to Absolute Positioning
G92 E0 ;Zero the extruded length
G1 E15 F200;Extrude 15mm of filament to prime nozzle
G92 E0 ;Zero the extruded length
G1 E-5 ;retract filament
G28 SC ;Home the extruder head tell printer to prepare for start (S) and run nozzle cleaning procedure (C)
G92 X-6 ;Sets Simplify3D coordinates to match heated bed with 6cm offset
M117 Printing ;Display "Printing" on LCD

Layer Change Script

Tool Change Script

By default, this script is not enabled in Simplify3D. To enable this script for your prints go into the Scripts tab of your process settings and remove the “;” (semi-colon) at the start of each line.

{IF NEWTOOL=0} ; LEFT Extruder is active (T0)
{IF NEWTOOL=0}M104 S190 T1 ; Cool inactive extruder to 175c (T1)
{IF NEWTOOL=0}M104 S200 T0 ; Heat active extruder to 210c (T0).
{IF NEWTOOL=1} ; RIGHT Extruder is active (T1)
{IF NEWTOOL=1}M104 S190 T0 ; Cool inactive extruder to 190c (T0)
{IF NEWTOOL=1}M104 S200 T1 ; Heat active extruder to 195c (T1).

Ending Script

By default this ending script will not automatically shut off the printer after completion. If you would like to enable auto-shutdown for your prints, delete the “;” (semi-colon) that appears on the last line in front of the “M81” command, this will enable auto-shutdown.

M104 S0 ; turn off extruder
M140 S0 ; turn off bed
M84 ; disable motors
G91 ; relative positioning
G1 E-10 X-50 Y-50 ; move and retract filament even more
M117 Print Complete
M84 ;steppers off
G90 ;absolute positioning
;M81 ;Turns power off from the printer

Start G-Code

G21  ;Metric values
G90  ;Set absolute positioning
M82  ;Set extruder to absolute positioning
M106 S255  ;Set fan on full
G1 F200 E10  ;Extrude 10mm of filament to prime nozzle
G92 E0  ;Zero the extruded length
G1 E-3  ;Retract filament slightly to avoid leaking before starting part
G28 SC ;Run homing and nozzle cleaning procedure
G92 X-6 ;Adjust software coordinates to match with MAKEiT print bed

End G-Code

M106 S255
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-2 F9000
G1 Z+5
G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way
M84 ;steppers off
G90 ;absolute positioning
;M81 ;Power off the printer (remove semi-colon in front of line to enable)

Layer Change G-Code

Currently MAKEiT does not specify any script for layer change in Matter Control.

Before Tool Change G-Code

Currently MAKEiT does not specify any script for before tool change in Matter Control.

After Tool Change G-Code

Currently MAKEiT does not specify any script for after tool change in Matter Control.

Pause G-Code

Currently MAKEiT does not specify any custom script for pause in Matter Control.

Resume G-Code

Currently MAKEiT does not specify any custom script for resume in Matter Control.

Cancel G-Code

Currently MAKEiT does not specify any custom script for cancel in Matter Control.

On Connect G-Code

Currently MAKEiT does not specify any custom script for on-connect in Matter Control.

start.gcode

M117 Heating Bed
M106 S255 ;set fan to max
M140 S{print_bed_temperature} ;Set target temperature for the heated bed.
M190 ;wait until bed has heated
M117 Heating Nozzles
M104 T0 S{print_temperature} ;Set target temperature for the nozzle 1.
M109 T0 ;Wait until nozzle 1 have reached target temperature.
M117 Priming Nozzles
T0
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
G92 E0 ;zero the extruded length
G28
G1 E15 F200 ;extrude 30mm of feed stock
G92 E0
G1 E-5 ;retract 5 mm
G28 SC ;Do homeing, clean nozzles (C) and let printer to know that printing started (S)
G92 X-6 ;Sets Curas checker board to match printers heated bed coordinates
M117 Printing ;Send message to the LCD display on the printer.

end.gcode

M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-7 ;retract filament before moving
G28 XY ;move nozzle away from print
M117 Print Complete
M84 ;steppers off
G90 ;absolute positioning
;M81 ;Turns power off from the printer

preSwitchExtruder.gcode

postSwitchExtruder.gcode

start2.gcode

M117 Heating Bed
M140 S{print_bed_temperature} ;Set target temperature for the heated bed.
M190 ;Wait until heated bed have reached target temperature.
M104 T1 S{print_temperature2} ;Set target temperature for the nozzle 2.
M104 T0 S{print_temperature} ;Set target temperature for the nozzle 1.
M117 Heating Nozzles
M109 T1 ;Wait until nozzle 2 have reached target temperature.
M109 T0 ;Wait until nozzle 1 have reached target temperature.
M117 Priming Nozzles
G28
G21 ;metric values
G90 ;absolute positioning
T1 ;Switch to the 2nd extruder
G92 E0 ;zero the extruded length
G1 E30 F200 ;extrude 30mm of feed stock
G92 E0
G1 E-{retraction_dual_amount}
T0 ;Switch to the first extruder
G92 E0 ;zero the extruded length
G1 E30 F200 ;extrude 30mm of feed stock
G92 E0
G1 E-5
G28 SC ;Home, run cleaning, prepare for print
M117 Printing ;Put printing message on LCD screen
G92 X-6

end2.gcode

M104 T0 S0 ;extruder heater off
M104 T1 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-7 ;retract filament before moving
G28 XY ;move nozzle away from print
M117 Print Complete
M84 ;steppers off
G90 ;absolute positioning
;M81 ;Turns power off from the printer