Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
503 views47 pages

RepRapFirmware G-Code Guide

This document summarizes G-codes, which are a machine control language used widely in 3D printing. It describes the G-codes supported by RepRapFirmware, noting they were originally based on information from the RepRap wiki. RepRapFirmware follows a "G-code everywhere" philosophy where user interaction and configuration is done through G-codes. The document provides details on G-code structure and commands.

Uploaded by

Fenix Mechanics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
503 views47 pages

RepRapFirmware G-Code Guide

This document summarizes G-codes, which are a machine control language used widely in 3D printing. It describes the G-codes supported by RepRapFirmware, noting they were originally based on information from the RepRap wiki. RepRapFirmware follows a "G-code everywhere" philosophy where user interaction and configuration is done through G-codes. The document provides details on G-code structure and commands.

Uploaded by

Fenix Mechanics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Gcode dictionary

This page describes the RepRapFirmware supported G-codes, originally based on the
information from the RepRap wiki G-code page.

G-Codes are a widely used machine control language. They are human readable
and editable. This page describes the RepRapFirmware supported G-codes.
RepRapFirmware follows the philosophy of "G-code everywhere", in essence the
users or external program's interaction with the firmware should be through G-
codes. There are G-codes for all supported control and configuration inputs along
with status and debugging information.

RepRapFirmware G-codes were originally based on the information from


the RepRap wiki G-code page. There are some G-Codes listed on that page that are
not implemented in RepRapFirmware. More details can be found on the G-Codes
not implemented page.

Introduction
A typical piece of G-code sent to a machine running RepRapFirmware might look
like this (The meaning of these codes (and more) is explained below on this page.)

G10 P0 S195 R175

T0

G1 X100 Y100 Z0.3 F3000

G1 X100.4 Y99.3 E0.23 F600

...many 1000 more lines...

G-Code Everywhere

A design philosophy of RepRapFirmware is "G-code everywhere" what this means is


explained in this sub section
The G-code can originate from a number of sources:

 Sent to over USB (for example from http://www.pronterface.com/)

 Sent by the Duet Web Control Web (DWC) Interface

 Sent by an external controller such as the PanelDue.

In all cases the G-Code could

 be entered by user one line at time, for example during configuration or testing

 be sent by the User Interface (Pronterface, Web Interface or PanelDue) in


response to the user pressing buttons

 originate from macros that are triggered on startup, on certain events (such as
error conditions), or called by the user or UI.

 be from a g-code file which are normally stored on the on-board or external SD
card.

A key difference from other 3d printer firmwares is not employing a separate


command set (other than G-codes) to configure the printer. To that end
RepRapFirmware has a large collection of configuration g-codes that allow the
behaviour of the machine to be controlled. For some examples of when these G-
Codes are employed have a look at these wiki pages:

 Configuring RepRapFirmware for a Cartesian printer

 Configuring RepRapFirmware for a Delta printer

 Configuring RepRapFirmware for a CoreXY printer

 Configuring RepRapFirmware for an IDEX printer

 Configuring RepRapFirmware for a SCARA printer

 Configuring RepRapFirmware for a Polar printer

 Configuring RepRapFirmware for a Hangprinter printer

 Tuning the heater temperature control


 Setting up automatic probing of the print bed

 Using servos and controlling unused IO pins

The advantage of "G-code everywhere" is the same commands can be send from
any of the G-Code sources, and originate from the user, a UI, macro or file and it
will generate the same response from the firmware. This greatly improves the ease
and power of firmware configuration and operation.

G-Code Structure
This section explains the elements that make up a G-Code command.

Command Order

The general rule on command order in config.g is: don't try to change the
parameters of anything that you haven't already created and doesn't exist by
default.

For example:

 Don't refer to any axis letter or extruder number that you haven't created using
M584 (except that XYZ already exist by default)

 Don't refer to any temperature sensor in M950 or M106 before you create it
using M308

 Don't refer to a heater in M307, M140, M141, M143 or m563 before you create
it using M950

 Don't refer to a fan in M106 before you create it using M950

 Don't refer to a tool in G10/M568 before you create it using M563

Comments

G-Code comments begin at a semicolon, and end at the end of the line:
T0 ; This is a comment

G92 E0

;So is this

G28

Alternatively, comments can be enclosed in brackets, but they must start and end
on the same line:

G28 (here come the axes to be homed) X Y

Comments and white space will be ignored by RepRapFirmware when executing


the G-Code

Fields

A RepRap G-Code is a list of fields that are separated by white spaces or line
breaks. A field can be interpreted as a command, parameter, or for any other
special purpose. It consists of one letter directly followed by a number, or can be
only a stand-alone letter (Flag). The letter gives information about the meaning of
the field (see the list below in this section). Numbers can be integers (128)
or fractional numbers (12.42), depending on context. For example, an X coordinate
can take integers (X175) or fractionals (X17.62), but selecting extruder number
2.76 would make no sense. In this description, the numbers in the fields are
represented by nnn as a placeholder.

In RepRapFirmware 3.01 and later, instead of a number you may use an expression
enclosed in braces, for example {2+2}. See GCode Meta Commands for details of
the supported expression types.

In RepRapFirmware, some parameters can be followed by more than one number,


with colon used to separate them. Typically this is used to specify extruder
parameters, with one value provided per extruder. If only one value is provided
where a value is needed for each extruder, then that value is applied to all
extruders.
Letter Meaning

Gnnn Standard G-Code command, such as move to a


point

Mnnn RepRap-defined command, such as turn on a


cooling fan

Tnnn Select tool nnn. In RepRap, a tool is typically


associated with a nozzle, which may be fed by
one or more extruders.

Snnn Command parameter, such as time in seconds;


temperatures; voltage to send to a motor

Pnnn Command parameter, such as time in


milliseconds; proportional (Kp) in PID Tuning

Xnnn A X coordinate, usually to move to. This can


be an Integer or Fractional number.

Ynnn A Y coordinate, usually to move to. This can


be an Integer or Fractional number.

Znnn A Z coordinate, usually to move to. This can


be an Integer or Fractional number.

U,V,W Additional axis coordinates


Innn Parameter - X-offset in arc move (Not yet
implemented in RepRapFirmware); integral
(Ki) in PID Tuning; signal inversion

Jnnn Parameter - Y-offset in arc move (Not yet


implemented in RepRapFirmware)

Dnnn Parameter - used for diameter; derivative (Kd)


in PID Tuning; drive number

Hnnn Parameter - used for heater number in PID


Tuning

Fnnn Feedrate in mm per minute. (Speed of print


head movement)

Rnnn Parameter - used for temperatures

Qnnn Parameter - not currently used

Ennn Length of filament to move through the


extruder. This is exactly like X, Y and Z, but
for the length of filament to consume. Where a
tool has more than one extruder drive then
Ennn:nnn:nnn etc is supported to allow for the
individual morement of each to be controlled
directly

Nnnn Line number. Used to request repeat


transmission in the case of communications
errors. Optional
*nnn Checksum. Used to check for communications
errors. Optional

Case sensitivity

The original NIST GCode standard requires gcode interpreters to be case-


insensitive, except for characters in comments. However, not all 3D printer
firmwares conform to this and some recognise uppercase command letters and
parameters only.

RepRapFirmware version 1.19 and later is case-insensitive, except for characters


within quoted strings. RepRapFirmware version 1.18 and earlier accept only
uppercase letters for command and parameter letters.

Quoted strings

In RepRapFirmware, quoted strings are permitted anywhere a string parameter is


expected. This allows file names, WiFi passwords etc. to contain spaces, semicolons
and other characters that would otherwise not be permitted. Double-quote
characters are used to delimit the string, and any double-quote character within
the string must be repeated.

Unfortunately, many gcode sender programs convert all characters to uppercase


and don't provide any means to disable this feature. Therefore, within a quoted-
string, the single-quote character is used as a flag to force the following character
to lowercase. If you want to include a single quote character in the string, use two
single quote characters to represent one single quote character.

Example: to add SSID MYROUTER with password ABCxyz;" 123 to the WiFi network
list, use command:

M587 S"MYROUTER" P"ABCxyz;"" 123"

or if you can't send lowercase characters:


M587 S"MYROUTER" P"ABC'X'Y'Z;"" 123"

Checking

This is an optional feature that is seldom used as g-code files are normally printed
form the on-board SD card.

N: Line number

Example: N123

If present, the line number should be the first field in a line. For G-code stored in
files on SD cards the line number is usually omitted.

If checking is supported, the firmware expects line numbers to increase by 1 each


line, and if that doesn't happen it is flagged as an error. But you can reset the count
using M110 (see below).

*: Checksum

Example: *71

If present, the checksum should be the last field in a line, but before a comment.
For G-code stored in files on SD cards the checksum is usually omitted.

If checking is supported, the RepRap firmware checks the checksum against a


locally-computed value and, if they differ, requests a repeat transmission of the line
of the given number.

Method

Example: N123 [...G Code in here...] *71

The firmware checks the line number and the checksum.


You can leave both of these out - RepRap will still work, but it won't do checking.
You have to have both or neither though. If only one appears, it produces an error.
See this thread for an example of usage, in this case sending g-code to the
PanelDue port without disabling
cheksums: https://forum.duet3d.com/topic/15134/how...

The checksum "cs" for a G-Code string "cmd" (including its line number) is
computed by exor-ing the bytes in the string up to and not including the *
character as follows:

int cs = 0;

for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)

cs = cs ^ cmd[i];

cs &= 0xff; // Defensive programming...

and the value is appended as a decimal integer to the command after the *
character.

Conditional execution, loops, and other command words

In RepRapFirmware 3.01 and later, if the line begins with a recognised keyword
(optionally preceded by N and a line number, and/or space or tab characters) then
that whole line of GCode is interpreted as a meta-command. Recognised keywords
are:

abort elif else if set var while

See GCode Meta Commands for details of these commands.

A line that does not start with one of these keywords must start with command
letter G, M or T or be empty apart from white space and comments. Exception:
when in CNC or Laser mode, if a line does not start with a G, M or T command but
nevertheless has other fields, and the previous line that included a command was a
G0, G1, G2 or G3 command, then the previous command will be repeated with
values from the new fields. This is to support GCode generated for CNC machines.

Multiple commands on a single line

RepRapFirmware allows multiple G- and M-commands to be included in a single


line. Each occurrence of G or M on the line that is preceded by a space or tab
character and is not inside a quoted string or a meta command starts a new
command. In RRF 3.2 and later, the space or tab character is not required.

Important: a command that invokes a macro file must be the last command in that
line of GCode, because any following commands on the same line will not be
executed.

Buffering

RepRapFirmware stores some commands in a ring buffer internally for execution.


This means that there is no (appreciable) delay while a command is acknowledged
and the next transmitted. In turn, this means that sequences of line segments can
be plotted without a dwell between one and the next. As soon as one of these
buffered commands is received it is acknowledged and stored locally. If the local
buffer is full, then the acknowledgement is delayed until space for storage in the
buffer is available. PC host programs rely on this for flow control when the
controller electronics does not support device level flow control.

Only the G0 to G3 movement commands are buffered by RepRapFirmware. All


other G, M or T commands are not buffered. When M555 P6 is used to select
nanoDLP compatibility mode, no commands are buffered.

When an unbuffered command is received it is stored, but it is not acknowledged


to the host until the buffer is exhausted and then the command has been executed.

Filenames and Paths


System macro gcode files are expected in "0:/sys/". See M505 for how to switch
between multiple configurations

User macro gcode files are expected in "0:/macros/"

Job gcode files are expected in "0:/gcodes/" or a sub directory of that.

"0:/ is root of the on board SD card in stand alone mode, or equivalent folder in
SBC mode (/opt/dsf/sd/)

Long file names (e.g. longer than 8.3 format) are supported, file names with spaces
are supported.

Full paths, including all directories and subdirectories are limited to 120 characters.

e.g.:

0:/gcodes/0123456789/012.gcode

counts as 30 characters

Live editing

As a general rule, any G or M command can be sent at any time. This means all
settings can be changed 'on the fly', i.e. while printing. This does not take into
account logical considerations, or individual pre-requisites for individual
commands. For example, sending new values for M566 'jerk', M201 'acceleration',
or M203 'max speed' while printing is a great way to tune these values. However,
while it is theoretically possible to change M563 'define a tool' while printing, it's
probably not a good idea.

G-commands
G0 & G1: Move
G0: Rapid move

G1: Controlled *(linear) move

G2 & G3: Controlled Arc Move

G2: Clockwise arc move

G3: Counter-clockwise arc move

G4: Dwell

G4: Pause the machine for a period of time, in milliseconds or seconds

G10: Tool Temperature Setting

G10: (P parameter with R or S parameter) Sets active and standby tool


temperatures

G10: Set workplace coordinate offset or tool offset

G10: (XYZUVWABC and L parameters) Sets tool offset or coordinate system origin
(absolute or relative current position) for specific tool

G10: Retract

G10: (no parameters) Retracts filament then performs any zlift/hop according to
settings of M207

G11: Unretract

G11: Unretracts/recovers filament after undoing any zlift/hop according to settings


of M207

G17: Select XY plane for arc moves

G17: Sets XY as the active plane for interpreting the tool path of an arc (G2 or G3)
G18: Select XZ plane for arc moves

G18: Sets XZ as the active plane for interpreting the tool path of an arc (G2 or G3)

G19: Select YZ plane for arc moves

G19: Sets YZ as the active plane for interpreting the tool path of an arc (G2 or G3)

G20: Set Units to Inches

G20: Units from this command onwards are in inches

G21: Set Units to Millimeters

G21: Units from this command onwards are in millimeters

G28: Home

G28: Move all axes, or the specified ones, to establish a known position for them,
for example by moving an axis motor until an endstop switch is triggered

G29: Mesh bed probe

G29: Uses a Z probe to measure the bed height at 4 or more points to determine
its tilt and overall flatness, then enables mesh compensation so that the nozzle will
remain parallel to the bed

G30: Single Z-Probe

G30: Uses a Z probe to measure bed height at a single point

G31: Set or Report Current Probe status

G31: Sets Z probe parameters or reports status

G32: Run bed.g macro


G32: Runs macro file bed.g. This macro can be used to probe the bed and then
perform auto calibration of a delta printer, perform bed levelling by moving the Z
leadscrews independently, or display the manual corrections needed to the bed
levelling screws.

G38.2 to G38.5: Straight Probe

G38.2: Probe toward workpiece, stop on contact, signal error if failure

G38.3: Probe toward workpiece, stop on contact

G38.4: Probe away from workpiece, stop on loss of contact, signal error if failure

G38.5: Probe away from workpiece, stop on loss of contact

G53: Use machine coordinates

G53: Causes all coordinates in movement commands on the remainder of the


current line of GCode to be interpreted as machine coordinates, ignoring any
coordinate offset of the workplace coordinate system currently in use, and also
ignoring any tool offsets

G54 to G59.3: Select coordinate system

G54: selects coordinate system 1

G55: selects coordinate system 2

G56: selects coordinate system 3

G57: selects coordinate system 4

G58: selects coordinate system 5

G59: selects coordinate system 6


G59.1: selects coordinate system 7

G59.2: selects coordinate system 8

G59.3: selects coordinate system 9

G60: Save current position to slot

G60: Saves current position to slots 0, 1 or 2

G68: Coordinate rotation

G68: Rotates the coordinate system in the current plane as selected by G17, G18 or
G19.

G69: Cancel coordinate rotation

G69: Cancels any coordinate rotation that was set up by G68.

G90: Set to Absolute Positioning

G90: All coordinates from this command onwards are absolute, relative to the
origin of the machine

G91: Set to Relative Positioning

G91: All coordinates from this command onwards are relative to the last position.

G92: Set Position

G92: Sets position of axes by manually specifying values for the axis positions

M-commands
M0: Stop or Unconditional stop
M0: After finishing any moves left in buffer, runs either cancel.g or stop.g, then sets
motors to idle and turns heaters off (unless specified not to)

M1: Sleep or Conditional stop

M1: After finishing any moves left in buffer, runs either cancel.g or sleep.g, then
turns off all motors and heaters

M3: Spindle On, Clockwise (CNC specific)/ Laser on (Laser specific)

M3: In CNC mode turns on spindle clockwise, in Laser mode turns on laser power

M4: Spindle On, Counterclockwise (CNC specific)

M4: Turns on spindle counterclockwise

M5: Spindle Off (CNC specific), laser off (Laser specific)

M5: In CNC mode turns off spindle, in Laser mode turns off laser power

M17: Enable all stepper motors

M17: Enables all stepper motors when used without parameters, or use axes
parameters to enable selectively

M18: Disable all stepper motors

M18: Disables all stepper motors when used without parameters, or use axes
parameters to enable selectively

M20: List SD card

M20: Lists files on the SD card. Use parameters to list files in subdirectories or on
secondary SD card

M21: Initialize SD card


M21: The specified SD card is initialized. If an SD card is loaded when the machine
is switched on, this will happen by default. SD card must be initialized for the other
SD functions to work.

M22: Release SD card

M22: The specified SD card is released, so further (accidental) attempts to read


from it are guaranteed to fail. Helpful, but not mandatory before removing the card
physically.

M23: Select SD file

M23: The specified file is selected ready for printing.

M24: Start/resume SD print

M24: The machine prints from the file selected with the M23 command. If the print
was previously paused with M25, printing is resumed from that point.

M25: Pause SD print

M25: The machine pauses printing at the current position within the file.

M26: Set SD position

M26: Set the file offset in bytes from the start of the SD card file selected by M23.

M27: Report SD print status

M27: Reports the number of bytes processed in the format bytes processed / bytes
total in file

M28: Begin write to SD card

M28: The specified file is created (or overwritten if it exists) on the SD card and all
subsequent commands sent to the machine are written to that file.
M29: Stop writing to SD card

M29: File opened by M28 command is closed, and all subsequent commands sent
to the machine are executed as normal.

M30: Delete a file on the SD card

M30: The specified file is deleted.

M32: Select file and start SD print

M32: The specified file is selected from the SD card and starts printing. Does the
same as M23 and M24.

M36: Return file information

M36: Returns information for the specified SD card file in JSON format.

M36.1: Return embedded thumbnail data

M36.1: Returns the data for a thumbnail image in a GCode file in JSON format.

M37: Simulation mode

M37: Enters/leaves simulation mode, or runs the specified file in simulation mode
allows the electronics to compute an accurate printing time, taking into account
the maximum speeds, accelerations etc. that are configured.

M38: Compute SHA1 hash of target file

M38: Used to compute a hash of a file on the SD card and returns a hexadecimal
string which is the SHA1 of the file.

M39: Report SD card information

M39: Returns information about the SD card in the specified slot in the requested
format.
M42: Switch I/O pin

M42: Switches a general purpose I/O pin.

M73: Set remaining print time

M73: Generated by some slicers to inform the firmware about the state of the print
so that it can provide a better estimate of the remaining print time.

M80: ATX Power On

M80: Turns on the ATX power supply from standby mode to fully operational mode
using the power supply control pin on the External 5V header.

M81: ATX Power Off

M81: Turns off the ATX power supply. Counterpart to M80.

M82: Set extruder to absolute mode

M82: Makes the extruder interpret extrusion as absolute positions.

M83: Set extruder to relative mode

M83: Makes the extruder interpret extrusion values as relative positions.

M84: Stop idle hold

M84: Stop the stepper motor idle hold on all axes and extruder.

M92: Set axis steps per unit

M92: Allows programming of steps per mm for motor drives.

M98: Call Macro/Subprogram

M98: Runs the macro in the specified file.


M99: Return from Macro/Subprogram

M99: Returns from an M98 call. This is not required to return from the end of a
macro and the macro naturally returns at the end of file.

M101: Un-retract filament

M101: Same behaviour as G11 (unretract). Supported for compatibility with


Simplify3D.

M102: Turn extruder on (ignored)

M102: Command ignored as it is unnecessary in RRF. Supported for compatibility


with Simplify3D.

M103: Retract filament

M103: Same behaviour as G10 without parameters (retract). Supported for


compatibility with Simplify3D.

M104: Set Extruder Temperature

M104: Sets the active and standby temperature of the current or specified tool to
the temperature specified, and returns control to the host immediately (i.e. before
that temperature has been reached by the extruder).

M105: Get Extruder Temperature

M105: Reports the current and target temperatures of all active heaters.

M106: Fan On

M106: Sets fan parameters and turns them on and off.

M107: Fan Off

M107: Deprecated in RepRapFirmware. Use M106 S0 instead.


M108: Cancel Heating

M108: Breaks out of an M109 or M190 wait-for-temperature loop, continuing the


print job.

M109: Set Extruder Temperature and Wait

M109: Sets extruder temperature and waits until within 2.5°C of target.

M110: Set Current Line Number

M110: Sets the current line number in the running Gcode file.

M111: Set Debug Level

M111: Enables or disables debugging features, for the module number specified by
the P parameter.

M112: Emergency Stop

M112: Any moves in progress are immediately terminated, then RepRap shuts
down. All motors and heaters are turned off. It can be started again by pressing the
reset button or power cycling the board.

M114: Get Current Position

M114: Reports the X, Y, Z and E (and U, V, W, A, B, C if configured) coordinates to


the host. The coordinates reported are those at the end of the last completed
move.

M115: Get Firmware Version and Capabilities

M115: Request the Firmware Version and Capabilities of the current


microcontroller.

M116: Wait
M116: waits for all temperatures, or a specified tool or heater's temperature, and
other slowly-changing variables to arrive at their set values.

M117: Display Message

M117: Causes the given message to be shown in the status line on an attached LCD
or if no LCD is attached, this message will be reported on the web interface.

M118: Send Message to Specific Target

M118: Used to send messages to a specific target: USB, PanelDue/UART, HTTP or


Telnet

M119: Get Endstop Status

M119: Returns the current state of the configured endstops.

M120: Push

M120: Push the state of the machine onto a stack. Called automatically when a
macro file is run.

M121: Pop

M121: Recover the last state pushed onto the stack.

M122: Diagnose

M122: Reports firmware diagnostic information.

M135: Set PID sample interval

M135: Deprecated. Sets the PID to measure temperatures and calculate the power
to send to the heaters

M140: Set Bed Temperature (Fast) or Configure Bed Heater


M140: Configures heaters as bed heaters and sets active and standby
temperatures, turns heaters on and returns control to the host immediately.

M141: Set Chamber Temperature (Fast) or Configure Chamber Heater

M141: Configures heaters as chamber heaters and sets active and standby
temperatures, turns heaters on and returns control to the host immediately.

M143: Maximum heater temperature

M143: Configures heater maximum temperatures. When the temperature of the


heater exceeds this value a heater error will be triggered.

M144: Bed Standby

M144: Switch the bed to its standby temperature.

M150: Set LED colours

M150: Sets RGB colours and brightness for Dotstar and NeoPixel LEDs.

M190: Wait for bed temperature to reach target temp

M190: Sets the temperature of the bed and waits for the temperature to be
reached.

M191: Wait for chamber temperature to reach target temp

M191: Set the temperature of the build chamber and waits for the temperature to
be reached.

M200: Set filament diameter

M200: Enables or disables volumetric extrusion per extruder, and sets the filament
diameter.

M201: Set max acceleration


M201: Sets the acceleration that axes can do in mm/second^2 for print moves.

M201.1: Set reduced acceleration for special move types

M201.1: Set the acceleration that axes should use for special types of move that
should be done using reduced acceleration, eg probing and stall homing.

M203: Set maximum feedrate

M203: Sets the maximum feedrates that axes can do in mm/min.

M204: Set printing and travel accelerations

M204: Sets the maximum acceleration for printing and/or travel moves as a whole.

M205: Set max instantaneous speed change in mm/sec

M205: Sets the maximum allowable speed change (sometimes called 'jerk speed')
of each motor when changing direction, in mm/sec.

M206: Offset axes

M206: Deprecated. The specified values will be subtracted from the coordinates
given in G0, G1 and related commands.

M207: Set retract length

M207: Sets the retract length used by the G10 and G11 firmware retraction and
reprime commands.

M208: Set axis max travel

M208: The specified values set the software limits for axis travel in the specified
direction. The axis limits are also the positions assumed when an endstop is
triggered.

M220: Set speed factor override percentage


M220: Sets the speed factor override percentage.

M221: Set extrude factor override percentage

M221: Sets extrude factor override percentage for the specified extruder.

M226: Synchronous Pause

M226: Initiates a pause in the same way as if the pause button is pressed, except
that execution of all prior GCode commands in the same input stream is completed
first.

M260: i2c Send and/or request Data

M260: Send and/or receive data over the i2c bus.

M261: i2c Request Data

M261: Deprecated. Requests data over the i2c bus.

M280: Set servo position

M280: Set absolute servo position.

M290: Baby stepping

M290: Applies the specified additional offset to the Z coordinate for all future
moves, and to apply the offset to moves that have already been queued if this can
be done.

M291: Display message and optionally wait for response

M291: Provides a more flexible alternative to M117, in particular messages that


time out, messages that suspend execution until the user acknowledges them, and
messages that allow the user to adjust axis positions before acknowledging them.

M292: Acknowledge message


M292: Sent by the user interface when the user acknowledges a message that was
displayed because of a blocking M291 command.

M300: Play beep sound

M300: Play beep sound via connected LCD, or if no LCD, via web interface.

M301: Set PID parameters

M301: Sets Proportional (P), Integral (I) and Derivative (D) values for hot end.

M302: Allow cold extrudes

M302: Disables temperature restrictions on extrusion and retraction, or sets these


temperatures.

M303: Run heater tuning

M303: This command computes the process model parameters (see M307), which
are in turn used to calculate the PID constants.

M304: Set PID parameters - Bed

M304: Sets Proportional, Integral and Derivative values for bed.

M305: Set temperature sensor parameters

M305: Sets or reports the parameters for each temperature sensor. If using RRF 3,
use M308 instead.

M307: Set or report heating process parameters

M307: Sets or reports the parameters for the heating process model, for each
heater.

M308: Set or report sensor parameters


M308: Sets or reports the parameters for each connected sensor. If using RRF 2,
use M305 instead.

M309: Set or report heater feedforward

M309: Sets or reports the feedforward PWM setting for a specified tool. Supported
in RepRapFirmware v3.4 and later

M350: Set microstepping mode

M350: Sets or reports the microstepping mode for each defined axis.

M374: Save height map

M374: Saves the mesh grid parameters and height map into the specified file, or
the default file heightmap.csv if no filename was specified.

M375: Load height map

M375: Loads the default grid (without parameters), or grid specified by filename.
Equivalent to G29 S1.

M376: Set bed compensation taper

M376: When using bed mesh compensation, specifies the height over which bed
compensation tapers. Full bed compensation is applied at Z=0, tapering down to
no bed compensation by the specified height.

M400: Wait for current moves to finish

M400: Finishes all current moves and and thus clears the buffer. Same as G4 P0.

M401: Deploy z-probe

M401: Runs macro file sys/deployprobe#.g (where # is the specified probe number)
if it exists, otherwise sys/deployprobe.g if it exists.
M402: Retract z-probe

M402: Runs macro file sys/retractprobe#.g (where # is the specified probe number)
if it exists, otherwise sys/retractprobe.g if it exists.

M404: Filament width and nozzle diameter

M404: Sets filament width and nozzle diameter. Used for slicers that report filament
volume, from which RRF calculates length for job status reporting.

M408: Report JSON-style response

M408: Reports system parameters in a JSON-style response. Different levels of


reporting are available.

M409: Query object model

M409: Reports parameters from the Object Model of RepRapFirmware, which


includes firmware configuration, Duet hardware information, and the state of the
machine that RRF is controlling.

M450: Report Printer Mode

M450: Report mode the machine is running; FFF (ie 3D printer), Laser or CNC.

M451: Select FFF Printer Mode

M451: Switches to Fused Filament Fabrication mode for filament printing.

M452: Select Laser DeviceMode

M452: Switches to laser mode and configures laser parameters.

M453: Select CNC Device Mode

M453: Switches to CNC mode.

M470: Create Directory on SD-Card


M470: Creates a new directory on the SD-Card, using the specified (or default)
path.

M471: Rename File/Directory on SD-Card

M471: Rename or move a file or directory.

M486: Object cancellation

M486: Used to identify objects on the print bed and selectively cancel them if
necessary.

M500: Store parameters

M500: Saves current parameters to the sys/config-override.g on the SD card.

M501: Read stored parameters

M501: Set the active parameters to those stored in sys/config-override.g on the SD


card.

M502: Revert stored parameters

M502: Sets all machine parameters to the values defined in config.g, ignoring the
config-override.g file so that any changes that were saved by M500 are not applied.

M503: Print settings

M503: Reports the current print settings stored in sys/config.g.

M505: Set configuration file folder

M505: Following this command, files that would normally be fetched from /sys/ (for
example, homing files and system macro files in RepRapFirmware) are fetched from
the specified folder instead. This command can be used to allow multiple
configurations to be maintained easily.
M540: Set MAC address

M540: Sets the MAC address of the machine, creating a unique identifier for the
Duet on the network.

M550: Set Name

M550: Sets the name of the machine. Also used for mDNS local network discovery.

M551: Set Password

M551: Sets the password for network access to the machine.

M552: Set IP address, enable/disable network interface

M552: Sets the IP address of the machine and enables/disables network access.

M553: Set Netmask

M553: Sets the network mask of the machine.

M554: Set Gateway and/or DNS server

M554: Sets the Gateway IP address of the machine.

M555: Set compatibility

M555: Sets the firmware to a mode where its input and (especially) output behaves
similar to other established firmware.

M556: Axis skew compensation

M556: This tells firmware the tangents of the angles between the axes of the
machine. Obtained by printing then measuring a test part.

M557: Set Z probe point or define probing grid

M557: Defines the grid used by G29 to create a bed height mesh.
M558: Set Z probe type

M558: Defines the Z probe type and parameters of operation.

M559: Upload file

M559: Upload file, with parameters for file size and CRC-32 check. Was used in RRF
3.1 and earlier to upload files to /sys.

M560: Upload file

M560: Upload file, as M559, with terminating string. Was used in RRF 3.1 and
earlier to upload files to /www.

M561: Set Identity Transform

M561: Cancels any bed-plane fitting as the result of probing (or anything else) and
returns the machine to moving in the user's coordinate system.

M562: Reset temperature fault

M562: If the heater has switched off and locked because it has detected a fault, this
will reset the fault condition and allow you to use the heater again.

M563: Define or remove a tool

M563: Defines a tool with the specified parameters.

M564: Limit axes

M564: Allows or forbids movement of axes that have not been homed and/or limits
movement to within axis boundaries.

M566: Set allowable instantaneous speed change

M566: Sets the maximum allowable speed change (sometimes called 'jerk speed')
of each motor when changing direction.
M567: Set tool mix ratios

M567: Sets the mix ratio for a tool. When a move command contains a single E
value but the current tool uses multiple extruders, each extruder will extrude the
amount specified in the E parameter times the mix value for that tool.

M568: Set Tool Settings

M568: Set tool parameters to values specified. Active and standby temperatures,
spindle RPM and heater state.

M569: Set motor driver direction, enable polarity, mode and step pulse timing

M569: Sets stepper driver parameters to values specified. Parameters include motor
direction, enable, minimum step pulse width, interval, direction setup and hold
time, and other stepper driver features.

M569.1: Stepper driver closed loop configuration

M569.1: Set the configuration parameters of a closed loop driver. Supported for
drivers attached to Duet 3 Expansion 1HCL board.

M569.2: Read or write stepper driver register

M569.2: Reads the specified register and returns the value of that register, or if a
value is specified, that value is written to the specified register.

M569.3: Read Motor Driver Encoder

M569.3: Report a current motors encoder position to the host in units of arc
degrees (1/360'ths of turns), relative to set reference position.

M569.4: Set Motor Driver Torque Mode

M569.4: Tell one or more motor drivers to apply a specified torque regardless of
position.
M569.5: Closed loop data collection

M569.5: Collect performance data from a drive whilst in closed loop mode.

M569.6: Execute closed loop tuning move

M569.6: Perform a runtime tuning manoeuvre with a closed loop drive.

M569.7: Configure motor brake port

M569.7: Specifies the output port that controls a brake.

M570: Configure heater fault detection

M570: Sets time and temperature parameters for the detection of heater
anomalies.

M571: Set output on extrude

M571: Turns on the defined output pin whenever extrusion is being done, and
turns it off when the extrusion is finished.

M572: Set or report extruder pressure advance

M572: Sets the pressure advance coefficient for the specified extruder.

M573: Report heater PWM

M573: Gives a running average (usually taken over about five seconds) of the PWM
to the specified heater.

M574: Set endstop configuration

M574: Defines the pin name, position and type of endstop or sensor that the
machine has for an axis.

M575: Set serial comms parameters


M575: Sets the communications parameters of the serial comms channel specified.

M576: Set SPI comms parameters

M576: Sets the communications parameters of the SPI channel.

M577: Wait until endstop is triggered

M577:Wait for a specified endstop switch or input to be triggered.

M578: Fire inkjet bits

M578: Fires specified inkjet head using the specified bit pattern. Not enabled in
firmware by default.

M579: Scale Cartesian axes

M579: Scales the specified axes by the given amount, to get prints exactly the right
size.

M580: Select Roland

M580: Enables/disables Roland mode, which changes output to Roland Machine


Language (RML).

M581: Configure external trigger

M581: Defines parameters for external triggers.

M582: Check external trigger

M582: Checks state of specified trigger.

M584: Set drive mapping

M584: Assigns stepper driver numbers to axes, and defines axes as linear or
rotational.
M585: Probe Tool

M585: Allows the current tool's offset to be updated by driving it into a given
endstop, on machines with at least one tool probe.

M586: Configure network protocols

M586: Enables/disables network protocols (HTTP, HTTPS, FTP, Telnet, SSH) and
configures parameters.

M587: Add WiFi host network to remembered list, or list remembered


networks

M587: Adds WiFi network SSID and password to the remembered networks list.
Optionally sets IP address, gateway, netmask, DNS server and country code.

M588: Forget WiFi host network

M588: Removes the specified network SSID from the remembered networks list.

M589: Configure access point parameters

M589: Configures the Duet to allow WiFi devices to connect directly, as an access
point. Settings for SSID, password, IP address and optionally the WiFi channel.

M591: Configure filament sensing

M591: Configures filament sensing for the specified extruder. The sensor may be a
simple filament presence detector, a device that measures movement of filament,
or both.

M592: Configure nonlinear extrusion

M592: Nonlinear extrusion is a feature that compensates for the increased back
pressure from the hot end as extrusion speed increases.

M593: Configure Input Shaping


M593: Configures the parameters for input shaping, which is used to reduce
ringing (also called ghosting).

M594: Enter/Leave Height Following mode

M594: Height following mode allows the Z position of the tool to be controlled by
a PID controller using feedback from a sensor. See also M951.

M595: Set movement queue length

M595: Allows the movement queue parameters to be adjusted so that the queue
can be lengthened if necessary, or kept short if a long movement queue is not
needed and there are other demands on RAM.

M600: Filament change pause

M600: Behaves like M226 except that if macro file filament-change.g exists in /sys
on the SD card, it is run in preference to pause.g.

M650: Set peel move parameters

M650: Sent by nanoDLP to execute a peel move after exposing a layer.

M651: Execute peel move

M651: Sent by nanoDLP to execute a peel move after exposing a layer.

M665: Set delta configuration

M665: Set the delta calibration variables, including diagonal rod length, delta
radius, printing radius, homed nozzle height and tower postion correction.

M666: Set delta endstop adjustment

M666: Sets delta endstops and bed tilt adjustments.

M667: Select CoreXY or related mode


M667: Deprecated. Selects CoreXY or CoreXZ mode. Use M669.

M669: Set kinematics type and kinematics parameters

M669: Sets kinematic type (cartesian, CoreXY, CoreXZ, Delta, SCARA, Hangprinter,
polar etc) and any extra kinematic parameters.

M670: Set IO port bit mapping

M670: Sets the port switching time advance for the specified pins.

M671: Define positions of Z leadscrews or bed levelling screws

M671: Sets the positions of 2 to 4 leadscrews or bed levelling screws used to


raise/lower the bed or gantry. This allows the firmware to perform bed levelling by
probing the bed and either automatically moving the leadscrews, or reporting the
adjustment to be made. See the G32 command.

M672: Program Z probe

M672: Sends configuration data to programmable Z probes such as the Duet3D


Smart Effector, for example to set the sensitivity.

M673: Align plane on rotary axis

M673: Aligns a plane that is mounted on a rotary axis. To make use of this code it is
required to take two probe points via G30 P first.

M674: Set Z to center point

M674: Determines the Z center point of a stash that is mounted on a rotary axis.
This code is yet to be implemented.

M675: Find center of cavity

M675: Finds the center of a cavity that can be measured using the configured axis
endstop.
M701: Load filament

M701: Loads the specified material in the current active tool.

M702: Unload filament

M702: Unloads the previously loaded filament from the current tool.

M703: Configure filament

M703: After assigning a filament to a tool, this command may be used to run
/filaments/<filament name>/config.g to set parameters like temperatures,
extrusion factor, retract distance.

M750: Enable 3D scanner extension

M750: Used as an OEM extension to enable scanner functionality in the firmware.

M751: Register 3D scanner extension over USB

M751: Used to turn on communication between the 3D printing and a 3D scanner


board, when attached to the USB port.

M752: Start 3D scan

M752: Initiates a new 3D scan and uploads it to the board's SD card

M753: Cancel current 3D scanner action

M753: Instruct the attached 3D scanner to cancel the current operation.

M754: Calibrate 3D scanner

M754: Calibrates the attached 3D scanner.

M755: Set alignment mode for 3D scanner

M755: Sends the ALIGN ON/OFF command the attached 3D scanner.


M756: Shutdown 3D scanner

M756: Sends the SHUTDOWN command the attached 3D scanner.

M851: Set Z-Probe Offset (Marlin Compatibility)

M851: Implemented for backwards compatibility with other firmware. It sets the Z
probe trigger in the same way as G31 Z-nn (note the sign reversal).

M905: Set local date and time

M905: Updates the machine's local date and time or reports them if no parameters
are specified.

M906: Set motor currents

M906: Sets the peak currents to send to the stepper motors for each axis.

M911: Configure auto save on loss of power

M911: When the supply voltage falls below the auto save threshold while a print
from SD card is in progress, all heaters will be turned off, printing will be stopped
immediately (probably in the middle of a move), the position saved, and the
specified command string executed.

M912: Set electronics temperature monitor adjustment

M912: Adjusts the temperature reading offset of the MCU's on-chip temperature
sensor.

M913: Set motor percentage of normal current

M913: Sets motor currents to a specified percentage of their normal values.

M914: Set/Get Expansion Voltage Level Translator

M914: This command is supported in the Alligator build of RepRapFirmware only.


M915: Configure motor stall detection

M915: Sets the stall detection parameters and optionally the low-load current
reduction parameters for TMC2660, TMC2130 or similar driver chips.

M916: Resume print after power failure

M916: If the last print was not completed and resume information has been saved
(either because the print was paused or because of a power failure), then the
heater temperatures, tool selection, head position, mix ratio, mesh bed
compensation height map etc. are restored from the saved values and printing is
resumed.

M917: Set motor standstill current reduction

M917: Sets the percentage of the current set by M906 that is to be used when the
motor is stationary but not idle, or moving very slowly.

M918: Configure direct-connect display

M918: Configures RepRapFirmware for a directly-connected LCD such as a 12864


or compatible display.

M929: Start/stop event logging to SD card

M929: When event logging is enabled, important events such as power up,
start/finish printing and (if possible) power down will be logged to the SD card.

M950: Create heater, fan, spindle or GPIO/servo pin

M950: Used to create heaters, fans, spindles and GPIO ports, and to configure
parameters.

M951: Set height following mode parameters

M951: Height following mode allows the Z position of the tool to be controlled by
a PID controller using feedback from a sensor. See also M594.
M952: Set CAN-FD expansion board address and/or normal data rate

M952: Expansion boards without address selection switches use a default address.
This command can change the address, and the default data rate.

M953: Set CAN-FD bus fast data rate

M953: Allows the bandwidth of the CAN bus to be optimised, by increasing the
data rate during transmission of CAN-FD data packets by means of the BRS (bit
rate switch) feature.

M954: Configure as CAN expansion board

M954: Used to reconfigure the board it is executed on as a CAN-connected


expansion board.

M955: Configure Accelerometer

M955: Configures an accelerometer with specified parameters such as pins,


orientation, sample rate, resolution, SPI clock frequency.

M956: Collect accelerometer data and write to file

M956: Causes the specified number of accelerometer samples to be collected and


saved to a .csv file on the internal SD card.

M957: Raise event

M957: Raises an event internally, based on the given parameters, as if the event
had actually occurred, and executes any related handler macro for that event.

M997: Perform in-application firmware update

M997: Triggers a firmware update if the necessary files are present on the SD card.
Can update firmware on Duet mainboards, Duet 3 CAN-connected expansion
boards, WiFi modules and PanelDue.
M998: Request resend of line

M998: Request a resend of the specified line of Gcode.

M999: Restart

M999: Restarts the firmware using a software reset. Can also reboot attached SBC.

T: Select Tool
Parameters

 nnn: Tool number to select. A negative number deselects all tools.

 R1: Select the tool that was active when the print was last paused (firmware 1.20
and later)

 Pnnn: Bitmap of all the macros to be run (dc42 build 1.19 or later and ch fork
1.17b or later)

 Tool number

Example

 T0 ; select tool 0

 T1 P0 ; select tool 1 but don't run any tool change macro files

 T-1 P0 ; deselect all tools but don't run any tool change macro files

 T R1 ; select the tool that was active last time the print was paused

 T ; report the current tool number

If Tn is used to select tool n but that tool is already active, the command does
nothing. Otherwise, the sequence followed is:

Note: Prior to RRF 3.3, when changing tools, tool change macro files are not run
unless all axes have been homed. In RRF 3.3 and later, tool change macro files are
now run regardless of whether axes have been homed or not. You can use
conditional GCode to choose which commands are executed if axes have been
homed/not homed.

1. If another tool is already selected, run macro tfree#.g where # is the number of
that tool.

2. If another tool is already selected, deselect it and set its heaters to their standby
temperatures (as defined by the R parameter in the most recent G10/M568
command for that tool)

3. Run macro tpre#.g where # is the number of the new tool

4. Set the new tool to its operating temperatures specified by the S parameter in
the most recent G10/M568 command for that tool

5. Run macro tpost#.g where # is the number of the new tool. Typically this file
would contain at least a M116 command to wait for its temperatures to
stabilise.

6. Apply any X, Y, Z offset for the new tool specified by G10/M568

7. Use the new tool.

Selecting a non-existent tool (49, say) just does Steps 1-2 above1. That is to say it
leaves the previous tool in its standby state. You can, of course, use the G10/M568
command beforehand to set that standby temperature to anything you like.

After a reset tools will not start heating until they are selected. You can either put
them all at their standby temperature by selecting them in turn, or leave them off
so they only come on if/when you first use them. The M0, M1 and M112
commands turn them all off. You can, of course, turn them all off with the M1
command, then turn some back on again. Don't forget also to turn on the heated
bed (if any) if you use that trick.

Tool numbering starts at 0 by default however M563 allows the user to specify tool
numbers, so with them you can have tools 17, 29 and 48 if you want. Negative
numbers are not allowed. The highest Tool number that can be defined from RRF3
onwards is 49
Starting from RRF 3.3beta2 both selecting as well as deselecting with a configured
spindle will stop the spindle assigned to these tools. This is in accordance to NIST
GCode standard that says "after a tool change is complete the spindle is stopped".

Notes

1
Selecting a non-existent tool also removes any X/Y/Z offset applied for the old
tool.

2
Under special circumstances, the execution of those macro files may not be
desired. RepRapFirmware 1.19 or later supports an optional P parameter to specify
which macros shall be run. If it is absent then all of the macros above will be run,
else you can pass a bitmap of all the macros to be executed. The bitmap of this
value consists of tfree=1, tpre=2 and tpost=4.

3
You may wish to include a move to a parking position 'within the tfreeN.g gcode
macro in order to allow the new extruder to reach temperature while not in contact
with the print.

4
Tool offsets are applied whenever there is a current tool. So they are applied in
tfree.g (for the outgoing tool) and in tpost.g (for the incoming tool), but not in
tpre.g (because no tool is current at that point).

G-Code Background Information


Codes for print head movements follow the http://www.nist.gov/manuscript-
publicati..., so RepRapFirmware should be usable for CNC milling and similar
applications but be aware of the G-Codes not implemented. See also
on https://en.wikipedia.org/wiki/G-code.

For more information and background, along with the master list of all RepRap G-
Codes check the http://reprap.org/wiki/G-code.

For the technically minded, G-Code line endings are Unix Line Endings (\n), but will
accept Windows Line Endings (\r\n), so you should not need to worry about
converting between the two, but it is best practice to use Unix Line Endings where
possible.

Replies from the RepRap machine to the host computer

All communication is in printable ASCII characters. Messages sent back

to the host computer are terminated by a newline and look like this:

xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5]
[Some debugging or other information may be here]

xx can be one of:

ok

rs

!!

ok means that no error has been detected.

rs means resend, and is followed by the line number to resend.

!! means that a hardware fault has been detected. The RepRap machine will

shut down immediately after it has sent this message.

The T: and B: values are the temperature of the currently-selected extruder

and the bed respectively, and are only sent in response to M105. If such
temperatures don't exist (for example for an extruder that works at room
temperature and doesn't have a sensor) then a value below absolute zero (-273oC)
is returned.
C: means that coordinates follow. Those are the X: Y: etc values. These are only

sent in response to M114 and M117.

The RepRap machine may also send lines that look like this:

// This is some debugging or other information on a line on its own. It may be


sent at any time.

Such lines will always be preceded by //.

On the latest version of Pronterface and Octoprint (1.2.0+) a special comment of


the form:

// action:command

is allowed to be sent from the firmware, the command can currently be pause,
resume or disconnect which will execute those commands on the host.

As this is also a comment other hosts will just ignore these commands.

The most common response is simply:

ok

When the machine boots up it sends the string

start

once to the host before sending anything else. This should not be replaced or
augmented

by version numbers and the like. M115 (see above) requests those.
All this means that every line sent by RepRap to the host computer except the start
line has a two-character prefix (one of ok, rs, !! or //). The machine should never
send a line without such a prefix.

Exceptions:

RepRapFirmware responds to some commands with a reply string in JSON format,


terminated by a newline. This allows later firmware revisions to include additional
information without confusing clients (e.g. PanelDue) that do not expect it, and to
make responses self-describing so that the client will not be confused if responses
are delayed or lost. The commands affected are:

 M20 S2

 M36

 M408

Slicer Start and End G-Codes

Slicers will optionally add G-Code scripts to the beginning and end of their output
file to perform specified actions before and/or after a print such as z-probing the
build-area, heating/cooling the bed and hotend, performing ooze free "nozzle
wipe" startup routine, switching system power on/off, and even "ejecting" parts. For
general information and examples (not specific to RepRapFirmware) there is more
info on
the https://reprap.org/wiki/Start_GCode_rout... and https://reprap.org/wiki/End_GC
ode_routin... pages.

You might also like