3D printer m codes
M Codes - ReplicatorG
Main
- About
- Download
- Installation
- Usage
- Drivers
Reference
- Primer
- G Codes
- M Codes
- Generators
Development
- Development Mailing List
- Building ReplicatorG
- Reporting Bugs
Friends
- RepRap
- Arduino
- Processing
- NYC Resistor
- Thingiverse
- MakerBot Industries
Coded by:
- Zach Hoeken
- Marius Kintel
- Adam Mayer
- Matt Mets
M Codes
This page presents a summary of M codes used by ReplicatorG. M codes are very protean and flexible; many are RepRap or MakerBot specific.
The following extra M-Codes were defined for RepRap:
- M101 Extruder on, fwd
- M102 Extruder on, reverse
- M103 Extruder off
- M104 Snn set temperature in degrees Celsius
- M105 get extruder temperature
- M106 turn fan on
- M107 turn fan off
- M108 Set Extruder's Max Speed (Rnnn = RPM, Pnnn = PWM)
- M109 Snnn set build platform temperature in degrees Celsuis
- M110 Snnn set chamber temperature in degrees Celsius
- M120, M121, M122 Snnn set the PID gain for the temperature regulator (not currently supported by ReplicatorG)
- M123, M124 Snnn set iMax and iMin windup guard for the PID controller (not currently supported by ReplicatorG)
- M128 get position
- M129 get range (not currently supported by ReplicatorG)
- M130 set range (not currently supported by ReplicatorG)
- M200 reset driver
- M202 clear buffer (not currently supported by ReplicatorG)
- M300 Snnn set servo 1 position
- M301 Snnn set servo 2 position
Other M codes understood by ReplicatorG
- M0 Unconditional Halt (not supported on SD)
- M1 Optional Halt (not supported on SD)
- M2 End program
- M3 spindle on, CW
- M4 spindle on, CCW
- M5 spindle off
- M6 Tool change. This code waits until the toolhead is ready before proceeding. This is often used to wait for a toolhead to reach the its set temperature before beginning a print. ReplicatorG also supports giving a timeout with M6 P<secs>.
- M7 coolant A on (flood coolant)
- M8 cooland B on (mist coolant)
- M9 all coolants off
- M10 close clamp
- M11 open clamp
- M13 spindle CW and coolant A on
- M14 spindle CCW and coolant A on
- M17 enable motor(s)
- M18 disable motor(s)
- M21 open collet
- M22 close collet
- M30 program rewind
- M40-M46 change gear ratio (0 - 6)
- M50 read spindle speed
- M70 Display message on machine, with optional timeout specified by P-code in seconds
- Ex.: M70 P10 (Display this text for ten seconds)
- M71 Pause activity and display message, resuming build on button push. Optional timeout specified by P-code in seconds. If timeout is specified and no button is pushed, machine should shut down or reset.
- Ex.: M71 (Please insert motor into assembly and push a button.)
- Ex.: M71 P20 (Machine will reset in twenty seconds!)
- M72 Play a song or tone defined by the machine, by a P-code specifying a song type. Default songs are Error Sound (P0), a Ta-da sound (P1), and a warning sound (P2). all other sounds are user or machine specific, with P2 the default for unknown sounds.
- Ex M72 P1 (Machine will play a 'TaDa' song!)
- M73 Manually set build percentage. Valid P values are 0 to 100, values over 100 are rounded down to 100
- Ex M73 P10 (Set build percent to 10% )
- M126 valve open (acceleration on for subsequent instructions in the Jetty Firmware)
- M127 valve close (acceleration off for subsequent instructions in the Jetty Firmware)
- M310 (filepath) logging (see below)
- M311 stop logging (see below)
- M312 (message) log message (see below)
- M320 acceleration on for subsequent instructions (Replicator/MightyBoard)
- M321 acceleration off for subsequent instructions (Replicator/MightyBoard)
- M322 Znn Pause@ZPos (Sailfish Only)
Logging in ReplicatorG
ReplicatorG 26 and later will feature basic logging functionality through M codes. You can experiment with this feature by checking out the "temperature_log" branch in the git repository.
- M310 (FILE_PATH)
- Start logging to the file specified by "FILE_PATH". The parenthesis are necessary!
- M311
- Stop logging
- M312 (MESSAGE)
- Log the message text to the logging file.
Status messages will be logged to the file once logging is turned on; this means you can log temperature data. NB: you must turn on "monitor temperature" in your preferences to monitor the toolheads! The status of all configured toolheads will be dumped to the log file at one second intervals.
Example:
(This will log 5 seconds of temperature data on all configured tools) M310 (test.log) M312 (--Start logging--) M104 S225 T0 (set extruder temperature) G04 P5000 M104 S0 T0 M312 (--End logging--) M311
Other examples
(run toolhead 0 for 5 seconds)
G21 (set units to mm)
G90 (set positioning to absolute)
M108 T0 R1. 98 (set extruder speed)
M103 T0 (Make sure extruder is off)
M104 S225 T0 (set extruder temperature)
M6 T0 (wait for toolhead parts, nozzle, HBP, etc., to reach temperature)
M101 T0 (Extruder on, forward)
G04 P5000 (Wait t/1000 seconds)
M103 T0 (Extruder off)
M104 S0 T0 (set extruder temperature)
(run toolhead 1 for 6 seconds)
M108 T1 R1.98 (set extruder speed)
M103 T1 (Make sure extruder is off)
M104 S225 T1 (set extruder temperature)
M6 T1 (wait for toolhead parts, nozzle, HBP, etc., to reach temperature)
M101 T1 (Extruder on, forward)
G04 P6000 (Wait t/1000 seconds)
M103 T1 (Extruder off)
M104 S0 T1 (set extruder temperature)
M codes used by the Jetty Firmware but not understood by ReplicatorG
The following M codes are used by the Jetty Firmware and are documented at Jetty M Codes. With the exception of M126, M127 and M200, they are not presently supported by the standard ReplicatorG releases. Versions of ReplicatorG which understand these M codes are available as part of Thing 17855 at Thingiverse. A number of these M codes are also supported by the Marlin firmware.
- M126 use acceleration for subsequent instructions
- M127 disable acceleration for subsequent instructions
- M201 set maximum rates of acceleration/deceleration
- M203 set maximum feed rates
- M204 set default rates of acceleration
- M205 set minimum feed rates and planner speed
- M206 set extruded noodle diameter, extruder maximum reverse feed rate, extruder deprime, slowdown limit, and direction of extruder feed
- M207 set JKN Advance parameters K and K2
- M208 set extruder steps per millimeter
- M209 turn acceleration planner on or off; enable or disable override of gcode temperature settings
- M215 set steps per millimeter for each axis
- M216 set maximum speed changes for each axis
- M200 reset (to pick up changes)
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.
Gcode | Marlin Firmware
1.0.0-beta motion
Add a straight line movement to the planner
1.0.0-beta motion ARC_SUPPORT
Add an arc or circle movement to the planner
1.0.0-beta motion
Pause the planner
1.1.0 motion
Cubic B-spline with XYE destination and IJPQ offsets
motion DIRECT_STEPPING
Perform a direct, uninterpolated, and non-kinematic synchronized move
1.0.0-beta motion FWRETRACT
Retract the filament
1. 0.0-beta motion FWRETRACT
Recover the filament with firmware-based retract.
1.1.0 nozzle NOZZLE_CLEAN_FEATURE
Perform the nozzle cleaning procedure.
geometry CNC_WORKSPACE_PLANES
Select CNC workspace plane
1.1.0 units INCH_MODE_SUPPORT
Set Units to Inches.
1.1.0 units INCH_MODE_SUPPORT
Set Units to Millimeters.
1.1.0 calibration G26_MESH_VALIDATION
Test the mesh and adjust.
1.1.0 nozzle NOZZLE_PARK_FEATURE
Park the current toolhead
calibration
Auto home one or more axes.
calibration AUTO_BED_LEVELING_3POINT
Probe the bed and enable leveling compensation.
calibration AUTO_BED_LEVELING_BILINEAR
Probe the bed and enable leveling compensation.
calibration AUTO_BED_LEVELING_LINEAR
Probe the bed and enable leveling compensation.
calibration MESH_BED_LEVELING
Measure Z heights in a grid, enable leveling compensation
calibration AUTO_BED_LEVELING_UBL
Probe the bed and enable leveling compensation.
calibration AUTO_BED_LEVELING_(3POINT|LINEAR|BILINEAR|UBL)|MESH_BED_LEVELING
Probe the bed and enable leveling compensation
1. 0.0-beta calibration HAS_BED_PROBE
Probe bed at current XY location
1.0.0-beta calibration Z_PROBE_SLED
Dock the Z probe sled.
1.0.0-beta calibration Z_PROBE_SLED
Undock the Z probe sled.
1.1.0 calibrationdelta DELTA_AUTO_CALIBRATION
Calibrate various Delta parameters
2.0.4 calibration MECHANICAL_GANTRY_CALIBRATION
Modern replacement for Průša's TMC_Z_CALIBRATION
calibration Z_STEPPER_AUTO_ALIGN
Align multiple Z steppers using a bed probe
calibration ASSISTED_TRAMMING
Run a procedure to tram the bed
1. 1.0 calibration G38_PROBE_TARGET
Probe towards (or away from) a workpiece
1.1.2 calibration HAS_MESH
Move to a specific point in the leveling mesh
geometry CNC_COORDINATE_SYSTEMS
Apply native workspace to the current move.
geometry CNC_COORDINATE_SYSTEMS
Select a workspace coordinate system
coordinates
Save current position to specified slot
coordinates
Return to saved position of specified slot
calibration PROBE_TEMP_COMPENSATION
Calibrate probe temperature compensation
motion GCODE_MOTION_MODES
Cancel the current motion mode
1. 0.0-beta units
Set the interpreter to absolute positions
1.0.0-beta units
Set the interpreter to relative positions
1.0.0-beta motion
Set the current position of one or more axes.
calibration CALIBRATION_GCODE
Use a conductive object to calibrate XYZ backlash
1.0.0-beta motion
Stop and wait for user
1.1.2 control SPINDLE_LASER_ENABLE
Set the spindle CW speed or laser power
1.1.2 control SPINDLE_LASER_ENABLE
Set the spindle CCW speed or laser power
1. 1.2 control SPINDLE_LASER_ENABLE
Turn off spindle or laser
control
Turn mist or flood coolant on / off
2.0.8 control AIR_EVACUATION
Enable and disable the Cutter Vacuum or Laser Blower Motor.
2.0.0 safety EXPECTED_PRINTER_CHECK
Prevent G-code usage on the wrong machine
control
Enable steppers
control
Disable steppers (same as M84).
sdcard SDSUPPORT
List the contents of the SD Card.
sdcard SDSUPPORT
Attempt to detect an SD card in the slot.
sdcard SDSUPPORT
Simulate ejection of the SD card
sdcard SDSUPPORT
Select an SD file to be executed
sdcard SDSUPPORT
Start or resume a file selected with [`M23`](/docs/gcode/M023. html)
sdcard SDSUPPORT
Pause printing from the SD card
sdcard SDSUPPORT
Set the SD read position
sdcard SDSUPPORT
Print SD progress to serial
sdcard SDSUPPORT
Start writing to a file on the SD card
sdcard SDSUPPORT
Stop writing the file, end logging.
sdcard
Delete a specified file from SD.
printjob
Report the current print time.
sdcard SDSUPPORT
Begin an SD print from a file.
1. 0.2 sdcard SDSUPPORT LONG_FILENAME_HOST_SUPPORT
Convert a short pathname to a long pathname.
1.1.0 sdcard SDSUPPORT SDCARD_SORT_ALPHA
Set SDCard file sorting options.
control
Set an analog or digital pin to a specified state.
debug PINS_DEBUGGING
Get information about pins.
debug PINS_DEBUGGING
Get information about pins.
calibration Z_MIN_PROBE_REPEATABILITY_TEST
Measure Z Probe repeatability.
1.1.7 lcd LCD_SET_PROGRESS_MANUALLY
Set current print progress percentage for LCD.
printjob
Start the print job timer.
printjob
Pause the print job timer.
printjob
Stop the print job timer.
printjob PRINTCOUNTER
Print statistics about print jobs.
control PSU_CONTROL
Turn on the power supply
control PSU_CONTROL
Turn off the power supply.
units
Set E to absolute positioning.
units
Set E to relative positioning.
control
Set the inactivity timeout.
motion
Set the number of steps-per-mm, per-inch, or per-degree
debug M100_FREE_MEMORY_WATCHER
Observe memory used by code
2. 1.1 calibration BD_SENSOR
Set the state or trigger distance (in 0.1mm units) for the Bed Distance Sensor.
thermal
Set a new target hot end temperature.
thermal
Send a temperature report to the host.
thermal EXTRA_FAN_SPEED
Turn on the fan and set its speed
thermal
Turn off a fan
control
Break out of the current waiting loop
thermal
Wait for the hot end to reach its target.
hosts
Set the current line number.
hosts
Report and optionally set the debug flags.
safety
Shut everything down and halt the machine.
hosts HOST_KEEPALIVE_FEATURE
Get or set the host keepalive interval.
hosts
Report the current tool position to the host.
hosts
Print the firmware info and capabilities.
lcd ULTRA_LCD
Set the message line on the LCD.
hosts
Send text to serial
debug
Report endstop and probe states to the host.
control
Enable endstops and keep them enabled when not homing.
control
Disable endstops and keep them enabled when not homing.
1.1.7 debug HAS_TRINAMIC_CONFIG
Get TMC Debug Info
control
Report fan speeds from tachometers
nozzle PARK_HEAD_ON_PAUSE
Save current position and move to filament change position.
baricuda BARICUDA
Open the valve for Baricuda 1.
baricuda BARICUDA
Close the valve for Baricuda 1.
baricuda BARICUDA
Open the valve for Baricuda 2.
baricuda BARICUDA
Close the valve for Baricuda 2.
thermal
Set a new target bed temperature.
thermal
Set a new target chamber temperature.
2.0.8 thermal TEMP_SENSOR_COOLER TEMP_COOLER_PIN COOLER_PIN LASER_FEATURE
Set a new target laser coolant temperature.
lcd NEWPANEL
Set material presets in the LCD menu.
units TEMPERATURE_UNITS_SUPPORT
Set temperature units to Celsius, Fahrenheit, or Kelvin.
lcd BLINKM|RGB_LED|RGBW_LED|NEOPIXEL_LED|PCA9632
Set the color of the RGB(W) LED, backlight, or LED strip.
2.0.8.1 hosts AUTO_REPORT_POSITION
Periodically auto-report position to serial
hosts AUTO_REPORT_TEMPERATURES EXTENDED_CAPABILITIES_REPORT
Auto-report temperatures to host periodically.
mixing MIXING_EXTRUDER
Set a single mix factor for a mixing extruder.
mixing MIXING_EXTRUDER MIXING_VIRTUAL_TOOLS
Save the current mix as a virtual tool.
mixing MIXING_EXTRUDER DIRECT_MIXING_IN_G1
Set all mix factors for the mixing extruder.
2.0.0 mixing MIXING_EXTRUDER GRADIENT_MIX
Set a Gradient Mix
thermal
Wait for the bed to reach target temperature.
thermal
Wait for the chamber to reach target temperature.
2.0.6.2 calibration PROBE_TEMP_COMPENSATION
Wait for the probe temperature sensor to reach a target
2. 0.8 thermal TEMP_SENSOR_COOLER TEMP_COOLER_PIN COOLER_PIN LASER_FEATURE
Set a new target laser coolant temperature.
motion
Set the diameter for volumetric extrusion.
motion
Set acceleration and frequency limits for print moves.
motion
Set maximum feedrate for one or more axes.
motion
Set the starting acceleration for moves by type.
motion
Set some advanced settings related to movement.
motion HAS_HOME_OFFSET
Apply a persistent offset
motion FWRETRACT
Set options for firmware-based retraction.
motion FWRETRACT
Firmware-retraction recover settings.
motion FWRETRACT
Enable / disable auto-retraction.
motion (MIN|MAX)_SOFTWARE_ENDSTOPS
Set and/or get the software endstops state
2.0.0 calibration EXTRUDERS > 1
Set length and speed for filament swapping
calibration EXTRUDERS>1
Set the offset of a hotend (from hotend 0).
motion
Set the global feedrate percentage.
motion
Set the flow percentage, which applies to all E moves.
control
Wait for a pin to have a given state.
extras PHOTO_GCODE
Trigger a camera shutter
lcd HAS_LCD_CONTRAST
Set and/or get the LCD contrast.
2.0.9.4 lcd DISPLAY_SLEEP_MINUTES or LCD_BACKLIGHT_TIMEOUT
Set and/or get the LCD Sleep Timeout.
2.0.9.2 lcd HAS_LCD_BRIGHTNESS
Set and/or get the LCD brightness.
i2c EXPERIMENTAL_I2CBUS
Send data to the I2C bus.
i2c EXPERIMENTAL_I2CBUS
Request and echo bytes from the I2C bus.
servos NUM_SERVOS>0
Set or get a servo position.
2. 0.0 servos EDITABLE_SERVO_ANGLES
Set servo deploy and/or stow angles
2.0.9.2 servos SERVO_DETACH_GCODE
Detach a servo until its next move
1.1.7 calibration BABYSTEPPING
Babystep one or more axes
lcd SPEAKER
Play a single tone, buzz, or beep.
thermal PIDTEMP
Set PID values for a hotend.
thermal PREVENT_COLD_EXTRUSION
Set minimum extrusion temperature, allow cold extrusion.
thermal PIDTEMP|PIDTEMPBED
Auto-tune the PID system to find stable values.
thermal PIDTEMPBED
Set PID values for the heated bed.
thermal temperature sensor `1000`
Set (or report) custom thermistor parameters
2.0.9.4 thermal MPCTEMP
Set MPC values for a hotend.
control HAS_MICROSTEPS
Set micro-stepping for drivers that support it
control HAS_MICROSTEPS
Directly set the micro-stepping pins
control CASE_LIGHT_PIN
Turn the case light on or off, set brightness
control MORGAN_SCARA
Move to Theta A
control MORGAN_SCARA
Move to Theta-B
control MORGAN_SCARA
Move to Psi-A
control MORGAN_SCARA
Move to Psi-B
control MORGAN_SCARA
Move to Psi-C
none EXT_SOLENOID
Activate
none EXT_SOLENOID
Deactivate all extruder solenoids
motion
Wait for all moves to finish
calibration HAS_BED_PROBE
Deploy the bed probe
calibration HAS_BED_PROBE
Stow the bed probe
control PRUSA_MMU2
Set filament type for Multi-Material Unit 2. 0
control FILAMENT_WIDTH_SENSOR
Set the nominal diameter for filament width sensor auto-flow
control FILAMENT_WIDTH_SENSOR
Enable filament width sensor flow control
control FILAMENT_WIDTH_SENSOR
Disable filament width sensor flow control
control FILAMENT_WIDTH_SENSOR
Report the measured filament width
motion
Stop all steppers instantly
2.0.0 control FILAMENT_RUNOUT_SENSOR
Get/set filament runout detection parameters
2.0.0 control POWER_LOSS_RECOVERY
Enable / disable power-loss recovery
motion AUTO_BED_LEVELING_(3POINT|LINEAR|BILINEAR|UBL)|MESH_BED_LEVELING
Get and/or set bed leveling state and parameters
motion AUTO_BED_LEVELING_(BILINEAR|UBL)|MESH_BED_LEVELING
Set a single mesh Z height
2. 0.4 calibration Z_STEPPER_AUTO_ALIGN
Set a Z motor position for G34 Auto-Alignment
2.0.9.4 calibration X_AXIS_TWIST_COMPENSATION
Modify, reset, and report X-Axis Twist Compensation data
calibration BACKLASH_COMPENSATION BACKLASH_GCODE
Enable and tune backlash compensation
motion HAS_HOME_OFFSET
Set home offsets based on current position
thermal either POWER_MONITOR_CURRENT or POWER_MONITOR_VOLTAGE
Read and display current (A), voltage (V), and power (W)
sdcard CANCEL_OBJECTS
Identify and cancel objects
eeprom EEPROM_SETTINGS
Save settings to EEPROM.
eeprom EEPROM_SETTINGS
Restore settings from EEPROM.
eeprom
Restore all settings to factory defaults.
eeprom
Report all settings that may be saved to EEPROM.
eeprom EEPROM_SETTINGS
Validate the contents of the EEPROM.
2.0.6.1 security PASSWORD_FEATURE
Lock the machine if it has a passcode
2.0.6.1 security PASSWORD_FEATURE
Unlock the machine if it has a passcode
2.0.6.1 security PASSWORD_FEATURE
Set a numeric passcode for locking the machine
2. 0.0 sdcard SDSUPPORT
Abort an SD print started with [`M24`](/docs/gcode/M024.html)
sdcard SDSUPPORT SD_ABORT_ON_ENDSTOP_HIT
Abort SD printing when an endstop is triggered.
2.0.0 trinamic TMC2130|TMC2208|TMC2209
Toggle stealthChop
2.0.0 hosts BAUD_RATE_GCODE
Change the serial baud rate
1.1.0 filament ADVANCED_PAUSE_FEATURE
Automatically change filament
1.1.0 filament ADVANCED_PAUSE_FEATURE
Configure automatic filament change parameters
control MULTI_NOZZLE_DUPLICATION|DUAL_X_CARRIAGE
Set the behavior mode for a multiple nozzle setup
none MORGAN_SCARA|MAKERARM_SCARA
Set SCARA geometry values
none DELTA
Set delta geometry values
calibration (X|Y|Z)_DUAL_ENDSTOPS
Set dual endstop offsets
calibration DELTA
Set Delta endstop adjustments
2. 0.2 control DUET_SMART_EFFECTOR
Set Duet Smart Effector sensitivity
control NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE FILAMENT_LOAD_UNLOAD_GCODES
Load filament
control NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE FILAMENT_LOAD_UNLOAD_GCODES
Unload filament
2.0.5.2 thermal CONTROLLER_FAN_EDITABLE
Set or report controller fan settings
debug MAX7219_DEBUG
Control Max7219 Segmented LEDs
2.0.8 none GCODE_REPEAT_MARKERS
Set or go to a marker for looping G-code
GCODE_MACROS
Set/execute one of ten G-code macros
none HAS_BED_PROBE
Set the Z probe XYZ offset from nozzle
calibration
Misalignment in the XYZ axes.
1.0.0-beta encoder I2C_POSITION_ENCODERS
I2C position encoders for closed loop control
calibration PROBE_TEMP_COMPENSATION
Configure probe temperature compensation
hosts HOST_PROMPT_SUPPORT
Handle Host prompt responses
control LIN_ADVANCE
Get and set Linear Advance K value
none TMC2130|TMC2208|TMC2660|L64xx
Set the motor current (in milliamps)
control DIGIPOTSS_PIN|HAS_MOTOR_CURRENT_PWM|DIGIPOT_I2C|DAC_STEPPER_CURRENT
Set motor current via digital trimpot
control DAC_STEPPER_CURRENT|DIGIPOTSS_PIN
Set a digital trimpot directly
control DAC_STEPPER_CURRENT
Report DAC current values to host
control DAC_STEPPER_CURRENT
Commit digipot/DAC value to external EEPROM
trinamic TMC2130|TMC2208|TMC2209|TMC2660 MONITOR_DRIVER_STATUS
Driver overtemperature pre-warn condition
control TMC2130|TMC2208|TMC2209|TMC2660 MONITOR_DRIVER_STATUS
Clear overtemperature pre-warn condition flag
control TMC2130|TMC2208|TMC2209 HYBRID_THRESHOLD
TMC driver switching to spreadCycle
trinamic SENSORLESS_HOMING
Set sensorless homing sensitivity
control TMC2130 TMC_Z_CALIBRATION
Align ends of the Z axis and test torque
L6474 MONITOR_L6470_DRIVER_STATUS
Find L6474 drive level (KVAL_HOLD) threshold
L6474 MONITOR_L6470_DRIVER_STATUS
Find L6474 minimum current thresholds
L6474 MONITOR_L6470_DRIVER_STATUS
Find L6474 speed threshold
2. 0.9.4 trinamic TMC2130|TMC2160|TMC2208|TMC2209|TMC2660|TMC5130|TMC5160
Set Chopper Timing values for TMC stepper drivers
sdcard
Log serial input to an SD file
calibration MAGNETIC_PARKING_EXTRUDER
Set / report Magnetic Parking Extruder settings
sdcard HAS_SPI_FLASH SDSUPPORT MARLIN_DEV_MODE
load or back up SPI Flash and SD
calibration TOUCH_SCREEN_CALIBRATION
Touch screen calibration for TFT display
2.0.0 control
Perform in-application firmware update
control
Return the machine to Running state
control
Switch to the specified tool
G-CODE in Russian for 3D printing (Mini-guide)
Often, for high-quality printing, and especially when selecting print parameters, it is necessary to be able to read and edit the G-code during calibration.
A commonplace example: setting your own values for the "Temperature Tower" or creating start and end blocks of codes in slicers for a specific printer.
On some sites (like reprap.org/wiki/G-code) on the Russian-language pages, the commands are only partially described in Russian, and the rest in English. On some domestic sites, the commands are translated into Russian, but some are given with errors - stupidly copy-paste a clumsy translation.
Tired of searching through different sites, trying to find the CORRECT description of a particular command and its parameters.
I made myself such a mini-reference book. I'll be glad if anyone else finds it useful.
I tried to describe the maximum number of commands used, except for very specific ones.
(Yes, special commands for deltas, for example, sorry, I consider them specific and not necessary for me)
However, most commands are supported by all printers and firmware.
Attention! Compliance of commands and parameters is checked only for Marlin firmware.
G-commands
G0(G1) Xnnn Ynnn Znnn Ennn Fnnn – movement.
G0 - fast idle
G1 - linear working travel
Xnnn, Ynnn, Znnn – coordinates.
Еnnn - amount of extruded material in mm (with negative values - retract).
Fnnn – travel speed in mm/min (this speed will be used until the next change).
G0 X12 (will move 12mm in X)
G0 F1500 (Set travel speed to 1500 mm/min.)
G1 X90.6 Y13.8 E22.4 (Move 90.6mm in X and 13.8mm in Y while extruding 22.4mm of material.)
G4 .
Pnnn - Timeout, in milliseconds
Snnn - Timeout in seconds.
"G4 S2" and "G4 P2000" - equivalent to
G10 - Plastic rollback (Retract)
Filament rollback according to M207 settings.
G11 - Plastic feed
Feed / reposition the head according to M208 settings.
G20 - Inch unit setting
G21 - Setting the units in millimeters
From now on, the reading will be in inches/millimeters.
G28 - Move to start ("home") until limit switches actuate
G28 – home on all axes.
G28 X Z - Move home only in X and Z axes
G29 - Create table curvature mesh (MESH_BED_LEVELING)
The command allows you to create a compensation (Z-height) grid and use it later when printing. The grid can be used repeatedly even after the printer is turned off.
After using the G28 command, the mesh created by the G29 command flies off.
It is necessary to save the rhinestone mesh after it has been created! To recall the grid from memory, use the M420 command.
Be sure to use G28 before using G29, otherwise the mesh will be incorrect.
Creating Mesh Bed Leveling manually (via commands):
1. Enter G29 S0 to start meshing.
2. Enter G29 S1 to set the first grid point.
3. Align the nozzle with paper (as usual).
4. Enter G29 S2 to save the value and jump to a new point
5. Repeat steps 3 and 4 until the creation procedure is completed.
6. Enter M500 to write the resulting mesh to EEPROM.
Creating Mesh Bed Leveling using the printer menu (the function must be active in the firmware):
1. Select Prepare followed by Auto home (aka G28 command).
2. Select Prepare and then Level Bed.
3. Wait for on-screen instructions to begin. Press the "twist" on the screen when the inscription "Click to Begin" appears. The head will go to the first grid point.
4. Use the thumbwheel to raise or lower the nozzle to align the nozzle with the paper. Same as when leveling the table. After you have achieved the desired gap between the nozzle and the piece of paper, press the "twist". The head will move to a new grid point.
5. Repeat step 4 until the program has passed all points.
6. When finished, enter the Control menu and select the Store memory item to save the created mesh to EEPROM.
To use the grid stored in EEPROM when printing, use the command
M420 S1 (See M420).
G90 - Setting absolute coordinates
All coordinates are absolute relative to the machine origin.
G91 - Set relative coordinates
All coordinates from now on become relative to the last position. Marlin translates all axes into relative coordinates, including the extruder.
G92 Xnnn Ynnn Znnn Ennn - Set position
This command can be used without any additional parameters.
G92 - reset all axis coordinates to zero.
Xnnn - new X coordinate
Ynnn - new Y coordinate
Znnn - new Z coordinate
Ennn - new extruder position
Example: G92 X10 E90
M-commands
M17 - Enable/Enable all stepper motors
M18 - Remove current from motors
Motors can be turned by hand. Command analog M84
M20 - List of files on SD card
M21 - SD card initialization
If the SD card is loaded when the printer is turned on, this will happen by default. The SD card must be initialized for other SD card functions to work.
M22 - Release SD card
The specified SD card will be released. On future (random) read attempts, a guaranteed error occurs. Useful before removing the SD card.
M23 - Select file on SD card
Example: M23 filename.gco
M24 - Start/continue printing from SD card
The printer will print from the file selected with the M23 command.
M25 - SD card print pause
M28 - Start writing to SD card
Example: M28 filename.gco.
A file is created on the SD card, designated as filename.gco (if the file exists, it is overwritten) and all subsequent commands to the printer are written to this file.
M29 - Stop writing to SD card
Example: M29 filename.gco
The file opened by the M28 command is closed and all subsequent commands are executed by the printer in normal mode.
M30 - Delete file from SD card
Example: M30 filename.gco. filename.gco will be deleted.
M32 - Select file and start printing from SD card
Example: M32 filename.gco.
Used for SD card printing and works the same as M23 and M24
M80 - Enable ATX Power Supply
Puts the ATX power supply into sleep mode. Does not work on electronics without sleep mode.
M81 - Turn off the ATX power supply
M82 - Set the extruder to absolute mode
M83 - Set extruder to relative mode
Allows extruder to be extruder in absolute/relative units
M84 SNNN X, Y, Z, E - transfer motors to the waiting mode of
SNNN - time per seconds.
If a timeout is specified with Snnn, this command simply sets the stepper motor inactivity timeout.
If no motors (X,Y,Z or E) are specified, this command immediately disables all.
If one or more axes are specified, this command disables the specified ones immediately. For example, "M84 S10" will put stepper motors into standby mode after 10 seconds of inactivity.
M92 Xnnn Ynnn Znnn Ennn - Set the number of steps per axis per unit
Ennn - steps per unit for extruder
Examples: M92 X87.489 Y87.489 Z87.489 or M92 E420
Allows you to set the number of steps per unit (usually mm) for motors. These values are replaced with the values from the firmware at power up unless written to the EEPROM see M500.
M104 Snnn - Set extruder temperature and DO NOT wait
Snnn - Set temperature
Example: M104 S190
Sets the temperature of the active extruder 190C and immediately returns control (that is, DOES NOT WAIT for the extruder to reach the set temperature). See also M109
M105 - Get Extruder Temperature
Gets the temperature of the active extruder and hot bed in degrees Celsius. The temperature is transmitted to the connected computer. The response sent to the computer might look like this: ok T:201 B:117
M106 Snnn - Turn on the fan blowing part
SNNN - fan rotation of fan from 0 to 255 (127 - 50% speed)
m107 - turn off the fan
m108 - cancel the heating 9000 9000 temperature set by M109 and M190, continues printing.
M109 Snnn - Set extruder temperature and wait
Sets the temperature in Celsius and waits for it to be reached. See also M104
M110 Nnnn - Set current line number
Nnnn - Line number
Example: M110 N123
In this example, the number of the current line 123 is set. Thus, it is expected that the next line after this command will be 124.
M112 - Emergency Stop
m114 - receipt of current positions 9
M115 - Get a firmware version
m119 - get the status of ends
m140 - set the temperature of the table and DO NOT wait
Example: M140 S65
Sets the table temperature to 65C and immediately returns control (ie DOES NOT WAIT for the table to reach the set temperature). See also M190
M190 - Set table temperature and wait
Sets the temperature in Celsius and WAITS to reach it. see M140
M200 Dnnn Tnnn - Set the REAL diameter of the filament rod.
Dnnn – diameter in mm.
Tnnn – extruder number. (can be omitted for single extruder printers)
Example: M200 D1.65
Used to calculate the actual extruded volume.
See M404 for rating setting.
M201 Xnnn Ynnn Znnn Ennn - Setting of the maximum accelerations (in mm/s in sq.)
for axes.
Ennn - accelerations in mm/s in sq. for the extruder.
Only one/two of the parameters can be used.
Example: M201 X1000 Y1000 Z100 E2000
Use M500 to store parameters in EEPROM
M202 - Setting the maximum acceleration for simple (idle) movement.
!Not used in Marlin! V mm/s in sq. Example: M202 X1000 Y1000
M203 Xnnn Ynnn Znnn Ennn - Setting the maximum speed (in mm/s)
Xnnn, Ynnn, Znnn - max speed for axes
Ennn - max extruder speed.
Only one/two of the parameters can be used.
Example: M203 X6000 Y6000 Z300 E10000
Use M500 to store parameters in EEPROM.
M204 Pnnn Rnnn Tnnn - Acceleration setting (in mm/sec. in sq.)
Pnnn - Printing acceleration
Rnnn – Retract Acceleration
Tnnn - Accelerations during idle movements
Only one/two of the parameters can be used.
Example: M204 P800 T3000 R9000
Use M500 to store parameters in EEPROM.
M205 Xnnn, Znnn, Ennn - Setting the maximum jerk (jerk) (mm / s)
Xnnn - jerk along the X and Y axes. (Jerks are the same along these axes)
Znnn - jerk along the Z axis.
Ennn - extruder jerk.
Only one/two of the parameters can be used.
Example: M205 X30 Z5 - Set jerk X/Y = 30, Z jerk = 5.
Use M500 to store parameters in EEPROM.
М206 Xnnn, Ynnn, Znnn - Set offsets relative to limit switches (zero)
Similar to G92 command, but these offsets can be written to EEPROM see M500.
Example: M206 X10.0 Y10.0 Z-0.4
M207 Snnn Fnnn Znnn - Set retract parameters (bar retraction)
Snnn - positive retract value in mm.
Fnnn – feedrate mm/sec.
Znnn - lift (lift) of the head along the Z axis in mm during retract. (Helps avoid hitting the model)
Example: M207 S4.0 F2400 Z0.075
Used subsequently for G10 and G11 commands.
Use M500 to store parameters in EEPROM.
M208 Snnn Fnnn – Bar feed recovery parameters after retract
Snnn – positive feed value in mm.
Fnnn – feedrate mm/sec.
Use M500 to store parameters in EEPROM.
M209 Snnn – On/off automatic retraction
Snnn – value 1 – on, 0 – off
Used if the slicer does not support the G10 and G11 commands.
Each extrusion command will be classified as a retract, depending on the value (positive or negative).
M218 Tnnn Xnnn Ynnn – head offset setting
Tnnn - head number
Xnnn, Ynnn – X,Y coordinates.
Example: M218 T0 X50 Y10. 5
M301 Hnnn Pnnn Innn Dnnn — Write hotend PID parameters(!)
Hnnn – extruder number. h2 - the first exruder (hotend).
Pnnn - Proportional gain (Kp)
Innn - Integral factor (Ki)
Dnnn - Derivative coefficient (Kd)
Example: M301 h2 P1 I2 D3
Use M500 to store parameters in EEPROM.
See M304 for writing table PID.
M302 Snnn - Allow extrusion at Snnn and above.
Snnn - Set temperature
Example: M302 S170 – enable extrusion (turn on the extruder motor) at a nozzle temperature of 170C and above. M302 S0 - extrude at any temperature.
M303 Ennn Snnn Cnnn - Start PID calibration process for table/hotend
Ennn - E0 hotend, E1 table.
Snnn is the calibration temperature.
Cnnn – number of calibration cycles. More cycles - more precise parameters.
Example M303 E1 C8 S110 – table PID calibration at 110C for 8 cycles.
The PID parameters will be displayed as a string on the terminal screen of a program running in connection with the printer, such as Repetier-Host.
M304 Pnnn Innn Dnnn - Write table PID parameters(!)
Pnnn - Coefficient proportional (Kp)
Innn - Integral factor (Ki)
Dnnn - Derivative coefficient (Kd)
Example: M301 h2 P1 I2 D3
M301 - without parameters will display the current parameters.
Use M500 to store parameters in EEPROM.
For writing extruder PID see M301.
М404 Wnnn - Setting the nominal filament thickness 1.75 or 3.
Wnnn - nominal (theoretical) filament thickness in mm.
Example: M404 W1.75
M404 - without parameters, will display the current nominal value as a string.
This value is used to determine the percentage difference in the automatic rate adjustment in response to the measured filament width and must match the value used for the filament width in slicer settings.
Set actual filament thickness, see M200.
М420 Snnn – Enable/disable the use of the table curvature compensation grid (MESH_BED_LEVELING)
Snnn – S1 on, S0 off.
M420 S1 – use the table curvature compensation grid loaded from EEPROM when printing.
See G29 to get the current status and create a table curvature compensation grid.
M500 - Save data to EEPROM
M501 - Reading data from EEPROM
M600 - Command for automatic filament change
3D Printing G-code Basics: List and Guide
3DPrintStory    3D printing process     G-code Basics for 3D Printing: List and Guide
G-code is a programming language for numerical control (CNC). In other words, it is the language that the computer that controls the car speaks, and it transmits all the commands necessary for movement and other actions.
Although G-code is a standard language for various desktop and industrial equipment, it can be very familiar with a 3D printer. You may not have figured this out yet, and that's okay, since 3D slicers generate G-code "automatically".
However, if you want to get a deeper understanding of 3D printing, it's important to learn the basics of G-code. This knowledge will allow you to better diagnose and control 3D printing processes, as well as configure 3D printer firmware such as RepRap or Marlin.
In this article, we'll cover the basics of G-code, including how to read, understand, and write commands, even if you're new to programming!
What is a G-code?
For those unfamiliar with programming in general, you can think of G-code as successive lines of instructions, each telling the 3D printer to perform a specific task. These lines are called commands, and the printer executes them one after the other until it reaches the end of the code.
Although the term "G-code" is used to refer to a programming language in general, it is also one of two types of commands used in 3D printing: "basic" and "auxiliary" commands.
The main command lines are responsible for the types of motion in the 3D printer. Such commands are denoted by the letter "G". In addition to controlling the three positive axes performed by the printhead, they are also responsible for the extrusion of the filament.
On the other hand, different commands make the machine perform non-geometric tasks. In 3D printing, such tasks include nozzle and bed heating commands, as well as fan control, and so on. Auxiliary commands are denoted by the letter "M".
G-code syntax
Each line of G-code commands has a specific syntax. Each line corresponds to only one command, which can lead to very long codes.
The first argument of any string is the command code itself. As you have seen, this can be a code like "G" or "M" followed by a number identifying the command. For example, "G0" corresponds to a linear movement command.
Next are the parameters that define the command more precisely. For example, for a G0 linear motion command, you can add an end position and a travel speed, also indicated in capital letters. Each command has its own set of options, which we will discuss below.
G-code comments
When you read the G-code of a command, you will see semicolons after letters and numbers that explain what the code does. Here is an example of a line with a comment to the code:
G1 X25 Y5; I'm commenting out the code!
Programmers often need to include plain language explanations so that other programmers can understand certain lines or sections of code. It can also happen that you forget why you wrote something in a certain way, making it hard for you to figure it out again. Code comments are used to solve this problem. Comments include everything (on the same line) after the semicolon and are completely ignored by the machine when executing G-code. As such, they are solely for the eyes of programmers.
Important 3D Printing Commands
Although there are literally hundreds of G-code commands, in the next few sections we'll cover the most basic and important ones. Once you get comfortable, you can learn other commands on your own.
G0 and G1: linear movement
The G0 and G1 commands execute linear movements. By convention, G0 is used for non-extrusion motions such as initial and idle motions, while G1 covers all linear motions with material extrusion.
Both commands work the same, however. The parameters for G0 or G1 include the end positions for all X, Y, and Z axes, the degree of extrusion performed during the move, and the speed determined by the feed rate in given units.
Example
G1 X90 Y50 Z0. 5 F3000 E1 tells the 3D printer to move in a straight line (G1) to end coordinates X = 90mm, Y = 50mm, Z = 0.5mm at a feedrate (F) of 3000mm / min. and extrusion (E) 1 mm of material in the extruder.
Most linear moves are within the same layer, which means that the Z coordinate is usually not specified on the command line.
G90 and G91: absolute and relative positioning
The G90 and G91 commands tell the machine how to interpret the coordinates used for movement. G90 sets "absolute positioning", which is normally the default, while G91 sets "relative positioning".
Neither command requires any parameters, and setting one automatically overrides the other. Positioning works quite simply, so let's get straight to the point.
Example
Let's say we want to move the print head X = 30 in a line. In absolute positioning mode it would look like this:
G90; sets absolute positioning G0X30; moves to X = 30
This simple move will tell the printer to move the printhead so that it is positioned at X = 30. Now, to move the relative position, we need to know where the printhead is currently located. Suppose it's X = 10:
G90; sets relative positioning G0X20; moves +20mm in the X direction
G91 first tells the 3D printer to interpret the coordinates relative to the current position (X = 10). Knowing this, it is enough just to move 20 mm in the positive direction of the X axis, thus reaching X = 30, as we would like.
G28 and G29: automatic zeroing and table calibration
Homing is the process of moving up to physical limits for all axes of motion. The G28 command will accomplish this task by moving the print head until the limit switches on all axes are engaged.
Moving "to zero" is important not only to orient the device, but also to prevent the printhead from running out of bounds. The G28 command is usually executed before every start of 3D printing.
A specific axis can be individually homed by including X, Y or Z as parameters. Otherwise, only G28 will provide movement to zero in all axes.
Example
G28 X Y; only X and Y axes G28; to zero on all axes
Another command, G29, starts the automatic table calibration sequence. There are many different methods for leveling a table before 3D printing. Usually this operation is provided by the firmware and not by the end users. For this reason, we will not go into details regarding the methods and parameters of commands. Just be aware that G29 is usually sent after automatic homing (G28). As a result, automatic table calibration should be performed, which is determined by the firmware.
G29; execute automatic bed leveling sequence
M104, M109, M140 and M190: temperature setting
These are important commands, which again are not motion related.
To start, the M104 command sets the target temperature that the hot end must reach and holds it until otherwise specified.
Some of the parameters include actual temperature value (S) and print head (T) for heating.
Example
M104 S210; set target temperature for hot end to 210 degrees
This command line tells the 3D printer to heat the hot end to 210°C.
Alternatively, if we want to wait until this target is reached before moving on to the next line, we can use the M109 command.
M109 S210; set the hot end target temperature to 210 degrees and do nothing until it is reached
Setting the table temperature is very similar, but instead set using the M140 and M190 commands:
M140 S110; set target table temperature to 110 degrees M190S110; set the target bed temperature to 110 degrees and do nothing until it is reached
M106 and M107: Fan control
Another important command for 3D printers, the M106 and M107 commands provide fan control.
M106 turns on the fan and sets its speed. This is especially useful for the part cooling fan, as during the 3D printing process, different speeds are required during the printing of the first layer and the web.
The speed parameter must be between 0 and 255. A value of 255 provides 100% power, and any number in this range will indicate the appropriate percentage.
Example
M106; turn on the fan at maximum (100%) speed M106 S128; turn on the fan and set it to 50% power
Multiple variable speed fans can be identified using the index (P) parameters since each fan is assigned an index by the firmware.
Finally, the M107 command will turn off the specified fan. If the index parameter is not specified, the partial cooling fan is usually disabled.
Program structure
Now we have a good opportunity to look at the actual code snippet that is used for 3D printing. As we will see later, G-code programs can be divided into three distinct sections.
It is worth noting that if you use a text editor to open a G-code file created with a 3D slicer, it may not immediately start with G- or M-commands. For example, a slicer like Cura or Simplify3D runs the code, including some of the print process parameters defined earlier in the comments. These lines do not affect the print, but instead are a quick guide to parameters such as layer height.
Stage 1: Initialization
The first section of any program includes the preparatory tasks necessary to start printing a 3D model. Below are the first six lines of G-code initialization commands from the actual 3D print job.
G90 M82 M140 S80 M104 S200 G28 G29
As we now know, the first line tells the move to use absolute positioning, and the second line tells the extruder to also interpret the extrusion in absolute units.
The third and fourth lines start heating the bed and the nozzle to the set temperatures. Note that it will not wait for the target temperature to be reached, meaning the printer will automatically reset and level the table when heated.
Some initialization routines (such as the one used by the PrusaSlicer) include a nozzle cleaning process or printing a single straight line before moving on to the 3D printing process.
Stage 2: 3D printing
This is where the magic begins. If you look at the layered G-code file, you realize that it's really impossible to understand what a nozzle actually does.
3D printing is a layer-by-layer process, so you'll find that this step involves a lot of movement in the XY plane when printing a single layer. Once this is done, one tiny movement in the Z direction will define the beginning of the next layer.
Here is an example of what G-code commands might look like in 3D printing:
G1 X103.505 Y153.291 E4.5648; movement and extrusion in the XY plane G1 X103.291 Y153.505 E4.5804; movement and extrusion in the XY plane G1 Z0.600 F3000; change layer G1 X104.025 Y154.025 F9000; movement in the XY plane G1 X95.975 Y154.025 E0.4133 F1397; moving and extruding in the XY plane
Step 3: Reloading the 3D Printer
Finally, when the 3D print is complete, some last lines of the G-code commands reset the printer to its default state.
For example, the nozzle may move to a predetermined position, the hot end and table heaters are turned off, and the motors are turned off.
M107; turn off the fan G1Z10; move the nozzle away from the print M104S0; turn off hot end heating M140S0; turn off bed heating M84; turn off the motors
Data input and output via the terminal
So far we have only talked about the fact that the computer sends G-code commands to the 3D printer (usually transmitted via an SD card). However, this is not the only way to communicate.
Some 3D printer control software, such as Pronterface and OctoPrint, allows you to interact directly with the 3D printer, in which case you can enter commands manually.
For obvious reasons, it would be impractical to print anything by sending code lines individually. But sometimes this method of communication is required for other purposes, such as obtaining valuable information for calibration or when the 3D printer does not have a display.
For example, an M105 "report temperatures" command will retrieve the current nozzle and bed temperatures (which can then be displayed by something like OctoPrint).
This link is also very useful for viewing and changing EEPROM settings that are hardcoded at the firmware level. Parameters such as motor steps / mm, maximum feedrate or PID controller can be visualized with M503 ("report settings"), changed manually and then saved with M500 ("save settings").
Writing G-code
By now you should be able to read and understand G-code much better. We recommend looking towards the following options to deepen your knowledge:
- online G-code visualization is a great tool to test your skills as you can write G-code commands and simulate them accordingly. It's actually a lot of fun!
- looking at exported G-code files from slicers should also give you some idea of how G-code works for 3D printing.
- You can use the information from the official Marlin website as a command reference.
Compatible
We hope that with your understanding of the G-code commands, you will become a more advanced 3D printer user. Although G-code is not the most complex computer language, it still requires practice and learning.
Before we wrap up this article, it might be worth talking a little about G-code compatibility.
There are many types of 3D printing firmware, and each can have a different "variant" of G-code. This can lead to serious compatibility issues, as commands that work on one machine may not work on another.