
3D printers communicate via a language called G-code, like all Computer Numerical Controlled (CNC) machines. This versatile language provides a set of human-readable commands for controlling each action that a 3D printer performs. Slicing software may be thought of as an interpreter for translating 3D models into a series of G-code commands for producing a solid part.
We tend to spend a lot of time focusing on key parameters affecting the final print quality (layer height, infill, perimeters, etc.), but slicing software adds two additional sections orย scriptsย of G-code to the sliced files:ย start.gcodeย andย end.gcode. These two highly customizable scripts have a dramatic effect on your final print.
Letโs examine two typical G-code lines to better understand how a command is constructed. Commands beginning withย Gย control movements and offset definitions, while commands beginning withย Mย control miscellaneous actions.
START.GCODE
The purpose of theย start.gcodeย script is to prepare the 3D printer for producing the desired object. At a minimum, the extruder and heated bed (if applicable) need to be set to proper temperatures and the tool head needs to be homed. To increase your probability of a successful print, you should also perform additional actions like leveling (or tramming) the bed, priming the hotend, and even updating the LCD to inform the user that the print is underway. The script below walks through a compilation of typicalย start.gcodeย lines that many current slicers employ:
G21ย ;ย Set all units to millimeters M107ย ;ย Turn off the part cooling fan M104ย S215 ;ย Set extruder to 215ยฐC [and immediately move on] M140ย S60 ;ย Set bed to 60ยฐC [and immediately move on] M190ย S60 ;ย Set bed toย 60ยฐC [and wait for 60ยฐC] M109ย S215 ;ย Set extruder to 215ยฐC [and wait for 215ยฐC] G28ย ;ย Move toolhead to origin (or home X, Y, Z) ;ย Prusa uses G28 W to perform homing command G29ย ;ย Auto-Level the printer bed using a measurement probe ;ย Prusa uses G80 to accomplish a mesh bed leveling G92ย E0.0ย ;ย Reset the extruder position to 0mm G1ย Z0.2 ;ย Move hotend nozzle to Z position of 0.2mm G1ย X100.0ย E20.0 ;ย Prime the hotend (Move to X=100mm & Extruder=20mm) G92ย E0.0 ;ย Reset the extruder position to 0mm G90ย ;ย Set to absolute positioning as opposed to relative M83ย ;ย Set the extruder to relative positioning M300ย S300ย P1000 ;ย Play a 300Hz beep sound for 1000 milliseconds M117ย Printing...;ย Update the LCD screen with โPrinting...โ END.GCODE
The purpose of theย end.gcodeย script is to ensure that all printing functions have been halted, and perform any final cleanup tasks. From a safety standpoint, the most important job is to turn off power to the heating elements and motors. The script below walks through a compilation of typicalย end.gcodeย lines:
M107ย ;ย Turn off the part cooling fan G28ย X0 ;ย Home X axis and remove hotend from object M104ย S0 ;ย Turn off the extruder [and immediately move on] M140ย S0 ;ย Turn off the bed [and immediately move on] M84ย ;ย Turn off the stepper motors M300ย S300ย P1000 ;ย Play a 300Hz beep sound for 1000 millisecond M117ย Done! ;ย Update the LCD screen with โDone!โ
With great power comes great responsibility โ especially when you add custom movements into your G-code! Be sure to test your modifications from within your slicing software to ensure that you are not creating movements outside of your printerโs boundaries. You can learn more about G-code for RepRap firmware and 3D printing atย reprap.org/wiki/G-code.
COMMONย START.GCODEย ANDย END.GCODEย COMMANDS
G COMMANDS
G1 –ย Perform a synchronized movement
G21 –ย Set all units to millimeters since 3D printers use the metric system
G28 –ย Home the 3D printer or move the toolhead to the origin
G29 –ย Use a probe to measure the flatness of the bed then compensate by โlevelingโ or โtrammingโ the bed via a live z offset
G90 –ย Set all future commands to use absolute coordinates (as opposed to a relative position from the last location)
G92 –ย Define the current physical position to user-specified values
M COMMANDS
M83 –ย Set all future commands for the extruder to use relative coordinates from the last physical position (as opposed to absolute coordinates)
M84 –ย Stop holding the current position of the motor
M104 –ย Set the extruder temperature to a user-specified target (in Celsius) and immediately return control to the controller
M109 –ย Set the extruder temperature to a user-specified target (in Celsius) and wait for the user-specified target to be achieved
M117 –ย Display a user-specified message to appear on the LCD screen of the 3D printer
M140 –ย Set the heated bed temperature to a user-specified target (in Celsius) and immediately return control to the controller
M190 –ย Set the heated bed temperature to a user-specified target (in Celsius) and wait for the user-specified target to be achieved
M300 –ย Play a beep sound based on a user-specified frequency and duration
ADVERTISEMENT