Skip to content

Marlin-compatibility

Pre-release
Pre-release
Compare
Choose a tag to compare
@giseburt giseburt released this 22 Mar 04:38
· 396 commits to edge since this release

Now you can 3D Print from your favorite Marlin-centric GUI, and print using gcode from your favorite slicer using RepRap-flavor gcode!

Usage

The Marlin-protocol is auto-detected. When the machine is compiled to enable Marlin compatibility mode, an addition 2-second delay is inserted before the connection banner is displayed. During that time, the g2core will also detect and respond to a minimal set of STK550v2 commands - enough for a Marlin GUI to ask if it is an STK500v2 bootloader, and to tell it to "exit" to the main program - as well as normal G and M codes.

If any STK500v2 was spoken or any of the Marlin-specific M codes that are protocol-only are recognized (poll for temperature, for example), then the protocol will be switched to "Marlin compatible" and instead of a JSON response a Marlin "OK" (or error) will be sent back for each line.

Marlin line-number-order restrictions and checksum testing is honored, along with resend requests.

If any of the hallmarks of Marlin-flavor gcode are found (M codes otherwise not supported, such as the temperature controls, or an E word), then the gcode-flavor is switched to Marlin-flavor.

This means a Marlin-GUI can send either a Marlin-flavor gcode file or a g2core-flavor gcode file. Also, a g2core UI can send a Marlin-flavor file without loss of functionality or feedback.

Upon disconnection from the host the protocol and gcode flavor are rest to g2core.

Supported M-codes and G-codes

Supported M-codes:

  • M104, M109, M140, M190 - temperature controls
  • M106, M107 - fan controls
  • M105, M108, M114 - temperature/position polling
  • M110 - set next line number
  • M111 - debug controls (ignored quietly)
  • M115 - report version information
  • M117 - display on screen (currently silently ignored)
  • M84, M85, M18 - motor disable and motor disable timeout control
  • M82, M83 - relative extruder mode enable/disable
  • M20, M21, M22, M23 - SD card commands respond that there is no card inserted

All other M-codes used for configuration of a machine running Marlin should be accessible through JSON commands instead.

The g2core equivalent M100 and M101 commands with JSON active comments are also available and can be freely mixed with Marlin M-codes. Note: At this time an M101 wait for at-temperature will not switch on the Marlin temperature reporting that an M109 or M190 will.

Additional differences from g2core gcode:

  • G0/G1 - a G0 with an Fnnn will be treated as a G1.
    • This poses an issue with Ennn during retractions. To use retraction speed (configured using {avm:nnn} with a numeric value for nnn, and as A_VELOCITY_MAX in the configuration file) any move with just an Ennn axis change will be treated as a true G0 and the Fnnn will be ignored.
    • Otherwise, there's no way to achieve a true G0 while the gcode flavor is switched to Marlin.
  • Ennn - the synthetic E axis is treated as an A axis when T0 is applied (the default), and the B axis when T1 is applied.
    • Note that this is NOT a volumetric E axis. That is a work in progress, along with the retraction codes G10 and G11.
  • G28 is accepted as an alias for g2core G28.2 homing.
    • Note that this means that when gcode is being interpreted as Marlin-flavor, it is impossible to invoke a G28 go-to-position.
  • Axis words X, Y, etc. will be accepted without a following number where normally that would be rejected.
  • T words are interpreted 0-based where normally they are 1-based with 0 being the current tool.
    • T words are applied immediately on the line they were issued on instead of requiring an M6 command.
  • G29 "bed leveling" is a synthetic command and must be specifically configured at compile-time with list of commands to execute. (Explained more below.)

Enabling and configuration

In the board pinout file TEMPERATURE_OUTPUT_ON must be defined with a value of 1:

#define TEMPERATURE_OUTPUT_ON 1

In the settings file MARLIN_COMPAT_ENABLED must be defined as true:

#define MARLIN_COMPAT_ENABLED       true

And in order to configure G29 you must define MARLIN_G29_SCRIPT as shown:

#define MARLIN_G29_SCRIPT \
    "G1 X0 Y145 Z6 F20000\n" \
    "G38.2 Z-10 F200\n" \
    "G1 Z5 F20000\n" \
    "G1 X210 Y65 F20000\n" \
    "G38.2 Z-10 F200\n" \
    "G1 Z5 F20000\n" \
    "G1 X0 Y10 F20000\n" \
    "G38.2 Z-10 F200\n" \
    "G1 Z5 F20000\n" \
    "M100 ({\"tram\":true})" \

Note that every line must have a \n inside the string, and each line except the last must have a \ at the end of the line to concatenate the lines into one long string.

In the script above, G38.2 probes are used at three points in order to store the probe positions for the {"tram":true} command to be able to create the tramming rotation matrix.

Assumptions

Currently the following output and inputs are assumed (these will later be configurable):

Fan controls M106 and M107 assume {out4:n} is the output for the print fan.
Extruder 1 (T0) is assumed to be on {out1:n} and use kADC1_PinNumber.
Extruder 2 (T1) is assumed to be on {out2:n} and use kADC2_PinNumber.
Head Bed 2 (T3) is assumed to be on {out11:n} and use kADC0_PinNumber.

The extruder fan is assumed to be on {out3:n} and is controlled by the temperature of Extruder 1. (Note: This is a bug, and will be fixed in a later version. Extruder 1 and Extruder 2 should both influence this fan.) The settings for this fan are all configurable through the {he1:null} object.