This page tries to describe the flavour of G-codes that the RepRap firmwares use and how they work. The main target is additive fabrication using FFF processes. Codes for print head movements follow the NIST RS274NGC G-code standard, so RepRap firmwares are quite usable for CNC milling and similar applications, too. See also on Wikipedia's G-code article.

There are a few different ways to prepare GCode for a printer. One is to use a slicer like Slic3r, Skeinforge or Cura. These programs take a CAD model, slice it into layers, and output the GCode required for each layer. Slicers are the easiest way to go from a 3D model to a printed part, but the user sacrifices some flexibility when using them. Another option for GCode generation is to use a lower level library like mecode. Libraries like mecode give you precise control over the tool path, and thus are useful if you have a complex print that is not suitable for naive slicing. The final option is to just write the GCode yourself. This may be the best choice if you just need to run a few test lines while calibrating your printer.

As many different firmwares exist and their developers tend to implement new features without discussing strategies or looking what others did before them, a lot of different sub-flavours for the 3D-Printer specific codes developed over the years. But this is the master page for RepRap. Nowhere in here should the same code be used for two different things; there are always more numbers to use... The rule is: add your new code here, then implement it.

But human nature being what it is, things aren't always done that way, so some multiple uses of the same code exist. The rule is that later appearances by them on this page than the original use of a code are deprecated and should be changed, unless there is a good technical reason (like the general G-Code standard) why a later instance should be prefered. Note that the key date is appearance here, not date of implementation.

Introduction

Gcode can also be stored in files on SD cards. A file containing RepRap Gcode usually has the extension .g, .gco or .gcode.
Files for BFB/RapMan have the extension .bfb.
Gcode stored in file or produced by a slicer might look like this:

G92 E0
G28
G1 F1500
G1 X2.0 Y2.0 F3000
G1 X3.0 Y3.0

The meaning of all those symbols and numbers (and more) is explained below.

To find out which specific Gcode(s) are implemented in any given firmware, there are little tables attached to the command descriptions, like this one:

There is some support for the Gcode. Often it is required to check out the source code branch for the firmware (usually stored in a different branch) or to flip configuration switches on the mainboard.

automatic

The firmware handles this Gcode automatically, so there's no need to send the command. An example is power supply on/off Gcode (M80/M81) in the Teacup firmware.

???

It is unknown if the firmware supports this Gcode. You may want to test this yourself before using it in production.

The firmware depreciated this Gcode. The firmware author(s) should amend the depreciated Gcode on this page with workarounds (if needed) and the last supported firmware version that will accept this Gcode.

For the technically minded, Gcode 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.

Fields

A RepRap Gcode 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.

Letter

Meaning

Gnnn

Standard GCode command, such as move to a point

Mnnn

RepRap-defined command, such as turn on a cooling fan

Tnnn

Select tool nnn. In RepRap, tools are 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.

Innn

Parameter - X-offset in arc move; integral (Ki) in PID Tuning

Jnnn

Parameter - Y-offset in arc move

Dnnn

Parameter - used for diameter; derivative (Kd) in PID Tuning

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 extrudate. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.

Nnnn

Line number. Used to request repeat transmission in the case of communications errors.

*nnn

Checksum. Used to check for communications errors.

Comments

Gcode comments begin at a semicolon, and end at the end of the line:

N3 T0*57 ; This is a comment
N4 G92 E0*67
; So is this
N5 G28*22

Comments and white space will be ignored by your RepRap Printer. It's better to strip these out on the host computer before sending the Gcode to your printer, as this saves bandwidth.

Checking

The RepRap 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.

The checksum "cs" for a GCode 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:

Buffering

If buffering is supported, the RepRap firmware 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 acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.

Typically, the following moving commands are buffered: G0-G3 and G28-G32. The Teacup Firmware buffers also some setting commands: G20, G21, G90 and G91. All other G, M or T commands are not 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. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.

Ennn The amount to extrude between the starting point and ending point

Fnnn The feedrate per minute of the move between the starting point and ending point (if supplied)

Snnn Flag to check if an endstop was hit (S1 to check, S0 to ignore, S2 see note, default is S0)1

Examples

G0 X12 (move to 12mm on the X axis)

G0 F1500 (Set the feedrate to 1500mm/minute)

G1 X90.6 Y13.8 E22.4 (Move to 90.6mm on the X axis and 13.8mm on the Y axis while extruding 22.4mm of material)

The RepRap firmware spec treats G0 and G1 as the same command, since it's just as efficient as not doing so.2

Most RepRap firmwares do subtle things with feedrates.

1. G1 F1500
2. G1 X50 Y25.3 E22.4

In the above example, we set the feedrate to 1500mm/minute on line 1, then move to 50mm on the X axis and 25.3mm on the Y axis while extruding 22.4mm of filament between the two points.

1. G1 F1500
2. G1 X50 Y25.3 E22.4 F3000

However, in the above example, we set a feedrate of 1500 mm/minute on line 1, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X and Y movement, so everything stays synchronized.

The RepRap spec treats the feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over the acceleration and deceleration of the printer head in such a way that ensures that everything moves smoothly together, and the right volume of material is extruded at all points.3

To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G0 or G1 to send an E value that is less than the currently extruded length.

Notes

1Some firmwares allow for the RepRap to enable or disable the "sensing" of endstops during a move. Please check with whatever firmware you are using to see if they support the S parameter in this way, as damage may occur if you assume incorrectly. In the dc42 fork of RepRapFirmware, using the S1 or S2 parameter on a delta printer causes the XYZ parameters to refer to the individual tower motor positions instead of the head position, and to enable endstop detection as well if the parameter is S1.

2In the RS274NGC Spec, G0 is Rapid Move, which was used to move between the current point in space and the new point as quickly and efficiently as possible, and G1 is Controlled Move, which was used to move between the current point in space and the new point as precise as possible.

3Some firmwares may not support setting the feedrate inline with a move.

4zpl and dc42 forks of RepRapFirmware implement an additional 'R1' parameter to tell the machine to go back to the coordinates a print was originally paused at.

Some older machines, CNC or otherwise, used to move faster if they did not move in a straight line. This is also true for some non-Cartesian printers, like delta or polar printers, which move easier and faster in a curve.

Innn The point in X space from the current X position to maintain a constant distance from

Jnnn The point in Y space from the current Y position to maintain a constant distance from

Ennn The amount to extrude between the starting point and ending point

Fnnn The feedrate per minute of the move between the starting point and ending point (if supplied)

Examples

G2 X90.6 Y13.8 I5 J10 E22.4 (Move in a Clockwise arc from the current point to point (X=90.6,Y=13.8), with a center point at (X=current_X+5, Y=current_Y+10), extruding 22.4mm of material between starting and stopping)

G3 X90.6 Y13.8 I5 J10 E22.4 (Move in a Counter-Clockwise arc from the current point to point (X=90.6,Y=13.8), with a center point at (X=current_X+5, Y=current_Y+10), extruding 22.4mm of material between starting and stopping)

G10: Tool Offset

This sets the offset for tool (or in older implementations extrude head) 3 (from the P3) to the X and Y values specified. You can put a non-zero Z value in as well, but this is usually a bad idea unless the tools are loaded and unloaded by some sort of tool changer. When all the tools are in the machine at once they should all be set to the same Z height.

Remember that any parameter that you don't specify will automatically be set to the last value for that parameter. That usually means that you want explicitly to set Z0.0.

The R value is the standby temperature in oC that will be used for the tool, and the S value is its operating temperature. If you don't want the tool to be at a different temperature when not in use, set both values the same. See the T code (select tool) below. In tools with multiple heaters the temperatures for them all are specified thus: R100.0:90.0:20.0 S185.0:200.0:150.0 .

Note that Marlin and Smoothie use G10/G11 for executing a retraction/unretraction move. The RepRapPro version of Marlin supports G10 for tool offset.

Duet-zpl allows tool heaters to be switched off if the absolute negative temperature (-273.15) is passed as active and standby temperature. In this case the current active and standby temperatures are not affected.

When the RepRap firmware receives this command, it moves all (or the supplied) axis's back to the zero endstops as quickly as it can, then backs off by a millimeter and slowly moves back to the zero endstop activation points to increase position accuracy. This process is also known as "Homing".

If you add coordinates, these coordinates are ignored. For example, G28 Z0.00 results in the same behaviour as G28 Z.

When Duet-dc42 firmware is used to control a delta printer, any G28 command will home all three towers, regardless of any XYZ letters.

G30: Single Z-Probe

Some implementations allow more general behaviour: if a Pn field is specified the probed X, Y, and Z values are saved as point n on the bed for calculating the offset plane. Generally n is 0, 1, or 2. If X, or Y, or Z values are specified (e.g. G30 P1 X20 Y50 Z0.3) then those values are used instead of the machine's current coordinates. A silly Z value (less than -9999.0) causes the machine to probe at the current point to get Z, rather than using the given value. If an S field is specified (e.g. G30 P1 Z0.3 S) the bed plane is computed for compensation and stored. The combination of these options allows for the machine to be moved to points using G1 commands, and then probe the bed, or for the user to position the nozzle interactively and use those coordinates. The user can also record those values and place them in a setup GCode file for automatic execution.

The dc42 variant of RepRapFirmware uses the value of the S parameter to specify what computation to perform. If the value is -1 then the Z offsets of all the points probed are printed, but no calibration is done. If the value is zero or not present, then this specified that the number of factors to be calibrated is the same as the number of points probed. Otherwise, the value indicates the number of factors to be calibrated, which must be no greater than the number of points probed. Currently (as of version 1.04d), the number of factors may be 3, 4 or 5 when doing auto bed compensation on a Cartesian or CoreXY printer, and 3, 4, 6 or 7 when doing auto calibration of a Delta printer.

G31: Report Current Probe status

When used on its own this reports whether the Z probe is triggered, or gives the Z probe value in some units if the probe generates height values. If combined with a Z and P field (example: G31 P312 Z0.7) this will set the Z height to 0.7mm when the Z-probe value reaches 312 when a G28 Z0 (zero Z axis) command is sent. The machine will then move a further -0.7mm in Z to place itself at Z = 0. This allows non-contact measuring probes to approach but not touch the bed, and for the gap left to be allowed for. If the probe is a touch probe and generates a simple 0/1 off/on signal, then G31 Z0.7 will tell the RepRap machine that it is at a height of 0.7mm when the probe is triggered.

In Duet-dc42 firmware, separate G31 parameters may be defined for probe types 0, 1/2, and 3 (probe types 1 and 2 share the same set of parameters). To specify which probe you are setting parameters for, send a M558 command to select the probe type before sending the G31 command.

Duet-dc42 firmware supports additional parameters S (bed temperature in degC at which the specified Z parameter is correct, default is current bed temperature) and C (temperature coefficient of Z parameter in mm/degC, default zero). This is useful for ultrasonic and other probes that are affected by temperature.

Duet-dc42 firmware versions 1.00b onwards also allow the X and Y offsets of the Z probe relative to the print head (i.e. the position when the empty tool is selected) to be specified, by adding parameters X and Y. This allows you to calculate your M557 probe coordinates based on the geometry of the bed, without having to correct them for Z probe X and Y offset. It also provides more accurate bed compensation.

G32: Probe Z and calculate Z plane

Probes the bed at 3 or more pre-defined points (see M557) and updates transformation matrix for bed leveling compensation. Later versions of RepRapFirmware execute macro file bed.g if present instead of using the M557 coordinates.

Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.

A G92 without coordinates will reset all axes to zero.

G93: Feed Rate Mode (Inverse Time Mode) (CNC specific)

G93 is Inverse Time Mode. In inverse time feed rate mode, an F word means the move should be completed in (one divided by the F number) minutes.
For example, if the F number is 2.0, the move should be completed in half a minute.

When the inverse time feed rate mode is active, an F word must appear on every line which has a G1, G2, or G3 motion, and an F word on a line that does not have G1, G2, or G3 is ignored. Being in inverse time feed rate mode does not affect G0 (rapid move) motions.

G94: Feed Rate Mode (Units per Minute) (CNC specific)

G94 is Units per Minute Mode. In units per minute feed mode, an F word is interpreted to mean the controlled point should move at a certain number of inches per minute, millimeters per minute, or degrees per minute, depending upon what length units are being used and which axis or axes are moving.

G130: Set digital potentiometer value

Set the digital potentiometer value for the given axes. This is used to configure the current applied to each stepper axis. The value is specified as a value from 0-127; the mapping from current to potentimeter value is machine specific.

The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M1, M112.

The Marlin Firmware does wait for user to press a button on the LCD, or a specific time.
"M0 P2000" waits 2000 milliseconds
"M0 S2" waits 2 seconds

M1: Sleep or Conditional stop

The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can still be sent G and M codes, the first of which will wake it up again. See also M0, M112.

Note that some firmwares list file names in upper case, but - when sent to the M23 command (below) they must be in lower case. Teacup has no such trouble and accepts both.

Duet-dc42 firmware returns the (long) filenames in the correct case. If the S2 parameter is present, the file list is returned in JSON format as a single array called "files", and the directory is returned in variable "dir". The optional P parameter specifies the directory to list, defaulting to the /gcodes directory in RepRapFirmware - for other firmware, this is whatever directory printable gcode files are normally stored in.

M24: Start/resume SD print

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. To restart a file from the beginning, use M23 to reset it, then M24.

When this command is used to resume a print that was paused, the dc42 and zpl forks of RepRapFirmware run macro file resume.g if it exists prior to resuming the print.

{"err":0,"size":457574,"height":4.00,"layerHeight":0.25,"filament":[6556.3],"generatedBy":"Slic3r 1.1.7 on 2014-11-09 at 17:11:32"}

The "err" field is zero if successful, nonzero if the file was not found or an error occurred while processing it. The "size" field should always be present if the operation was successful. The presence or absence of other fields depends on whether the corresponding values could be found by reading the file. The "filament" field is an array of the filament lengths required from each spool. The size is in bytes, all other values are in mm. The fields may appear in any order, and additional fields may be present.

If the file name parameter is not supplied and a file on the SD card is currently being printed, then information for that file is returned including additional field "fileName". This feature is used by the web interface any by PanelDue, so that if a connection is made when a file is already being printed, the name and other information about that file can be shown.

M37: Simulation mode

Used to switch between printing mode and simulation mode. Simulation mode allows the electronics to compute an accurate printing time, taking into account the maximum speeds, accelerations etc. that are configured.

M37 S1 enters simulation mode. All G and M codes will not be acted on, but the time they take to execute will be calculated.

M37 S0 leaves simulation mode.

M37 with no S parameter prints the time taken by the simulation, from the time it was first entered using M37 S1, up to the current point (if simulation mode is still active) or the point that the simulation was ended (if simulation mode is no longer active).

M40: Eject

If your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).

See also M240 and M241 below.

M41: Loop

If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:

When you press the reset button,

When the build material runs out (if your RepRap is set up to detect this), and

M43: Stand by on material exhausted

If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.

M73: Set build percentage

Instruct the machine that the build has progressed to the specified percentage. The machine is expected to display this on it's interface board. If the percentage is exactly 0, then a Build Start Notification is sent. If the percentage is exactly 100, then a Build End notification is sent.

M84: Stop idle hold

Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.

On Marlin, Repetier and Duet-zpl, M84 can also be used to configure or disable the idle timeout. For example, "M84 S10" will idle the stepper motors after 10 seconds of inactivity. "M84 S0" will disable idle timeout; steppers will remain powered up regardless of activity.

M98: Call Macro/Subprogram

Runs the macro in the file mymacro.g. In conventional G Codes for CNC machines the P parameter normally refers to a line number in the program itself (P2000 would run the Macro starting at line O2000, say). For RepRap, which almost always has some sort of mass storage device inbuilt, it simply refers to the name of a GCode file that is executed by the G98 call. That GCode file does not need to end with an M99 (return) as the end-of-file automatically causes a return. Macro calls cannot usually be nested or be recursive; i.e. you can't call a macro from a macro (though some implementations may allow this).

RepRapFirmware-dc42 and RepRapFirmware-zpl support nested macros and allow the filename to include a path. The default folder is /sys.

Allows programming of axis hysteresis. Mechanical pulleys, gears and threads can have hysteresis when they change direction. That is, a certain number of steps occur before movement occurs. You can measure how many mm are lost to hysteresis and set their values with this command. Every time an axis changes direction, these extra mm will be added to compensate for the hysteresis.

M104: Set Extruder Temperature

Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). Duet-dc42 and other firmware also supports the optional T parameter (as generated by slic3r) to specify which tool the command applies to. See also M109.

This is deprecated because temperatures should be set using the G10 and T commands (q.v.).

M104 in Teacup Firmware

In Teacup Firmware, M104 can be additionally used to handle all devices using a temperature sensor. It supports the additional P parameter, which is a zero-based index into the list of sensors in config.h. For devices without a temp sensor, see M106.

Example: M104 P1 S100

Set the temperature of the device attached to the second temperature sensor to 100 °C.

M105: Get Extruder Temperature

Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks like:

Duet-dc42 extension

Duet-dc42 firmware returns a JSON-formatted response if parameter S2 or S3 is included. This is used by the touch-screen control panel. Additionally, parameter Rnn may be provided, where nn is the sequence number of the most recent G-code response that the client has already received.

The response comprises a single JSON object, with no nesting of objects or arrays, followed by newline. It is similar to the object returned by the web interface status request, but some fields are omitted. Here is a sample response when S2 is used:

status: I=idle, P=printing from SD card, S=stopped (i.e. needs a reset), C=running config file, A=paused, D=pausing, R=resuming, B=busy (running a macro)
heaters: current heater temperatures, numbered as per the machine (typically, heater 0 is the bed)
active: active temperatures of the heaters
standby: standby temperatures of the heaters
hstat: status of the heaters, 0=off, 1=standby, 2=active, 3=fault
pos: the X, Y and Z positions of the print head
extr: the positions of the extruders
sfactor: the current speed factor (see M220 command)
efactor: the current extrusion factors (see M221 command)
tool: the selected tool number. Zero typically means no tool selected.
probe: the Z-probe reading
fanRPM: the cooling fan RPM
homed: the homed status of the X, Y and Z axes (or towers on a delta). 0=axis has not been homed so position is not reliable, 1=axis has been homed so position is reliable.
fraction_printed: the fraction of the file currently being printed that has been read and at least partially processed.
message: the message to be displayed on the screen (only present if there is a message to display)
timesLeft: an array of the estimated remaining print times (in seconds) calculated by different methods. These are currently based on the proportion of the file read, the proportion of the total filament consumed, and the proportion of the total layers already printed. Only present if a print from SD card is in progress.
seq: the sequence number of the most recent G-code response or error message. Only present if the R parameter was provided and the current sequence number is greater.
resp: the most recent G-code response or error message. Only present if the R parameter was provided and the current sequence number is greater.

The response when S3 is used comprises these fields plus some additional ones that do not generally change and therefore do not need to be fetched as often. The extra fields include:

myName: the name of the printer
geometry: one of "cartesian", "delta", "corexy, "corexz" etc.

The fields may be in any order in the response. Other implementations may omit fields and/or add additional fields.

M106 in Duet Firmware

Duet-dc42 firmware also supports an optional I parameter. If this parameter is present and greater than zero, the cooling fan output is inverted. This makes the cooling fan output suitable for feeding the PWM input of a 4-wire fan via a diode. If the parameter is present and zero or negative, the output is not inverted. If the parameter is not present, the inverted/non-inverted state remains unchanged. The default at power up is not inverted.

If the 'R' parameter is passed when using Duet-zpl firmware (0.96g+), the last-known fan value will be set. If the 'S' parameter is passed along with 'R', the firmware will not reset the last-known fan value. This may be useful for tool change macro files.

M106 in Teacup Firmware

Additionally to the above, Teacup Firmware uses M106 to control general devices. It supports the additional P parameter, which is an zero-based index into the list of heaters/devices in config.h.

Example: M106 P2 S255

Turn on device #3 at full speed/wattage.

Note: When turning on a temperature sensor equipped heater with M106 and M104 at the same time, temperature control will override the value given in M106 quickly.

For firmware that supports ethernet and web interfaces M111 S9 will turn web debug information on without changing any other debug settings, and M111 S8 will turn it off. Web debugging usually means that HTTP requests will be echoed to the USB interface, as will the responses.

M112: Emergency Stop

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 on the master microcontroller. See also M0 and M1.

M113: Set Extruder PWM

Set the PWM for the currently-selected extruder. On its own this command
sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:

M113 S0.7

it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.

This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.

M116: Wait

Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.

Duet-dc42 firmware version 0.78c and later supports an optional P parameter, used to specify a tool number. If this parameter is present, then the system only waits for temperatures associated with that tool to arrive at their set values. This is useful during tool changes, to wait for the new tool to heat up without necessarily waiting for the old one to cool down fully.

Users of Duet-zpl may specify a list of the heaters to be waited for by specifying an 'H' parameter. Duet-zpl v1.08d+ further supports an additional 'C' parameter to wait for the chamber temperature to be reached.

M117: Get Zero Position

This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)

M120: Push

Push the state of the RepRap machine onto a stack. Exactly what variables get pushed depends on the implementation (as does the depth of the stack - a typical depth might be 5). A sensible minimum, however, might be

Teacup's PID proportional units are in pwm/255 counts per quarter C, so to convert from counts/C, you would divide by 4. Conversely, to convert from count/qC to count/C, multiply by 4. In the above example, S=8 represents a Kp=8*4=32 counts/C.

Teacup's PID integral units are in pwm/255 counts per (quarter C*quarter second), so to convert from counts/qCqs, you would divide by 16. Conversely, to convert from count/qCqs to count/Cs, multiply by 16. In the above example, S=0.5 represents a Ki=0.5*16=8 counts/Cs.

Teacup's PID derivative units are in pwm/255 counts per (quarter degree per 2 seconds), so to convert from counts/C, you would divide by 4. Conversely, to convert from count/qC to count/C, multiply by 8. In the above example, S=24 represents a Kd=24*8=194 counts/(C/s).

M132 in MakerBot

Example: M132 X Y Z A B

Loads the axis offset of the current home position from the EEPROM and waits for the buffer to empty.

Teacup's PID integral limit units are in quarter-C*quarter-seconds, so to convert from C-s, you would multiply by 16. Conversely, to convert from qC*qs to C*s, divide by 16. In the above example, S=264 represents an integral limit of 16.5 C*s.

M133 in MakerBot

Example: M133 T0 P500

Instruct the machine to wait for the toolhead to reach its target temperature. T is the extruder to wait for. P if present, sets the time limit.

M140: Set Bed Temperature (Fast)

Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed). There is an optional R field that sets the bed standby temperature: M140 S65 R40.

Duet-zpl allows the bed heater to be switched off if the absolute negative temperature (-273.15) is passed as active temperature. In this case the current active temperature is not affected:

M200: Set filament diameter

Without parameters loads default grid, and with specified extension attempts to load the specified grid. If not available will not modify the current grid.
If Z was saved with the grid file, it will load the saved Z with the grid.

Question: what does a firmware do with filament diameter? Has this an effect on how much an E command moves the extruder motor? --Traumflug 11:34, 14 October 2012 (UTC) Yes, Marlin uses this to set a 'volumetric_multiplier' by which the E-steps of a move are scaled in the planner. DaveX (talk) 16:44, 12 April 2014 (PDT)
Smoothie implements the same thing as Marlin --Arthurwolf (talk) 05:23, 10 November 2014 (PST)

M201: Set max printing acceleration

Sets the acceleration that axes can do in units/second^2 for print moves. For consistency with the rest of G Code movement this should be in units/(minute^2), but that gives really silly numbers and one can get lost in all the zeros. So for this we use seconds.

M207: Calibrate z axis by detecting z max length

After placing the tip of the nozzle in the position you expect to be considered Z=0, issue this command to calibrate the Z axis. It will perform a z axis homing routine and calculate the distance traveled in this process. The result is stored in EEPROM as z_max_length. For using this calibration method the machine must be using a Z MAX endstop.

This procedure is usually more reliable than mechanical adjustments of a Z MIN endstop.

M208: Set axis max travel

The values specified set the software limits for axis travel in the positive direction.

With Marlin firmware, this value can be saved to EEPROM using the M500 command.

With Duet-dc42 firmware, on a Cartesian printer you can also use this command to specify software limits for axis travel in the negative direction, by adding parameter S1. The axis limits you set are also the positions assumed when an endstop is triggered.

M226: Gcode Initiated Pause

Initiates a pause in the same way as if the pause button is pressed. That is, program execution is stopped and the printer waits for user interaction. This matches the behaviour of M1 in the NIST RS274NGC G-code standard and M0 in Marlin firmware.

M227: Enable Automatic Reverse and Prime

"Reverse and Prime" means, the extruder filament is retracted some distance when not in use and pushed forward the same amount before going into use again. This shall help to prevent drooling of the extruder nozzle. Teacup firmware implements this with M101/M103.

Play beep sound, use to notify important events like the end of printing. See working example onR2C2 electronics. Also supported by duet-dc42 firmware via the sounder on the add-on touch screen control panel.

Marlin

Hot end only; see M304 for bed PID. H is the heater number, default 1 (i.e. first extruder heater).

Duet-dc42 and RepRapFirmware (v1.09 onwards)

H: Is the heater number, and is compulsory. H0 is the bed, H1 is the first hot end, H2 the second etc.
P: Interprets a negative P term as indicating that bang-bag control should be used instead of PID (not recommended for the hot end, but OK for the bed heater).
I: Integral value
D: Derivative value
T: Is the approximate additional PWM (on a scale of 0 to 255) needed to maintain temperature, per degree C above room temperature. Used to preset the I-accumulator when switching from heater fully on/off to PID.
S: PWM scaling factor, to allow for variation in heater power and supply voltage. Is designed to allow a correction to be made for a change in heater power and/or power supply voltage without having to change all the other parameters. For example, an S factor of 0.8 means that the final output of the PID controller should be scaled to 0.8 times the standard value, which would compensate for a heater that is 25% more powerful than the standard one or a supply voltage that is 12.5% higher than standard.
W: Wind-up. Sets the maximum value of I-term, must be high enough to reach 245C for ABS printing.
B: PID Band. Errors larger than this cause heater to be on or off.

An example using all of these would be:

M301 H1 P20 I0.5 D100 T0.4 S1 W180 B30

Smoothie

S0 is 0 for the hotend, and 1 for the bed, other numbers may apply to your configuration, depending on the order in which you declare temperature control modules.

Other implementations

W: Wind-up. Sets the maximum value of I-term, so it does not overwhelm other PID values, and the heater stays on. (Check firmware support - Sprinter, Marlin?) Example:

M301 W125

Teacup

See M130, M131, M132, M133 for Teacup's codes for setting the PID parameters.

M303: Run PID tuning

PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed (E-1). Send the appropriate code and wait for the output to update the firmware.

Hot end usage:

M303 S<temperature> C<cycles>

Bed usage:

M303 E-1 C<cycles> S<temperature>

Example:

M303 C8 S175

Smoothie's syntax, where E0 is the first temperature control module (usually the hot end) and E1 is the second temperature control module (usually the bed):

Sets Proportional, Integral and Derivative values for bed. Duet-dc42 firmware interprets a negative P term as indicating that bang-bag control should be used instead of PID. In Duet-dc42 firmware, this command is identical to M301 except that the H parameter (heater number) defaults to zero.

M304 in RepRapPro version of Marlin: Set thermistor values

In the RepRapPro version of Marlin ( https://github.com/reprappro/Marlin ) M304 is used to set thermistor values (as M305 is in later firmwares). RRP Marlin calculates temperatures on the fly, rather than using a temperature table. M304 Sets the parameters for temperature measurement.

Example: M304 H1 B4200 R4800 T100000

This tells the firmware that for heater 1 (H parameter: 0 = heated bed, H = first extruder), the thermistor beta (B parameter) is 4200, the thermistor series resistance (R parameter) is 4.8Kohms, the thermistor 25C resistance (T parameter) is 100Kohms. All parameters other than H are optional. If only the H parameter is given, the currently-used values are displayed. They are also displayed within the response to M503.

M305: Set thermistor and ADC parameters

Sets the parameters for temperature measurement. Supported by RepRapFirmware from 0.78c, and Duet-dc42 firmware.

Example: M305 P1 T100000 R1000 B4200

This tells the firmware that for heater 1 (P parameter: 0 = heated bed, 1 = first extruder) the thermistor 25C resistance (T parameter) is 100Kohms, the thermistor series resistance (R parameter) is 1Kohms, the thermistor beta (B parameter) is 4200. All parameters other than P are optional. If only the P parameter is given, the existing values are displayed.

M360: Move to Theta 0 degree position

The arms move into a position where the Theta steering arm is parallel to the top platform edge. The user then calibrates the position by moving the arms with the jog buttons in software like pronterface until it is perfectly parallel. Using M114 will then display the calibration offset that can then be programmed into the unit using M206 (Home offset) X represents Theta.

Smoothieware: M360 P0 will take the current position as parallel to the platform edge, and store the offset in the homing trim offset (M666) No further user interaction is needed.

M361: Move to Theta 90 degree position

Theta move to 90 degrees with platform edge. User calibrates by using jog arms to place exactly 90 degrees. Steps per degree can then be read out by using M114, and programmed using M92. X represents Theta. Program Y (Psi) to the same value initially. Remember to repeat M360 after adjusting steps per degree.

Smoothieware: M360 P0 will accept the current position as 90deg to platform edge. New steps per angle is calculated and entered into memory (M92) No further user interaction is required, except to redo M360.

M364: Move to Psi + Theta 90 degree position

Move arms to form a 90 degree angle between the inner and outer Psi arms. Calibrate by moving until angle is exactly 90 degree. Read out with M114, and calibrate value into Home offset M206. Psi is represented by Y.

Smoothieware: M364 P0 will accept the current position as 90deg between arms. The offset is stored as a trim offset (M666) and no further user interaction is required except to save all changes via M500

M374: Save calibration grid

Without parameters safes the grid into the default grid file that gets loaded at boot
Parameter specifies the extension of the grid file - useful for special grid files such as for a special print surface like a removable print plate.
Addition of Z will additionally save the M206 Z homing offset into the grid file

Without parameters loads default grid, and with specified extension attempts to load the specified grid. If not available will not modify the current grid.
If Z was saved with the grid file, it will load the saved Z with the grid.

While Marlin only accepts the N parameter, Duet-zpl further allows to specify the nozzle diameter (in mm) via the D-parameter. It is used to properly detect the first layer height when a new print is being started.

M408: Report JSON-style response

Report a JSON-style response by specifying the desired type using the 'S' parameter. For some purposes it is necessary to pass the sequence number, which is why Duet-zpl and Duet-dc42 accept an additional 'P' parameter to specify it.

Example: M408 S0

The following response types are supported:

Type 0 is the M105 S2 response, which is like the new-style status response (for the old web interface) but some fields are omitted.

Type 1 is the M105 S3 response, which is like the M105 S2 response except that static values are also included.

Type 2 is the new-style standard JSON response, which is also reported to the new web interface (see Duet Web Control)

Type 3 is an extended version of type 2 which includes some additional parameters that aren't expected to change very frequently

Type 4 is an extended version of type 2 which may be used to poll for current printer stats

Set the color of your RGB LEDs that are connected to PWM-enabled pins. Note, the Green color is controlled by the E value instead of the G value due to the G code being a primary code that cannot be overridden.

M500: Store parameters in EEPROM

Save current parameters to EEPROM. dc42 and zpl forks of RepRapFirmware allow "S1" to be passed, which forces parameters to be automatically saved to EEPROM when they are changed.

In Redeem any parameters set through G/M-codes which is different than what is read from the config files, are stored back to the local config. For instance setting stepper current and microstepping through M906 and M907 followed by M500 will update /etc/redeem/local.cfg.

M502: Revert to the default "factory settings."

This command resets all tunable parameters to their default values, as set in the firmware. This doesn't reset any parameters stored in the EEPROM, so it must be followed with M501 if you want to do that.

M503: Print settings

This command asks the firmware to reply with the current print settings stored in EEPROM. The reply output includes the G-Code commands to produce each setting. For example, the Steps Per Unit values are displayed as an M92 command.

M540: Set MAC address

Sets the MAC address of the RepRap. This should be done before any other network commands. The MAC address is six one-byte hexadecimal numbers separated by colons. The 0x prefix is optional in later firmware revisions.

M551: Set Password

On machines that need a password to activate them, set that password. The code 'P' is not part of the password. Note that as this is sent in clear it does not (nor is it intended to) offer a very high level of security. But on machines that are (say) on a network, it prevents idle messing about by the unauthorised. The password can contain any printable characters except ';', which still means start comment.

M552: Set IP address

Sets the IP address of the RepRap machine to (in this case) 192.168.1.14. A restart may be required before the new IP address is used. If no P field is specified, this echoes the existing IP address configured. If S0 is added thus: M552 S0 P192.168.1.14 networking is disabled.

M553: Set Netmask

Sets the network mask of the RepRap machine to (in this case) 255.255.255.0. A restart may be required before the new network mask is used. If no P field is specified, this echoes the existing network mask configured.

M554: Set Gateway

Sets the Gateway IP address of the RepRap machine to (in this case) 192.168.1.1. A restart may be required before the new gateway IP address is used. If no P field is specified, this echoes the existing Gateway IP address configured.

Though with care and adjustment a RepRap can be set up with its axes at right-angles to each other within the accuracy of the machine, who wants to bother with care and adjustment when the problem
can be solved by software? This tells software the tangents of the angles between the axes of the machine obtained by printing then measuring a test part. The S parameter (100 here) is the length of a triangle along each axis in mm. The X, Y and Z figures are the number of millimeters of the short side of the triangle that represents how out of true a pair of axes is. The X figure is the error between X and Y, the Y figure is the error between Y and Z, and the Z figure is the error between X and Z. Positive values indicate that the angle between the axis pair is obtuse, negative acute.

M557: Set Z probe point

Set the points at which the bed will be probed to compensate for its plane being slightly out of horizontal. The P value is the index of the point (indices start at 0) and the X and Y values are the position to move extruder 0 to to probe the bed. An implementation should allow a minimum of three points (P0, P1 and P2). This just records the point coordinates; it does not actually do the probing. See G32.

M558: Set Z probe type

A Z probe may be a switch, an IR proximity sensor, or some other device. This selects which to use. P0 indicates that no Z probe is present. P1 gives an unmodulated IR probe, or any other probe type that emulates an unmodulated IR probe (probe output is an analog signal that rises with decreasing nozzle height above the bed). If there is a control signal to the probe, it is driven high when the probe type is P1. P2 specifies a modulated IR probe, where the modulation is commanded directly by the main board firmware using the control signal to the probe. P3 selects an alternative Z probe by driving the control signal to the probe low. P4 selects a switch (on the Duet, this must be connected to the E0 endstop pins).

The X, Y and Z parameters specify whether each axis uses the Z probe for homing or not. If the parameter is nonzero, the Z probe is used for homing that axis. if the parameter is zero, the endstop switch for that axis is used for homing instead. See also G31 and G32.

Duet-dc42 firmware versions 1.00e onwards supports additional parameter H. This specifies the dive height from which probing is done in response to a G30 command when the P parameter is present, or a G32 command.

M559: Upload configuration file

If the RepRap supports it, this uploads a file that is run on re-boot to configure the machine. This file usually is a special G Code file. After sending M559, the file should be sent, ending with an M29 (q.v.).

M560: Upload web page file

For RepRaps that have web support and that can be driven by a web browser, this uploads the file that is the control page for the RepRap. After sending M560 the file (usually an HTML file) should be sent, terminated by the string

<!-- **EoF** -->

. Clearly that string cannot exist in the body of the file, but can be put on the end to facilitate this process. This should not be too serious a restriction...

M562: Reset temperature fault

Reset a temperature fault on heater/sensor 2. If the RepRap has switched off and locked a heater because it has detected a fault, this will reset the fault condition and allow you to use the heater again. Obviously to be used with caution. If the fault persists it will lock out again after you have issued this command. P0 is the bed; P1 the first extruder, and so on.

M563: Define or remove a tool

Tools are usually (though not necessarily) extruders. The P field specifies the tool number. Tool numbers can have any positive integer value and 0. The D field specifies the drive(s) used by the tool - in this case drives 0, 5 and 6. Drive 0 is the first drive in the machine after the movement drives (usually X, Y and Z). If there is no D field the tool has no drives. The H field specifies the tool's heaters - in this case heaters 1 and 3. Heater 0 is usually the hot bed (if any) so the first extruder heater is usually 1. If there is no H field the tool has no heaters.

Tools are driven using multiple values in the E field of G1 commands, each controlling the corresponding drive in the D field above, as follows:

G1 X90.6 Y13.8 E2.24:2.24:15.89
G1 X70.6 E0:0:42.4

The first line moves straight to the point (90.6, 13.8) extruding a total of 2.24mm of filament from both drives 0 and 5 and 15.98mm of filament from drive 6.

The second line moves back 20mm in X extruding 42.4mm of filament from drive 6.

Normally an M563 command is immediately followed by a G10 command to set the tool's offsets and temperatures.

It is permissible for different tools to share some (or all) of their drives and heaters. So, for example, you can define two tools with identical hardware, but that just operate at different temperatures.

If you use the M563 command with a P value for a tool that has already been defined, that tool is redefined using the new values you provide.

Duet-dc42 firmware supports an additional form of the M563 command. The command:

M563 S1

means add 1 (the value of the S parameter) to all tool numbers found in the remainder of the current input stream (e.g. the current file if the command is read from a file on the SD card), or until a new M563 command of this form is executed. The purpose of this is to provide compatibility between the Duet firmware, in which tool numbers typically start at 1, and programs such as slic3r that assume tools are numbered from zero.

Duet-zpl firmware allows the deletion of existing tools if M563 is called in this way:

M563 P1 D-1 H-1

M564: Limit axes

Allow moves outside the print volume, or not. If the S parameter is 0, then you can send G codes to drive the RepRap outside its normal working volume, and it will attempt to do so. User beware... If you set the S parameter to 1 then the RepRap will not think outside the box. The default behaviour is S = 1.

M565: Set Z probe offset

Set the offset from the extruder tip to the probe position. The X, Y and Z values are the delta between the extruder and the actual trigger position of the probe. If the probe trigger point is below the extruder (typical) the Z offset will be negative. This just records the point offset; it does not actually do the probing. See G32.

M566: Set allowable instantaneous speed change

Work around an algorithm limitation of some firmwares, which can't calculate step timings for a standing start. Teacup Firmware and Smoothieware don't have this limitation, so M566 is obsolete there.

M566 sets the speeds in mm/minute that axes can do from a standing start. If an accelerating algorithm starts a move with a zero velocity on other firmwares and then accelerates from that, it can give problems when the zero initial velocity is used to calculate a timestep between stepper pulses at the beginning: the timestep ends up being infinite... So these systems have initial small velocities to start at. This sets them.

The dc42 variant of RepRapFirmware doesn't have the limitation, but instead it uses this parameter to determine the maximum allowable speed change of each motor when cornering.

M567: Set tool mix ratios

The example sets the mix ratio for tool 2 (the P value). When mixing is then turned on (see M568), only single E values need to be sent on a G1 command (any extra E values will be ignored, but are not illegal):

G1 X20 E1.3

This will move to X=20 extruding a total length of filament of 1.3mm. The first drive of tool 2 will extrude 0.1*1.3mm, the second 0.2*1.3mm and so on. The ratios don't have to add up to 1.0 - the calculation done is as just described. But it is best if they do.

M569: Set axis direction values

Set the control value for the drive specified by P that sends it forwards to the given value in the S field. After sending the example, sending a 1 to X (drive 0) will make it go forwards, sending a 0 will make it go backwards. Obviously to be used with extreme caution...

M571: Set output on extrude

This turns an output on whenever extrusion is being done, and turns it off when the extrusion is finished. The output could control a fan or a stirrer or anything else that needs to work just when extrusion is happening. The S parameter sets the value of the PWM to the output. 0.0 is off; 1.0 is fully on.

M572: Set or report extruder elasticity compensation

This sets the compensation time in seconds (S parameter) for Bowden extruder elasticity for the specified drive (P parameter). Supported by Duet-dc42 firmware. It has an effect similar to the EXTRUDER_ADVANCE_K factor in Marlin firmware. Normally, compensation should be applied to extruder drives only (drives 3 and higher).

M573: Report heater PWM

This gives a running average (usually taken over about five seconds) of the PWM to the heater specified by the P field. If you know the voltage of the supply and the resistance of the heater this allows you to work out the power going to the heater.

M574: Set endstop configuration

This defines the type of endstop switch or opto sensor that the printer has for each axis: 0 = none, 1 = low end, 2 = high end. The optional S parameter defines whether the endstop input is active high (S1, the default) or low (S0). Intended for use with boards that provide a single endstop input for each axis that may be used for either a high or a low end endstop, such as the Duet. Supported by Duet-dc42 firmware. On delta printers, the XYZ parameters refer to the towers and the endstops should normally all be high end.

M575: Set serial comms parameters

This sets the communications parameters of the serial comms channel specified by the P parameter. P0 specifies the main serial interface (typically a USB port, or serial-over-USB), while P1 specifies an auxiliary serial port (for example, the port used to connect a PanelDue). The B parameter is the required baud rate (this parameter is typically ignored if the port is a true USB port). The S parameter is a bitmap of features. The lowest bit, if set, specifies that only commands that include a valid checksum should be accepted from this comms channel.

M576: Set axis/extruder drive mapping

This maps each letter to the specified drive number(s). In this example the Z axis configuration consists of two motors that need to be controlled simultaneously. An extra axis 'A' is also defined for cusstom purposes (rotary nozzle, cutter tool etc.) while the remaining axes are mapped to extruder drives.

M600: Set line cross section

Sets the cross section for a line to extrude in velocity extrusion mode. When the extruder is enabled and movement is executed the amount of extruded filament will be calculated to match the specified line cross section.

M605 S0: Full control mode. The slicer has full control over x-carriage movement
M605 S1: Auto-park mode. The inactive head will auto park/unpark without slicer involvement
M605 S2 [Xnnn] [Rmmm]: Duplication mode. The second extruder will duplicate the first with nnn millimeters x-offset and an optional differential hotend temperature of mmm degrees. E.g., with "M605 S2 X100 R2" the second extruder will duplicate the first with a spacing of 100mm in the x direction and 2 degrees hotter.

I don't think it's a good idea to have two different implementations for the same G-code, and I also question the practical value of specifying the print bed radius when defining a delta configuration, since many delta printers use a square or rectangular print bed. So perhaps we should stick to the Marlin-defined command as the definition for this command, and use a different command or set of commands to define print bed shape and size. --AndrewBCN (talk) 23:10, 31 January 2015 (PST)

The implementations are not different, they have the same L and R parameters, but each has additional parameters that are not relevant to the other implementation. I'm not against defining a new Gcode to define bed size and shape; however, you can already define the limits of a rectangular print area using M208. Even when a delta printer has a square bed, the printable area is not square. It is usually taken to be circular, although it is in reality more complicated. My purpose in adding the B parameter was to make it easy to define a radius outside which movement will not normally be attempted. I have changed "bed radius" to "safe printing radius" in the text to help clarify this. --dc42

M667: Select CoreXY mode

M667 S0 selects Cartesian mode (unless the printer is configured as a delta using the M665 command). Forward motion of the X motor moves the head in the +X direction. Similarly for the Y motor and Y axis, and the Z motor and Z axis. This is the default state of the firmware on power up.

M667 S1 selects CoreXY mode. Forward movement of the X motor moves the head in the +X and +Y directions. Forward movement of the Y motor moves the head in the -X and +Y directions.

M667 S2 selects CoreXZ mode. Forward movement of the X motor moves the head in the +X and +Z directions. Forward movement of the Z motor moves the head in the -X and +Z directions.

M667 S3 selects CoreYZ mode. Forward movement of the Y motor moves the head in the +Y and +Z directions. Forward movement of the Z motor moves the head in the -Y and +Z directions.

M906: Set motor currents

Sets the currents to send to the stepper motors for each axis. The values are in milliamps.

The dc42 fork of RepRapFirmware supports an additional I parameter. This is the percentage of normal that the motor currents should be reduced to when the printer becomes idle but the motors have not been switched off.

M998: Request resend of line

Request a resend of line 34. In some implementations the input-handling code overwrites the incoming G Code with this when it detects, for example, a checksum error.
Then it leaves it up to the GCode interpreter actually to request the resend.

Set the current tool to its standby temperatures specified by G10 (see above),

Set the new tool to its operating temperatures specified by G10 and wait for all temperatures to stabilise,

Apply any X, Y, Z offset for the new tool specified by G10,

Use the new tool.

Selecting a non-existent tool (100, say) just does Step 1. above. That is to say it leaves all tools in their standby state. You can, of course, use the G10 command beforehand to set that standby temperature to anything you like.

Note that you may wish to move to a parking position before executing a T command in order to allow the new extruder to reach temperature while not in contact with the print. It is acceptable for the firmware to apply a small offset [by convention (-1mm x tool-number) in Y] to the current position when the above sequence is entered to allow temperature changes to take effect just away from the parking position. Any such offset must, of course, be undone when the procedure finishes.

If the Z value changes in the offsets and the tool moves up, then the Z move is made before the X and Y moves. If Z moves down, X and Y are done first.

Some implementations (e.g. RepRapFirmware) allow you to specify tool-change G Code macros. There are normally three specified (any of which can contain no commands if desired) that execute in this order:

Actions to do with the old tool before it is released - macro name: tfreeN.g where N is the tool number;

(Old tool is released);

Actions to do with the new tool before it is selected - macro name: tpreN.g where N is the tool number;

(New tool is selected); and

Actions to do with the new tool after it is selected - macro name: tpostN.g where N is the tool number.

With such implementations there is no wait for temperature stabilisation. That can be achieved by an M116 in any of the macros, of course.

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 may start at 0 or 1, depending on the implementation. Some implementations (those that use the M563 command to define tools) allow the user to specify tool numbers, so with them you can have tools 17, 99 and 203 if you want. Negative numbers are not allowed.

Proposed EEPROM configuration codes

BRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).

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 soon Octoprint 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:

1. Marlin 1.0.0 Gen6 Firmware does not follow the two character rule. 'rs' is actually 'Resend' and '!!' is 'Error'.
Example Lines:

Error: Line Number is not current line + 1. Last Line: 7

Resend: 8

Writing to File: print.gco

Done saving file.

File opened:print.gco Size:22992

File selected

When in the code base did this change take place and what other firmwares are affected?

2. The dc42 fork of 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:

M105 S2

M105 S3

M20 S2

M36

M408

Proposal for sending multiple lines of G-code

So far, this is a proposal, open for discussion.

Problem to solve

When using Marlin firmware or emulating Marlin, each line of G-code sent from the host to the controller is answered with an ok before the next line can be sent without locking communications up. This slows down communication and limits the number of commands that can be sent per second to the printer controller, as the USB stack on the host and the serial interface driver on the Arduino add their own latencies (up to 10 milliseconds). This is not a problem for other controller electronics using native USB such as the Duet, because the standard serial-over-USB drivers provide flow control, so the host software can be configured so as not to wait for the ok.