A work in progress page for useful gcode macros.
RepRapFirmware allows for gcode sequences, called macros, to be stored on the SD card. these macros can then be called by entering :
Macros can be called from any source of gcode: the console, from a gcode printing off the SD card, from the PanelDue and from another user or system macro. DuetWebControl makes it easy to upload, edit and create new macros.
Macros also allow for naming gcodes with easier to remember names. For example you can create a Macro for "Allow Cold Extrude" to call M302 P1.
The macro folder can divided into sub directories to more easily organise your macros by type.
For more information see Setting up macro files for common tasks
System files are also effectively macros, for example homing files are a sequence of gcodes to run the specific homing sequence for a specific printer type. See here for information on using tool change macros
The RepRap wikialso contains a page of useful macros.
RepRapFirmware configurator will produce appropriate system macros for most basic printer types. These are generally a good start point.
There is a github repository here for macros.
It is a work in progress. Please submit pull requests or comment on the forum if you have example macros to share.
Start and end gcodes
Macros can be used to complement printer "start gcode" and "end gcode", for example if you have different printers, with different start and ends sequences, but you want to use the same sliced gcode, you could use
M98 P" startprint.g"
see Filaments, specific load and unload macros can be defined by filament type.
Calibration and Tuning
Calibration and tuning printer settings often requires repeating the same steps repeatedly, changing one variable at a time. Macros can help automate this.
Example: Measuring the Z axis for a Z max endstop and saving the result
Here is an example macro that uses the M500 function to measure and save the length of the Z axis using the Z max endstop.
; 0:/macros/Bed Leveling/0_Set Zmax height.g ; Automates measuring the Zmax height ; M291 P"This will set Z0 and calibrate Zmax height" R"Proceed?" S3 M291 P"Heating and Homing all axis. Remove filament." T5 M190 S60 ; Set bed temp to 60 and wait M109 S215 ; Set nozzle temp to 215 and wait G28 ; Home all G90 ; absolute positioning G1 X155 Y140 F6000 ; move probe to center M291 P"Print head will now raise until the Z Max endstop is triggered" S3 M913 Z50 ; drop the motor current of the z axis motor G1 H3 Z300 F400 ; Z up until triggered. set M208 Z max M500 ; save m208 value for z axis to config override M291 P"ZMax homing will now be tested, starting with homing Zmin" S3 M291 P"Homing to Zmin" T5 G1 Z100 F6000 ; move z down a bit quickly M558 F600 A1 ; set single fast probe settings G30 ; probe the bed at center M558 F120 A10 ; set slower multi probe G30 ; probe the bed at center M291 P"Ready to test Zmax homing?" R"Proceed?" S3 M291 P"Homing to Zmax" T5 G28 Z ; home to zmax M291 P"Verify that Z max height is correct by moving to Z0" S3 G1 Z0 F400 ; move the Z axis to Z0 M291 "The nozzle should now be just touching the bed." S3 M913 Z100 ; return z axis motor current to normal M140 S0 ; turn bed heater off M104 S0 ; turn hotend heater off
RepRapFirmware uses gcode files to script many user configurable printer actions. The use of these system macros and opposed to hard coding the functionality is one the reasons RepRapFirmware is so flexible. It is recommended to start with a configuration from the RepRapFirmware configurator or a known good configuration as a start point.
Note, all these macros are in /sys/ on the SD card unless otherwise noted
Homing macros depend on the type of printer you are using. See:
- Cartesian printer homing.
- Delta printer homing.
- Peculiarities of CoreXY homing
- IDEX homing
- SCARA homing
- Polar homing
Deploying and retracting the probe
If you have a z probe that must be deployed before probing and retracted afterwards use deployprobe.g and retractprobe.g to call the appropriate deploy and retract commands. These are called by M401 - Deploy z probe, M402 - Retract z probe.
Note: If you do not have a Z probe that needs to deploy or retract you must not have these files in the /sys/ directory
bed.g is used as part of delta calibration.
There are normally three specified tool change macros (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;
- Actions to do with the new tool before it is selected - macro name: tpreN.g where N is the tool number;
- Actions to do with the new tool after it is selected - macro name: tpostN.g where N is the tool number.
See Selecting a tool for more details.
Start, pause, stop and power fail
- start.g is run when you start a print from SD card.
- pause.g is run when you pause a print.
- resume.g is run when you resume a print.
- cancel.g is optional, but if present is run when you cancel a paused print.
- stop.g is optional, but if present is run when a print finishes normally with an M0 command at the end of the print job.
- sleep.g If M1 is issued the firmware finishes any moves left in its buffer, then shuts down, the macro file sleep.g is run before all heaters and drives are turned off.
The Duet can be configured to detect a power failure and store the current state once the power returns if a user wants to resume the print resurrect-prologue.g is run that would contain user commands to home the printer etc before resuming.
M581 can be used to setup the external triggers (switches etc). These triggers carry out actions defined in trigger#.g
3D scanner control
M752 runs two macros before and after a 3d scan: before the SCAN command is sent to the scanner, the macro file scan_pre.g is executed and when the scan has finished, the macro file scan_post.g is run.