# G-code

## Introduction

G-code is the instruction set generated by the slicer which tells the printer what to do.

The AON-M2 runs using a firmware based off of the popular Marlin firmware project, and many of the G-code commands are similar in functionality, but with subtle yet important differences. Please refer to this manual for all G-code commands to be run on the M2.

While it is not necessary to be familiar with the intricacies of G-code for day-to-day usage, the aspiring power user will find it invaluable to develop a solid grasp of the fundamentals for developmental work, detailed optimization, or advanced troubleshooting.

## G-code Cheat Sheet

The most frequently used G-code commands are listed below.

G-code input is case-sensitive. Make sure to capitalize all letters.

G-code Description
G1 Linear Move/Extrude
G28 Home Axes
G29 Probe Bed
M104 Set Hotend Temperature
M140 Set Bed Temperature
M500 Save to EEPROM
M501 Restore from EEPROM
M502 Reset EEPROM

## Detailed Reference

### G commands

#### G0/G1 Linear Move

Performs a linear move between two points at a certain speed while extruding material.

Parameters

G1 [Xnnn] [Ynnn] [Znnn] [Ennn] [Fnnn]


[Xnnn] where nnn is a co-ordinate point on the X axis.

[Ynnn] where nnn is a co-ordinate point on the Y axis.

[Znnn] where nnn is a co-ordinate point on the Z axis.

[Ennn] where nnn is a value in mm determining how many mm of filament to extrude during the movement.

[Fnnn] where nnn is the speed of movement in mm/min.

Examples

G1 X50.2 Y10.7 E2.6 F1800 move to XY co-ordinate (50.2,10.7) in a straight line at 1800mm/min velocity while extruding 2.6mm of filament.

#### G28 Home Axes

Homes a specified axes or all axes.

Parameters

G28 [X] [Y] [Z]


Examples

G28 X Y Homes X and Y axes.

G28 Home all axes.

#### G29 Auto Bed Leveling

Initiates auto bed leveling with the nozzle probe. Requires G28 beforehand. This will probe the bed with a 5x5 grid, then move the active tool to the front corner of it's respective home side of the bed, i.e. when T0 is selected, it will move to the front left of the bed, and when T1 is selected, it will move to the front right of the bed.

After the probing process is complete, you should always verify that the nozzle is not making firm contact with the bed or depressing the probe mechanism. Adjustments should be made using M290.

Parameters

G29


#### G90 Absolute Positioning

Sets G-code interpretation to absolute position mode where positions are given as absolute values in co-ordinate space.

Parameters

G90


#### G91 Relative Positioning

Sets G-code interpretation to relative position mode where the next position is calculated relative to the last known position in co-ordinate space.

Parameters

G91


#### G92 Set Position

Manually sets the current position to the values specified by this command. Homing (G28) and probing (G29) will invalidate any set values.

!!! warning Only use this feature if you absolutely know what you are doing!

Parameters

G92 [Ennn] [Xnnn] [Ynnn] [Znnn]


[Ennn] where nnn is the extruder position, in mm

[Xnnn] where nnn is the X position, in mm

[Ynnn] where nnn is the Y position, in mm

[Znnn] where nnn is the Z position, in mm

Examples

G92 X50 Y50 Z1 sets the current known position to X=50, Y=50, Z=1 regardless of the actual physical location of the axes.

Changes the active toolhead. This will move the initial toolhead back to its parked position, and enable the new toolhead mesh and Z offset.

Parameters

[Tx]


[Tx] where x is an index between 0 or 1 corresponding to the desired tool.

Examples

T1 changes the active toolhead to T1 (right extruder). If the active toolhead is already T1, does nothing.

### M commands

#### M0 Stop

Pauses the printer and waits for user input, or pauses for a fixed period of time.

Parameters

M0 [Snnn]


[Snnn] where nnn denotes the pause time length in seconds.

Examples

M0 causes the printer to stop and wait until an M108 command is sent.

M0 S5 will cause the printer to stop for 5 seconds

#### M82 Set E to Absolute

Overrides G91 to set just the extruder into absolute co-ordinates mode. If used, ensure that it is disabled after use to avoid unintended retractions.

Parameters

M82


Examples

G91 ;sets all axes to relative mode
M82 ;sets E to absolute mode, all other axes remain in relative mode


#### M83 Set E to Relative

Overrides G90 to set just the extruder into relative co-ordinates mode.

Parameters

M83


Examples

G90 ;sets all axes to absolute mode
M83 ;sets E to relative mode, all other axes remain in absolute mode


#### M92 Set Steps Per mm

Sets the value of motor steps to be sent per mm of travel.

Note

The steps-per-mm value for the movement axes (XYZ) are determined by the hardware and should not be modified. Only to be used for recalibrating the Extruder axes. Extruder flow adjustment is preferably done through the slicer settings.

Parameters

M92 [Ennn] [Tx] [Xnnn] [Ynnn] [Znnn]


[Ennn] where nnn is the steps-per-mm for the extruder axis. 640 by default on the M2.

[Tx] where x can be 0 or 1 to set independent steps-per-mm for each toolhead.

[Xnnn] where nnn is the steps-per-mm for the X axis. 40 by default on the M2.

[Ynnn] where nnn is the steps-per-mm for the Y axis. 40 by default on the M2.

[Znnn] where nnn is the steps-per-mm for the Z axis. 400 by default on the M2.

Examples

M92 E645 T1 sets the T1 extruder steps-per-mm to 645.

#### M104 Set Hot End Temperature

Sets the hot end/chamber target temperature and continues to the next command.

Parameters

M104 [Tx] [Snnn]


[Tx] where x is 0 (T0), 1 (T1), or 2 (Chamber Heater)

[Snnn] where nnn is the target temperature in °C.

Examples

M104 T1 S250 Set T1 to 250°C

M104 T2 S120 Set chamber temperature to 120°C

#### M105 Report Temperatures

Report all temperatures.

Parameters

M105


Examples

M105 returns temperature values for all sensors (T0, T1, chamber, bed)

#### M106 Set Fan Speeds

Turns on and set fan speeds via PWM.

Parameters

M106 [Px] [Snnn]


[Px] where x is an index of 0, 1, or 2. The M2 only has a chamber fan, accessible as index 2.

[Snnn] where nnn is a value between 0-255 for PWM.

Examples

M106 P2 S255 turn chamber heater fan on to full power.

#### M107 Turn Fan Off

Turns fans off.

Parameters

M107 [Px]


[Px] where x is an index of 0, 1, or 2. The M2 only has a chamber fan, accessible as index 2.

Examples

M107 P2 turns chamber heater fans off.

#### M108 Break and Continue

Continues after a pause (M0) command. Can also override the waiting period for M109 and M190.

Parameters

M108


Examples

M0 ;pauses print job
M108 ;resumes print job


#### M109 Set Hot End Temperature and Wait

Sets the hot end/chamber target temperature and waits until target temperature is reached before continuing to the next command.

Parameters

M109 [Tx] [Snnn]


[Tx] where x is 0 (T0), 1 (T1), or 2 (Chamber Heater)

[Snnn] where nnn is the target temperature in °C.

Examples

M109 T1 S250 Set T1 to 250°C

M109 T2 S120 Set chamber temperature to 120°C

#### M111 Debug Mode

Parameters

M111 [Sx]


[Sx] where x is a binary summation of the desired debug bits from the following chart:

Bits Name Description
1 ECHO Echo all parser commands
2 INFO Extra info messages
4 ERRORS Extra error messages
8 DRYRUN Print without extrusion
16 COMM Communications
32 LEVELING Extra homing/probing info

Examples

M111 S35 turns on ECHO, INFO, and LEVELING (1+2+32=35)

#### M112 Emergency Stop

Virtual emergency stop. Immediately stops all movement, shuts down all heaters, stops further communication. Overrides any commands in the buffer, and will require a hard reboot once triggered.

Parameters

M112


Examples

M112 shuts down.

#### M114 Get Current Position

Gets the current position of the active toolhead.

Parameters

M114


Examples

M114 reports axes co-ordinates of the current active toolhead.

#### M115 Firmware Info

Outputs current firmware information.

Parameters

M115


Examples

M115 returns a string with information on current firmware.

#### M119 Endstop Status Report

Outputs current status of all endstops and probes - either open or triggered.

Parameters

M119


Examples

M119 returns set of strings reporting on Xmin, Xmax, Y1, Y2, Z1, Z2, Probe.

#### M140 Set Bed Temperature

Sets the bed temperature and continues the next command in the buffer.

Parameters

M140 [Snnn]


[Snnn] where nnn is the desired target temperature in °C.

Examples

M140 S150 sets the bed target to 150°C

#### M190 Set Bed Temperature and Wait

Sets the bed temperature and waits for target to be reached before continuing to the next command in the buffer.

Parameters

M190 [Snnn]


[Snnn] where nnn is the desired target temperature in °C.

Examples

M190 S150 sets the bed target to 150°C

#### M201 Set Maximum Printing Acceleration

Set global maximum acceleration rate for each movement axes in mm/s2

Parameters

M201 [Ennn] [Xnnn] [Ynnn] [Znnn]


[Ennn] where nnn is an integer value for acceleration in mm/s2. Default value is 10000.

[Xnnn] where nnn is an integer value for acceleration in mm/s2. Default value is 3000.

[Ynnn] where nnn is an integer value for acceleration in mm/s2. Default value is 3000.

[Znnn] where nnn is an integer value for acceleration in mm/s2. Default value is 100.

Examples

M201 X6000 Y6000 Z120 sets X/Y acceleration to 6000 mm/s2 and Z acceleration to 120 mm/s2.

#### M203 Set Maximum Feedrate

Set maximum travel/feedrate for each movement axes in mm/s.

Watch out!

The default values reach the upper limit of step generation rates on the microcontroller. Setting to higher values WILL result in print failure.

Parameters

M203 [Ennn] [Xnnn] [Ynnn] [Znnn]


[Ennn] where nnn is an integer value for max velocity in mm/s. Default value is 30.

[Xnnn] where nnn is an integer value for max velocity in mm/s. Default value is 499.

[Ynnn] where nnn is an integer value for max velocity in mm/s. Default value is 499.

[Znnn] where nnn is an integer value for max velocity in mm/s. Default value is 10.

Examples

M203 X350 Y350 sets the maximum travel speed of X/Y axes to 350mm/s.

#### M204 Set Acceleration

Sets acceleration values for different types of axes movements in mm/s2. Cannot exceed global maximums set by M201.

Parameters

M204 [Pnnn] [Rnnn] [Tnnn]


[Pnnn] where nnn is an integer value for printing moves acceleration in mm/s2. Default value is 3000.

[Rnnn] where nnn is an integer value for retraction moves acceleration in mm/s2. Default value is 3000.

[Tnnn] where nnn is an integer value for travel moves acceleration in mm/s2. Default value is 3000.

Examples

M204 P1500 T2500 sets acceleration during printing moves to 1500 and during travel moves to 2500.

Parameters

M205 [Bnnn] [Ennn] [Snnn] [Tnnn] [Xnnn] [Ynnn] [Znnn]


[Bnnn] where nnn is the minimum allowable print segment time in microseconds.

[Ennn] where nnn is the allowable instantaneous change in velocity for the Extruder in mm/s.

[Snnn] where nnn is the minimum allowable travel rate for printing moves in mm/min.

[Tnnn] where nnn is the minimum allowable travel rate for travel moves in mm/min.

[Xnnn] where nnn is the allowable instantaneous change in velocity for the X axis in mm/s.

[Ynnn] where nnn is the allowable instantaneous change in velocity for the Y axis in mm/s.

[Znnn] where nnn is the allowable instantaneous change in velocity for the Z axis in mm/s.

#### M206 Set Home Offsets

Applies an offset to the homed zero positions to effectively shift the build area in co-ordinate space.

Parameters

M206 [Xnnn] [Ynnn] [Znnn]


[Xnnn] where nnn is a value in mm.

[Ynnn] where nnn is a value in mm.

[Znnn] where nnn is a value in mm.

Examples

M206 X10 shifts the build area 10mm to the left.

M206 Z0.1 increases gap between nozzle and bed by 0.1mm.

Adjusts the dual extruder offset calibration.

Parameters

M218 [T1] [Xnnn] [Ynnn] [Znnn]


[Xnnn] where nnn is the X offset of T1 relative to T0 in mm. Default is 615.

[Ynnn] where nnn is the Y offset of T1 relative to T0 in mm. Default is 0.

[Znnn] where nnn is the Z offset of T1 relative to T0 in mm. Default is 0.

Examples

M218 T1 X605 Y-0.2 Z0.1 compensates for T1 that prints 10mm too far to the left, 0.2mm too close towards the front, and 0.1mm too far from the bed.

#### M220 Feedrate Override

During a print, overrides the XYZ axes movement speed by a percentage value.

Parameters

M220 [Snnn]


[Snnn] where nnn is a percentage value between 0-200%

Examples

M220 S125 increases print speed by 25%.

#### M221 Flowrate Override

During a print, overrides the extruder flow rate by a percentage value.

Parameters

M221 [Snnn]


[Snnn] where nnn is a percentage value between 0-200%

Examples

M221 S95 decreases material flow rate by 5%.

Allows for micro-adjustments of toolhead Z offset position. This should be used to calibrate the tool position after probing the bed and is equivalent to "touching off" in machining processes.

Parameters

M290 [Znnn]


[Znnn] where nnn is a value in mm to shift the toolhead location by in the Z axis.

Examples

M290 Z-0.1 decreases the nozzle-to-bed distance by 0.1mm.

#### M301 Set Hotend PID

Sets PID values for the hot ends and chamber heater. Obtain PID values from M303 and set using this command. Save with M500.

Parameters

M301 [Ex] [Pnnn] [Innn] [Dnnn]


[Ex] where x is an index of 0 (T0), 1 (T1), or 2 (chamber heater)

[Pnnn] where nnn is the proportional term of the PID.

[Innn] where nnn is the integral term of the PID.

[Dnnn] where nnn is the derivative term of the PID.

Examples

M301 E0 P15 I1 D50 sets the T0 PID to 15, 1, 50.

#### M303 PID Autotune

Automatically determines the appropriate PID values using the Ziegler-Nichols tuning method. Optionally, automatically applies PID values without the use of M301.

Parameters

M303 [Cnnn] [Ex] [Snnn] [U]


[Cnn] where nnn is an integer value denoting the number of heating/cooling cycles

[Ex] where x is an index of -1 (Bed), 0 (T0), 1 (T1), or 2 (Chamber)

[Snnn] where nnn is the set point around which to perform the tuning.

[U] optional - automatically applies the PID values to the heater indexed by [Ex]. Save with M500.

Examples

M303 C5 E0 S300 U run PID tuning on T0 around 300°C cycling 5 times and apply PID values immediately.

#### M304 Set Bed PID

The counterpart to M301 to set PID values for the bed determined by M303.

Parameters

M304 [Pnnn] [Innn] [Dnnn]


[Pnnn] where nnn is the proportional term of the PID.

[Innn] where nnn is the integral term of the PID.

[Dnnn] where nnn is the derivative term of the PID.

Examples

M304 P10 I0.1 D300 sets bed PID to 10, 0.1, 300.

#### M500 Save to EEPROM

Saves variables to EEPROM (programmable read-only memory)

Parameters

M500


#### M501 Restore from EEPROM

Restores variable values previously stored in EEPROM.

Parameters

M501


#### M502 Reset EEPROM

Clears EEPROM and restores default values from the firmware.

Parameters

M502


#### M503 Report EEPROM Values

Outputs all variables and values stored in EEPROM.

Parameters

M503


#### M605 Independent Dual Extruder Control

Switches control mode for the independent dual extruders.

Parameters

M605 [Sx]


[Sx] where x is an index of 1 (dual extrusion mode) or 2 (duplication mode)

Examples

M605 S2 sets the printer to print in duplication mode.

#### M666 Endstop Calibration

Sets the offset between two endstops on the same movement axes to account for skew/squarness.

Parameters

M666 [Ynnn] [Znnn]


[Ynnn] where nnn is a value in mm representing the offset of the second Y endstop (right hand side) relative to to the first.

[Znnn] where nnn is a value in mm representing the offset of the second Z endstop (right hand side) relative to to the first.

Examples

M666 Z0.1 after the Z axis homes, the right hand side Z motor will lower by 0.1mm.

last updated: 7/31/18