G-code/zh cn
English • العربية • български • català • čeština • Deutsch • Ελληνικά • español • فارسی • français • hrvatski • magyar • italiano • română • 日本語 • 한국어 • lietuvių • Nederlands • norsk • polski • português • русский • Türkçe • українська • 中文(中国大陆) • 中文(台灣) • עברית • azərbaycanca • |
该页面尝试描述RepRap的固件怎样使用和他们如何工作。该固件的主要目的是用于FFF/FDM方式的增材制造(译者注:国内流行使用 “3D打印”)。其代码用于控制打印头的移动遵守NIST RS274NGC G-code标准,因此RepRap的固件同时可用于CNC机床(或类似)的控制。
正因为如此,许多固件能够被开发出来并不断完善和加入新功能,而他们的开发者不需要参与到之前的开发,甚至不需要了解之前的功能是如何实现,却也能够为这些固件添加他们想要的功能。
Contents
- 1 概述
- 2 RepRap G Code Fields
- 3 注释
- 4 Individual commands
- 4.1 Checking 标记代码
- 4.2 Buffered G Commands
- 4.3 Unbuffered G commands
- 4.4 无缓冲的 M 和 T 命令
- 4.4.1 M0: Stop 停止
- 4.4.2 M1: Sleep 睡眠
- 4.4.3 M3: Spindle On, Clockwise (CNC specific)
- 4.4.4 M4: Spindle On, Counter-Clockwise (CNC specific)
- 4.4.5 M5: Spindle Off (CNC specific)
- 4.4.6 M7: Mist Coolant On (CNC specific)
- 4.4.7 M8: Flood Coolant On (CNC specific)
- 4.4.8 M9: Coolant Off (CNC specific)
- 4.4.9 M10: Vacuum On (CNC specific)
- 4.4.10 M11: Vacuum Off (CNC specific)
- 4.4.11 M17: Enable/Power all stepper motors
- 4.4.12 M18: Disable all stepper motors
- 4.4.13 M20: List SD card
- 4.4.14 M21: Initialize SD card
- 4.4.15 M22: Release SD card
- 4.4.16 M23: Select SD file
- 4.4.17 M24: Start/resume SD print
- 4.4.18 M25: Pause SD print
- 4.4.19 M26: Set SD position
- 4.4.20 M27: Report SD print status
- 4.4.21 M28: Begin write to SD card
- 4.4.22 M29: Stop writing to SD card
- 4.4.23 M30: Delete a file on the SD card
- 4.4.24 M40: Eject
- 4.4.25 M41: Loop
- 4.4.26 M42: Stop on material exhausted / Switch I/O pin
- 4.4.27 M43: Stand by on material exhausted
- 4.4.28 M80: ATX Power On
- 4.4.29 M81: ATX Power Off
- 4.4.30 M82: set extruder to absolute mode
- 4.4.31 M83: set extruder to relative mode
- 4.4.32 M84: Stop idle hold
- 4.4.33 M92: Set axis_steps_per_unit
- 4.4.34 M98: Get axis_hysteresis_mm
- 4.4.35 M99: Set axis_hysteresis_mm
- 4.4.36 M101 Turn extruder 1 on Forward / Undo Extruder Retraction
- 4.4.37 M102 Turn extruder 1 on Reverse
- 4.4.38 M103 Turn all extruders off / Extruder Retraction
- 4.4.39 M104: Set Extruder Temperature
- 4.4.40 M105: Get Extruder Temperature
- 4.4.41 M106: Fan On
- 4.4.42 M107: Fan Off
- 4.4.43 M108: Set Extruder Speed
- 4.4.44 M109: Set Extruder Temperature and Wait
- 4.4.45 M110: Set Current Line Number
- 4.4.46 M111: Set Debug Level
- 4.4.47 M112: Emergency Stop
- 4.4.48 M113: Set Extruder PWM
- 4.4.49 M114: Get Current Position
- 4.4.50 M115: Get Firmware Version and Capabilities
- 4.4.51 M116: Wait
- 4.4.52 M117: Get Zero Position
- 4.4.53 M117 in Marlin: Display Message
- 4.4.54 M118: Negotiate Features
- 4.4.55 M119: Get Endstop Status
- 4.4.56 M120: Push
- 4.4.57 M121: Pop
- 4.4.58 M126: Open Valve
- 4.4.59 M127: Close Valve
- 4.4.60 M128: Extruder Pressure PWM
- 4.4.61 M129: Extruder pressure off
- 4.4.62 M130: Set PID P value
- 4.4.63 M131: Set PID I value
- 4.4.64 M132: Set PID D value
- 4.4.65 M133: Set PID I limit value
- 4.4.66 M134: Write PID values to EEPROM
- 4.4.67 M136: Print PID settings to host
- 4.4.68 M140: Bed Temperature (Fast)
- 4.4.69 M141: Chamber Temperature (Fast)
- 4.4.70 M142: Holding Pressure
- 4.4.71 M143: Maximum hot-end temperature
- 4.4.72 M160: Number of mixed materials
- 4.4.73 M190: Wait for bed temperature to reach target temp
- 4.4.74 M200 - Set filament diameter / Get Endstop Status
- 4.4.75 M201 - Set max printing acceleration
- 4.4.76 M202 - Set max travel acceleration
- 4.4.77 M203 - Set maximum feedrate
- 4.4.78 M204 - Set default acceleration
- 4.4.79 M205 - advanced settings
- 4.4.80 M206: set home offset
- 4.4.81 M207: calibrate z axis by detecting z max length
- 4.4.82 M208: set axis max travel
- 4.4.83 M209: enable automatic retract
- 4.4.84 M220:set speed factor override percentage
- 4.4.85 M221: set extrude factor override percentage
- 4.4.86 M226: Gcode Initiated Pause
- 4.4.87 M227: Enable Automatic Reverse and Prime
- 4.4.88 M228: Disable Automatic Reverse and Prime
- 4.4.89 M229: Enable Automatic Reverse and Prime
- 4.4.90 M230: Disable / Enable Wait for Temperature Change
- 4.4.91 M240: Start conveyor belt motor / Echo off
- 4.4.92 M241: Stop conveyor belt motor / echo on
- 4.4.93 M245: Start cooler
- 4.4.94 M246: Stop cooler
- 4.4.95 M300: Play beep sound
- 4.4.96 M301: Set PID parameters - Hot End
- 4.4.97 M303: Run PID tuning
- 4.4.98 M304: Set PID parameters - Bed
- 4.4.99 M420: Set RGB Colors as PWM
- 4.4.100 T: Select Tool
- 5 Proposed EEPROM configuration codes
- 6 Replies from the RepRap machine to the host computer
- 7 Proposal for sending multiple lines of G-code
- 8 Alternatives to G-code
概述
一句能够被RepRap识别的Gcode代码应该是这样子的:
N3 T0*57 N4 G92 E0*67 N5 G28*22 N6 G1 F1500.0*82 N7 G1 X2.0 Y2.0 F3000.0*85 N8 G1 X3.0 Y3.0*33
以上这些句子中的各个符号(当然还有其他符号)的意义将会在下面解释。 The meaning of all those symbols and numbers (and more) is explained below.
以下这个表格可以清楚表明某个语句在哪些固件支持,或尚处于试验性质
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | automatic | yes | yes | experimental |
Here means:
- yes
- 完全支持.
- experimental
- 实验中的,有一些支持. 但通常情况下,你需要检查下源代码并可能需要做出一些修改。
- automatic
- 自动的,这说明在这个固件中这项命令是自动生成并处理的,因此该命令是不需要的,例如在Teacup(一种固件)你不会用到 power supply on/off (M80/M81)这个命令。
power supply on/off 电源开/关
- no
- 这个固件不支持这项指令.
另外,每一行命令(代码)都以一个<nl>结尾,或者以<nl><cr>结尾,因此,无论是Unix式和windows式的结尾都是有效的。
RepRap G Code Fields
以下是意译
对于指令Xnnn,其中大写X为指令头,可以是G,M,T,S等,而nnn则是一个整数,或者一个小数,这取决与当时的具体环境。
原文(This section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.)
Letter | Meaning |
---|---|
Gnnn | 标准 GCode 命令, 例如移动到一个坐标点。 |
Mnnn | RepRap定义的命令,例如打开一个冷却风扇。 |
Tnnn | 选择工具代码nnn. 在 RepRap中,工具通常是挤出头(extruder)。 |
Snnn | 命令参数, 例如马达的电压。 |
Pnnn | 命令参数, 频率:1次每毫秒。 |
Xnnn | X坐标, 通常用于移动命令。 |
Ynnn | Y坐标, 通常用于移动命令。 |
Znnn | Z坐标, 通常用于移动命令。 |
Innn | 参数 - 现在仍未使用(定义)。 |
Jnnn | 参数 - 现在仍未使用(定义)。 |
Fnnn | 进料速度 单位: 毫米每分钟 (关系到打印速度)。 |
Rnnn | 参数 - 温度相关。 |
Qnnn | 参数- 现在仍未使用(定义)。 |
Ennn | 挤出长度(单位:毫米)。就像 X, Y 和 Z命令,但这个命令用于控制挤出线材的长度. |
Nnnn | 行码 Line number. 在发送错误情况后,这可以用来重复输入某行代码(命令)。 |
*nnn | 标记码(Checksum). 用于标记错误代码。 |
注释
G Code 注释:
N3 T0*57 ;这是一条注释 N4 G92 E0*67 ; 这也是 N5 G28*22
注释会被RepRap忽略掉,就像空白行,但最好在发送命令之前把注释清除掉,省点流量嘛。。
Individual commands
Checking 标记代码
N 和 *
Example: N123 [...G Code 写在这里...] *71
这是行码和标记码。RepRap的固件会以一个本地计算的值来对比标记码,如果两者值不同,就会要求一个重复的输入
行码和检查码都可以去掉 - RepRap仍会工作, 但它不会做检查. 你必须同时使用,或同时放弃使用.
检查码cs 是通过对对应的一串Gcode cmd(包括它的的行码)的原始字节数据 进行 异或位运算得出的
下面是实例代码:
int cs = 0; for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++) cs = cs ^ cmd[i]; cs &= 0xff; // Defensive programming...
检查码cs的值即使其*符号右边的十进制数字
RepRap固件希望每次命令的行代码都是逐次增加1的大小,不然的话,它会返回一个错误。当然你也可以发送一个M110命令(详情请看下面)强行重置机器。
译者注:行码和检查码是为了减少信号干扰而存在。
Buffered G Commands
RepRap固件会缓存这些命令。 The RepRap firmware stores these 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.
G0: Rapid move 快速移动
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
??? | yes | yes | yes | yes |
Example: G0 X12
这个命令会移动的距离 X = 12 mm. 事实上, 对于RepRap来说,这个命令的效果和G1 X12是一样的。(这条命令本来是为了让那些喜欢走折线路径的老机器走直线这个比较快的路径,所以叫做快速移动)
G1: Controlled move 可控移动
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes | yes | yes | yes |
Example: G1 X90.6 Y13.8 E22.4
从当前的位置点(X, Y) 移动到目的点(90.6, 13.8), 并会在行进过程中挤出22.4mm的打印丝(注意,挤出命令是由E22.4控制的)
RepRap 对于进料速度很敏感. 因此:
G1 F1500 G1 X90.6 Y13.8 E22.4
会先设置 1500毫米每分钟 的进料速度, 然后才会移动(X90.6 Y13.8)并且吐丝.
但是
G1 F1500 G1 X90.6 Y13.8 E22.4 F3000
这串代码却会先设置1500毫米每分钟 的进料速度,然后在移动的时候提升进料速度,直到3000毫米每分钟。
RepRap 可以通过E命令轻易对进料速度进行加/减速,就像对X,Y,Z,E命令一样,这样,机器才能在必要的点吐必要的丝。
提示: 不是所有的固件都支持这项功能(移动在改变进料速度), 例如: 当前的 Marlin 会从一开始就使用新的进料速度,而不会尝试在中途改变它。
第一个例子是在移动时保持固定进料速度,而第二个例子则是在移动中改变进料速度。 因此:
G1 F1500 G1 X90.6 Y13.8 E22.4 F3000 G1 X80 Y20 E36 F1500
这段代码会先先加速进料速度到3000毫米每分钟 减速到1500 毫米每分钟。
吸丝操作,通过反向转动挤出机马达,减少挤出机内部压力,避免在悬空移动时候的吐丝,可以有效减少打印过程中的毛刺现象,具体操作:发送G1 Ennn指令给RepRap 其中nnn的值应当小于当前的值
G28: Move to Origin
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes | yes | yes | yes |
Example: G28
This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.
If you add coordinates, then just the axes with coordinates specified will be zeroed. Thus
G28 X0 Y72.3
will zero the X and Y axes, but not Z. The actual coordinate values are ignored.
G29-G32: Bed probing
G29 Detailed Z-Probe
probes the bed at 3 points.
G30 Single Z Probe
probes bed at current XY location.
G31 Report Current Probe status
reports whether Z probe is triggered.
G32 Probe Z and calibrate with FPU
probes the bed at 3 points and updates transformation matrix for bed leveling compensation.
Unbuffered G commands
The following commands are not buffered. When one 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.
Teacup Firmware buffers G20, G21, G90 and G91.
G4: Dwell
Example: G4 P200
In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.
G10: Head Offset
Example: G10 P3 X17.8 Y-19.3 Z0.0 R140 S205
This sets the offset for 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 heads are loaded and unloaded by some sort of head changer. When all the heads 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 head to be at a different temperature when not in use, set both values the same. See the T code (select tool) below.
The NIST G-code standard mentions an additional L parameter, which is ignored.
This command is subject to discussion.
G20: Set Units to Inches
Example: G20
Units from now on are in inches.
G21: Set Units to Millimeters
Example: G21
Units from now on are in millimeters. (This is the RepRap default.)
G90: Set to Absolute Positioning
Example: G90
All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)
G91: Set to Relative Positioning
Example: G91
All coordinates from now on are relative to the last position.
G92: Set Position
Example: G92 X10 E90
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.
无缓冲的 M 和 T 命令
M0: Stop 停止
Example(例子): M0
RepRap 会终止任何动作, 然后关机。所有的马达和加热器都很被关掉,你需要点击reset按钮来重启主控制器 See also M1, M112.
M1: Sleep 睡眠
Example: M1
RepRap 会终止任何动作, 然后关机。所有的马达和加热器都很被关掉,你仍可以发送 G或 M 命令来唤醒它 See also M0, M112.
M3: Spindle On, Clockwise (CNC specific)
Example: M3 S4000
The spindle is turned on with a speed of 4000 RPM.
M4: Spindle On, Counter-Clockwise (CNC specific)
Example: M4 S4000
The spindle is turned on with a speed of 4000 RPM.
M5: Spindle Off (CNC specific)
Example: M5
The spindle is turned off.
M7: Mist Coolant On (CNC specific)
Example: M7
Mist coolant is turned on (if available)
M8: Flood Coolant On (CNC specific)
Example: M8
Flood coolant is turned on (if available)
M9: Coolant Off (CNC specific)
Example: M9
All coolant systems are turned off.
M10: Vacuum On (CNC specific)
Example: M10
Dust collection vacuum system turned on.
M11: Vacuum Off (CNC specific)
Example: M11
Dust collection vacuum system turned off.
M17: Enable/Power all stepper motors
Example: M17
M18: Disable all stepper motors
Example: M18
Disables stepper motors and allows axis to move 'freely.'
- Is this not the same as M84? -- MrAlvin 05:53, 20 September 2012 (UTC)
M20: List SD card
Example: M20
All files in the root folder of the SD card are listed to the serial port. This results in a line like:
ok Files: {SQUARE.G,SQCOM.G,}
The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...
M21: Initialize SD card
Example: M21
The 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
Example: M22
SD card is released and can be physically removed.
M23: Select SD file
Example: M23 filename.gco
The file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.
M24: Start/resume SD print
Example: M24
The machine prints from the file selected with the M23 command.
M25: Pause SD print
Example: M25
The machine pause printing at the current position within the file selected with the M23 command.
M26: Set SD position
Example: M26
Set SD position in bytes (M26 S12345).
M27: Report SD print status
Example: M27
Report SD print status.
M28: Begin write to SD card
Example: M28 filename.gco
File specified by filename.gco 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
Example: M29 filename.gco
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
Example: M30 filename.gco
filename.gco is deleted.
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
Example: M41
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
- When there's an error (such as a heater failure).
M42: Stop on material exhausted / Switch I/O pin
M42 in ???
Example: M42
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. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).
M42 in Marlin/Sprinter
Example: M42 P7 S255
M42 switches a general purpose I/O pin.
M42 in Teacup
Not needed. General purpose devices are handled like a heater, see M104.
M43: Stand by on material exhausted
Example: M43
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.
M80: ATX Power On
Example: M80
Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.
Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.
M81: ATX Power Off
Example: M81
Turns off the ATX power supply. Counterpart to M80.
M82: set extruder to absolute mode
Example: M82
makes the extruder interpret extrusion as absolute positions.
This is the default in repetier.
M83: set extruder to relative mode
Example: M83
makes the extruder interpret extrusion values as relative positions.
M84: Stop idle hold
Example: M84
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.
M92: Set axis_steps_per_unit
Example: M92 X<newsteps> Sprinter and Marlin
Allows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.
M98: Get axis_hysteresis_mm
Example: M98
Report the current hysteresis values in mm for all of the axis.
Proposed for Marlin
M99: Set axis_hysteresis_mm
Example: M99 X<mm> Y<mm> Z<mm> E<mm>
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.
Proposed for Marlin
M101 Turn extruder 1 on Forward / Undo Extruder Retraction
M101 in Teacup firmware
If a DC extruder is present, turn that on. Else, undo filament retraction, which means, make the extruder ready for extrusion. Complement to M103.
M101 in other firmwares
Deprecated. Regarding filament retraction, see M227, M228, M229.
M102 Turn extruder 1 on Reverse
Deprecated.
M103 Turn all extruders off / Extruder Retraction
M103 in Teacup firmware
If a DC extruder is present, turn that off. Else, retract the filament in the hope to prevent nozzle drooling. Complement to M101.
M103 in other firmwares
Deprecated. Regarding extruder retraction, see M227, M228, M229.
M104: Set Extruder Temperature
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes | yes | yes | yes |
Example: M104 S190
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). See also M109.
This is deprecated because temperatures should be set using the G10 and T commands (q.v.).
Deprecation is subject to discussion. --Traumflug 11:33, 19 July 2012 (UTC)
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
Example: M105
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
ok T:201 B:117
M106: Fan On
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes | yes |
Example: M106 S127
Turn on the cooling fan at half speed.
Mandatory parameter 'S' declares the PWM value (0-255). M106 S0 turns the fan off.
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.
M107: Fan Off
Deprecated. Use M106 S0 instead.
M108: Set Extruder Speed
Sets speed of extruder motor. (Deprecated in current firmware, see M113)
M109: Set Extruder Temperature and Wait
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
??? | not needed | see text | yes | ??? |
M109 in Teacup
Not needed. To mimic Marlin behaviour, use M104 followed by M116.
M109 in Marlin, Sprinter (ATmega port)
Set extruder heater temperature in degrees celsius and wait for this temperature to be achieved.
Example: M109 S185
M109 in Sprinter (4pi port)
Parameters: S (optional), set target temperature value. If not specified, waits for the temperature set by M104. R (optional), sets target temperature range maximum value.
Example: M109 S185 R240 //sets extruder temperature to 185 and waits for the temperature to be between 185 - 240.
If you have multiple extruders, use T or P parameter to specify which extruder you want to set/wait.
Another way to do this is to use G10.
M110: Set Current Line Number
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
??? | not needed | ??? | ??? | ??? |
Example: M110 N123
Set the current line number to 123. Thus the expected next line after this command will be 124.
M111: Set Debug Level
Example: M111 S6
Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:
#define DEBUG_ECHO (1<<0) #define DEBUG_INFO (1<<1) #define DEBUG_ERRORS (1<<2)
Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)
Example: M253
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
Debug |
M112: Emergency Stop
Example: 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 on the master microcontroller. See also M0 and M1.
M113: Set Extruder PWM
Example: M113
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.
M114: Get Current Position
Example: M114
This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.
For example, the machine returns a string such as:
ok C: X:0.00 Y:0.00 Z:0.00 E:0.00
M115: Get Firmware Version and Capabilities
Example: M115
Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with a linefeed.
sample data from firmware:
ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A//reprap.org MACHINE_TYPE:Mendel EXTRUDER_COUNT:1
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
Example: M116
Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.
M117: Get Zero Position
Example: M117
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.)
M117 in Marlin: Display Message
Example: M117 Hello World
This causes the given message to be shown in the status line on an attached LCD. The above command will display Hello World.
M118: Negotiate Features
Example: M118 P42
This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.
See Protocol_Feature_Negotiation for more info.
M119: Get Endstop Status
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes |
Example: M119
Returns the current state of the configured X, Y, Z endstops. Takes into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.
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
- Current feedrate, and
- Whether moves (and separately extrusion) are relative or absolute
M121: Pop
Recover the last state pushed onto the stack.
M126: Open Valve
Example: M126 P500
Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.
M127: Close Valve
Example: M127 P400
Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.
M128: Extruder Pressure PWM
Example: M128 S255
PWM value to control internal extruder pressure. S255 is full pressure.
M129: Extruder pressure off
Example: M129 P100
In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.
M130: Set PID P value
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
Example: M130 P 0 S 8.0 # Sets heater 0 P factor to 8.0
M131: Set PID I value
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
Example: M130 P 1 S 0.5 # Sets heater 1 I factor to 0.5
M132: Set PID D value
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
Example: M130 P 0 S 24 # Sets heater 0 D factor to 24.0
M133: Set PID I limit value
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
Example: M130 P 1 S 264 # Sets heater 0 I limit value to 264
M134: Write PID values to EEPROM
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
Example: M134
M136: Print PID settings to host
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
Debug |
Example: M136 P1 # print heater 0 PID parameters to host
M140: Bed Temperature (Fast)
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes | yes | yes | yes |
Example: M140 S55
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).
M141: Chamber Temperature (Fast)
Example: M141 S30
Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).
M142: Holding Pressure
Example: M142 S1
Set the holding pressure of the bed to 1 bar.
The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.
M143: Maximum hot-end temperature
Example: M143 S275
Set the maximum temperature of the hot-end to 275C
When temperature of the hot-end exceeds this value, take countermeasures, for instance an emergency stop. This is to prevent hot-end damage.
M160: Number of mixed materials
Example: M160 S4
Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.
When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:
M160 S4 G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7 G1 X70.6 E42.4 0.0 0.0 0.0 1.0 G1 E42.4 1.0 0.0 0.0 0.0
The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.
The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.
The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.
M190: Wait for bed temperature to reach target temp
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
obsolete, see M116 | yes | yes |
Example: M190 S60
This will wait until the bed temperature reaches 60 degrees, printing out the temperature of the hot end and the bed every second.
M200 - Set filament diameter / Get Endstop Status
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
yes |
M200 sets the filament diameter.
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)
M201 - Set max printing acceleration
in units/s^2 for print moves (M201 X1000 Y1000)
M202 - Set max travel acceleration
in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
M203 - Set maximum feedrate
that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
Note: this should be in units/minute, just like the F code.
M204 - Set default acceleration
S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate
M205 - advanced settings
minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk
M206: set home offset
Example: M206 X10.0 Y10.0 Z-0.4
The values specified are added to the endstop position when the axes are referenced. The same can be achieved with a G92 right after homing (G28, G161).
With Marlin firmware, this value can be saved to EEPROM using the M500 command.
A similar command is G10, aligning these two is subject to discussion.
M207: calibrate z axis by detecting z max length
Example: M207
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
Example: M208 X250 Y210 Z180
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.
M209: enable automatic retract
Example: M209 S1
This boolean value S 1=true or 0=false enables automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
M220:set speed factor override percentage
Example: M220 S80
S<factor in percent>- set speed factor override percentage
M221: set extrude factor override percentage
Example: M221 S70
S<factor in percent>- set extrude factor override percentage
M226: Gcode Initiated Pause
Example: M226
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
Example: M227 P1600 S1600
P and S are steps.
"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.
M228: Disable Automatic Reverse and Prime
Example: M228
See also M227.
M229: Enable Automatic Reverse and Prime
Example: M229 P1.0 S1.0
P and S are extruder screw rotations. See also M227.
M230: Disable / Enable Wait for Temperature Change
Example: M230 S1
S1 Disable wait for temperature change S0 Enable wait for temperature change
M240: Start conveyor belt motor / Echo off
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
Debug: Echo off |
Example: M240
The conveyor belt allows to start mass production of a part with a reprap.
Echoing may be controlled in some firmwares with M111
M241: Stop conveyor belt motor / echo on
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
Debug: Echo on |
Example: M241
Echoing may be controlled in some firmwares with M111
M245: Start cooler
Example: M245
used to cool parts/heated-bed down after printing for easy remove of the parts after print
M246: Stop cooler
Example: M246
M300: Play beep sound
Usage: M300 S<frequency Hz> P<duration ms>
Example: M300 S300 P1000
Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.
M301: Set PID parameters - Hot End
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
PID |
Example: M301 P1 I2 D3 C5
Sets Proportional, Integral and Derivative values for hot end, the value C refers to an extrusion rate.
Alternate implementation
Example: M301 W125
M303: Run PID tuning
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
PID | PID |
Hotend Usage: M303 S<temperature> C<cycles> Bed Usage: M303 E-1 C<cycles> S<temperature> Example: M303 C8 S175
Generate Proportional, Integral and Derivative values for the hotend or bed (E-1). Send the appropriate code and wait for the output to update the firmware.
M304: Set PID parameters - Bed
Support | FiveD | Teacup | Sprinter | Marlin | Repetier |
---|---|---|---|---|---|
PID |
Example: M304 P1 I2 D3
Sets Proportional, Integral and Derivative values for bed
M420: Set RGB Colors as PWM
Usage: M420 R<Red PWM (0-255)> E<Green PWM (0-255)> B<Blue PWM (0-255)>
Example: M420 R255 E255 B255
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.
T: Select Tool
Example: T1
Select extruder number 1 to build with.
The sequence followed is:
- Set the current extruder to its standby temperature specified by G10 (see above),
- Set the new extruder to its operating temperature specified by G10 and wait for all temperatures to stabilise,
- Apply any X, Y, Z offset for the new extruder specified by G10,
- Use the new extruder.
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 head moves up, then the Z move is made before the X and Y moves. If Z moves down, X and Y are done first.
After a reset extruders 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.
Extruder numbering starts at 0.
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).
Marlin uses these codes to manipulate EEPROM values.
Sprinter has implemented the following commands to manipulate EEPROM Commit message.
Teacup uses codes M130-M136 to set, read, and save some parameters.
M500: stores paramters in EEPROM
M501: reads parameters from EEPROM
If you need to reset them after you changed them temporarily
M502: reverts to the default "factory settings".
You still need to store them in EEPROM afterwards if you want to.
M503: Print settings
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 //.
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: 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?
Proposal for sending multiple lines of G-code
So far, this is a proposal, open for discussion.
Problem to solve
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 communcations up. This makes operations very slow, as the usual USB-TTL converters and probably also the host's operating system drivers come with substantial latency, often 10 milliseconds.
For more details on this proposal, and some suggested solutions, and comments please see GCODE_buffer_multiline_proposal
Alternatives to G-code
- Main article: Firmware/Alternative#alternatives to G-code
- Wikipedia: STEP-NC: "STEP-NC was designed to replace ... G-codes ... adding tolerance data ... [with a] XML format."
- Elegant multispline motion controller "will not use G-code. It will use a custom language based on cubic Bezier curves. This allows for much better description of arcs and will result in much higher quality prints with a much lower data throughput requirements."