Main Menu

search

You are here

3d Printing: gCode Home page

[last updated: 2022-01-30]
3d printing home page
gCode Details
all gCodes
-----

  • General Notes:
    • Gotcha: gCode format, syntax, and available codes is Specific to your printer model,
      meaning gCode written for one brand/model of printer may not work on a different printer.
      Further, gCode commands available on one printer brand/model may not be available on a different printer.

    • Gcode files are text files with a ".gcode" extension

    • These are the files that are sent to your printer or CNC machine, and in fact are the only files that your 3dprinter or CNC machine understands and accepts.
    • Each line of a gCode file will be a "numerical control" type instruction. That is, every movement and action that you want your machine to execute must be specified.
    • Each line of the file (other than comments) will start with a 'G' (the source of the gCode name) or with an 'M',
      followed by a number of 1 to 3 (or more) decimal digits,
      followed (separated by a space) by some number of additional parameters of variable syntax.
      For example: G0 is the command for "rapid motion"
      It must be followed with a parameter defining the end point of the movement.
      So: G0 X5 Y15 will send the end effector (whether 3dp extruder or CNC cutting tool) to the point x=5, y=15
      (actual locations are defined by the coordinate system...)
    • Comments are designated with a " ; " so that, on any line, whatever follows a semicolon will be ignored
    • gcode filenames must be less than 30 characters
    • filenames cannot contain weird characters (eg. umlauts)
    • if you turn something on, you must turn it off.
      • OTOH, in fact (on Prusa Mk3 at least) it is necessary to have a M84 "disable motors" at the end of the file or else you get an "incomplete file" error, regardless that no motors were turned ON in the code...
    • Gcode (that is saved/stored on your SD card) gets executed on your printer by: Menu > "Print from SD"
      It doesn't matter if your gCode actually prints anything or just moves the extruder or just beeps at you. If it's gCode, and it's on your SD card, "Print from SD" will execute it.

  • gCode Created by PrusaSlicer:
    • When you use PrusaSlicer (PS) to define print parameters for your model,
      then you click "Slice Now", then click "Export gCode", PS will save a .gcode file to the name and destination you select.
    • If you examine the gcode file in a text editor, you'll see it's composed of several blocks:
      First is a generic section from Prusa
        It includes comments specifying print settings used

      Next is code from Printer Settings > Custom G-code > Start G-code

        All code sections designated "Custom G-code" can be edited by the user

      Next is a few lines of code setting units, coordinates, etc.
      Next is code from Filament Settings > Custom G-code > Start G-code
      Next is code from Printer Settings > Custom G-code > Before Layer Change G-code
      Next are the commands to control the printer to actually print your part

        These are the commands that the slicer creates after reading your .stl (or whatever drawing) file that tell the printer where to send the extruder, how fast, when to extrude, etc.
  • Custom gCode for PrusaSlicer:
    • [Expert] Printer Settings > Custom G-code:
      Custom code can be inserted at Start of print, End of print, Before and After layer changes, and other places.
      There is a block of code on the PS Custom G-code page for each of these options. If you have created/edited custom code in one of these blocks, you can save it as a "User preset".
      Click the square floppy disk icon (between the preset name field and the "X", 3rd line from top). You will be prompted with a Save Preset box, and asked to "Save Printer Settings as:"
      Enter your desired name.
      If you later want to recall this saved preset, click the drop-down arrow at the right end of the preset name field, and select the preset you want.
      • In my 2.3.1 system, custom defined setting files are stored as .ini files in:
        ~/.config/PrusaSlicer
            in sub-folders: printer, print, and filament
      • However, there are also .ini files stored in:
        ~/.PrusaSlicer
      • Gotcha: If you re-install Linux and/or PrusaSlicer,
        it may happen that you'll lose your custom settings files ...

    • At the top of each code section there are two icons: the one on the left is a padlock, and will either be black and locked, or orange and unlocked. The other icon will either be a black round spot or an orange circular arrow.
      • If the padlock icon is locked, that indicates the code in that section is the default code. If the padlock is unlocked, it indicates the code has been modified from default value. Clicking on the unlocked padlock will return the code in that section back to default.
      • If the other icon is a black round spot, it indicates the code in that section is identical to the code that was "last saved."
        • The deal is that, if you edit code in one of the sections, then move your cursor out of the section, the padlock icon will be unlocked and orange, indicating the code in that section is different than default, and the other icon will be an orange circular arrow, indicating the changes you've made have not yet been saved. If you then save the edited code as a "preset" (as described above), then the icon will go to a black spot (the padlock will stay unlocked and orange).
      • if you have un-saved changes, with an orange circular arrow showing, clicking on it will revert your code to the preset (or default) that was last saved.
    • Custom code for manual color change:
      • to pause for layer color change, insert this code into "After layer change" gCode section:
        {if layer_num == xx}M600 ; Color change {endif}
        where 'xx' is the layer number where you want the change to occur
      • Find the layer number in PS by moving the slider when in preview mode until you get to where you want to change colors.
  • Links:
  • .

    .

    .

    eof