26. February 2018

BLTouch on Duet WiFi – Configuration and usage

By BeTrue3D

In a previous post we connected our BLTouch sensor physically to the Duet hardware and made some basic configurations as well.

In this post I’ll talk about Probes and Sensors interchangeably and will be using the BLTouch name/model during this post, as that is the one I’m using to test this.

If you want to read a bit of an intro into the differences between autolevel and autocompensation, I wrote a brief section about this in Is this autolevel?

I’ve had some correspondence with a lot of peopleduring the writing of this post and I’ve come to understand that I need to specify the printertype I’m talking about here. My printers, which I’m using as basis for this post are:

  1. A box type printer with fixed XY gantries at the top, working together using the cross method to move a carriage around (like an Ultimaker and my xBot), and using a single z-motor to lift the z-gantry containing the printing bed surface.
  2. My xBot which uses the same XY cross-method, but has 3 seperate Z motors for the Z axis, making it possible to adjust it automatically for true autolevel.

You can still use all information even if you are using a Tower printer (like Prusa etc), but I am going to be referring to the two machine models above throughout this post.

i know very little about Delta machines, so I haven’t written with those machines in mind. Donate a Delta and I’ll write some how-tos on it ?

In this blog-post I’ll try to go through different types of more complete configurations and usage scenarios like:

  • Setup BLTouch in Config.g including defining Mesh Grid to probe using M557.
  • Doing a Mesh Grid Probing sequence using G29
  • Doing a Basic Single Probe using G30 before print start.
  • Doing an Advanced Probing sequence using G32 for Autolevel
  • Setup Slizer Startup Gcode to apply our Mesh Grid to the z-plane after doing the Autolevel Probing.
  1. Using a Probe – Intro and Explained
    1. Auto Bed Compensation drop-down menu walkthrough
    2. Summing up
    3. Usage
  2. Wiring of BLTouch
    1. Probe switch function
    2. PWM Channel for Servo Function
    3. Duex owners
  3. Configuring BLTouch
    1. Create a deployprobe.g and retractprobe.g file
    2. Create a BLTouch Macro Group
  4. Change config.g file
    1. Disable Heater to free up PWM pin
    2. Change Endstop Settings
    3. Define Probe Type
    4. Probe Position
    5. Define Mesh Grid
  5. Total Configuration – Summing up
      1. Config.g changes
      2. New Configuration files
      3. Macros
  6. Calibrate our sensor
    1. Find Z-Offset
    2. Run Mesh Grid Compensation sequence
    3. Save Custom named height maps
  7. Before Printing
    1. Homez.g
    2. Homeall.g
    3. Slizer startup gcode
  8. Multi Z-motor setup using bed.g
    1. Z-leadscrew placements
    2. Define XY Coordinates in config.g
    3. Lets have a look at Homing using a Probe
      1. Slizer Startup and Endcode Examples
      2. Single Z-Motor Machine
      3. Triple Z-Motor Machine
  9. Gcodes used

Using a Probe – Intro and Explained

When adding a Z-probe to your 3D Printer it also means introducing a lot of new terms and it requires a fair bit of setup to do and gcodes to learn to use.

Most printers just have some sort of basic limit switch or maybe a hall or IR -sensor for X, Y and Z. This means a G28 command is enough to home all axes.

When using RepRapFirmware a basic homing sequence requires 4 files to work:

  1. homex.gG28 X
  2. homey.gG28 Y
    1. By issuing: G28 XY you can opt to home X and Y at the same time without Z.
  3. homez.gG28 Z
    1. This command will just home Z without the X and Y axes.
  4. The homeall.g file, which is executed using G28 without specifying any axes afterwards.
    1. This file normally homes all axes your machine might have.

Important: When using a Probe located on Z-min (at your nozzle) and using the most basic/normal probetype with 1x Z-motor using Mesh Grid Compensation the Z-Max endstop will be disabled regardless of any virtual axes you might make to get around this issue! 

I am told that his is not the case when using a Delta type Printer. I am not familiar with Delta configurations.

If you have 2 or more individual Z-motors and have configured Auto Bed Compensation in combination with Mesh Grid Compensation a Z-max endstop is mandatory (is it really?) in order for the Printer to calculate your Z plane accurately.

In order to use a Probe we need to configure it using several new M/Gcodes, which we go through below.

We also get a new arsenal of Gcodes to use during startup, and we can use the various functions in the Auto Bed Compensation drop down menu in our web gui:

Auto Bed Compensation drop-down menu walhthrough

  • The actual button Auto Bed Compensation constitutes a G32 which can only be used if you have 2 or more independent Z-motors.
    • When issuing a G32 command, the bed.g macro file is executed.
    • I don’t know how to make the “Show Probed Points” active?
  • The Disable Bed Compensation is used if you have  Auto Bed Compensation in effect but want to disable it.
    • This can also be done by issuing the M561 command which cancels any bed-plane changes you might have in effect by probing (or anything else).
    • The M561 is also placed first in the bed.g file before doing a new Auto Bed Compensation run.
  • G29 – Run Mesh Grid Compensation – Performs a Mesh Probe which is saved to a heightmap.csv file.
    • By probing the bed you automatically enable it as well.
    • You can use custom names. More on this later.
  • The Show Mesh Grid Heightmap displays the grid performed by G29 graphically.
  • The Load Heightmap from SD Card constitutes a G29 S1 command, which you would typically place in your startupgcode file in your slizer after the probing sequence.
  • Disabled Mesh Grid Compensation equals G29 S2 and stops the printer from using the heightmap.

Before we can run G29 we need to define the mesh to probe, which is done via M557 in our config.g file, which we will further down in this post under Define Mesh Grid.

Summing up

  • We setup and configure our Probe/Sensor in config.g
  • Bed.g is only used if we have 2 or more  independent Z-motors. Tower printers would use this method if the Z motors are using seperate drivers.
  • The bed.g file is used to define probe points using M671 in relation to our Z-motors.
  • The bed.g file is not used if we do not have more than 1 independent Z-motor.
  • You can even have multiple differently named heightmaps to use, if you for instance have different plates for different materials.


  • M561 should always be used before running a new probe sequence of any kind.
  • We use G30 (without parameters) to do to the Z-min probe as defined by G31 in the config.g file
  • If we have 2 or more independent Z-motors we use G32 to do the probing sequence as defined in the bed.g file.
  • Any Heightmaps you want to use is loaded after you have finished your probing sequence.

Wiring of BLTouch

We can seperate the 5 wires of the BLTouch into 2 seperate groups:

  1. Probe switch function:
    The Black (GND) and White (Signal – Z Probe IN) which connects to the Probe Connector on the Duet Controller.

    Note: My “white” wire is red on this photo.
  2. PWM channel for Servo Function.
    The Brown (GND), Red (+5v) and Yellow(PWM) goes either onto  a PWM/Servo connector on a Duex board or we use 3 pins in the 40-pin expansion-connector.
    Note: Regardless of wheter we use a Duex or not, I am going to be using Heater7 in my setup examples, which is PWM channel 5. I do this as it is the last one, so it’s easy to remember and it is physically the PWM channel on Duex which sits closest to the edge of the board.
  3. Here is he complete overview of pins used if you do no have a Duex board.

    1. For Duex owners, the Heater7/PWM5 is the connector you see on the middle left side here and the upper one is the Probe connector on the Duet Controller.

      Note: On the photo I have a resistor installed in the Probe Connector. This is necessary if you are using one of the older BLTouch models without the trace you can cut on the rear of it, to make it run 3.3v logic.
      Note: I had a machine where I thought I had cut the trace, but it wasn’t cut all the way, but it still worked, so you might be able to skip this. Ie mine worked fine even though it was still setup as running 5v logic, which means it was still without correct readings it seemed.

Configuring BLTouch

Now that we have everything hooked up, we need to setup our firmware to be able to use it. This includes creating some files and editing config.g and in some cases also bed.g

Create a Deploy and Retract file

Regardless of setup we need to create a deployprobe.g  and a retractprobe.g file.

  • Deployprobe.g
    M280 P7 S10 I1
  • Retractprobe.g
    M280 P7 S90 I1
    These files are used to execute our probe as needed.

Note: If you use Duex2/5 you do not need the i1 parameter

Create a Levelplate Macro Group

This is not strictly necessary, but really usefull, so go to your Macro area and create a new Directory named BLTouch.

Now we create some macros as shown:

  • Alarm Release + Pin UP
    M280 P7 S160 ; Alarm Release and Push-Pin UP
  • Pin Down
    M280 P7 S10 ; Send PWM channel 7 the s10 (angle) command
  • Pin Up
    M280 P7 S90 ; Send PWM channel 7 the S90 (angle) command
  • Self-Test
    M280 P7 S120 ; Send PWM channel 7 the S10 (angle) command

You might want to create some more macros to quickly run your probe to the center of your bed and each corner etc.

Change config.g file

We need to make some changes in our config.g file in order to make use of our probe.

Please note that some or all of these entries exists in your config.g file alrleady if you used the RepRapFirmware online configurator to create your files.

Disable Heater 7

We use M307 to disable Heater 7 to free up the PWM5 channel for our servo (probe).

I’ve put this down with my oher Heater settings for hotend (M301) and heated bed (M307) in the config.g file.
; BLTouch - Heaters
M307 H7 A-1 C-1 D-1 ; Disable the 7th Heater to free up PWM channel 5 on the Duex board.

Change Endstop Settings

Next up we need to change our Endstop Settings, which is done using M574 gcode

It might look something like this now:
M574 X1 Y2 Z2 S1 ; X home to min. Y and Z home to max. Normally Closed limit switches.
We need to remove the Z2 from this line, and add a new line defining Z as using a probe.

The two new lines are going to look like this:
M574 X1 Y2 S1 ; X home to min. Y home to max. Normally Closed limit switches.
M574 Z1 S2 ; Define Z to use Probe. Home to Min

Define Probe Type

Next up we define our probe type using M558, which is Type 5 in our case:

  • P is probe type
  • H is diveheight, which means how far bed moves down/hotend up, between each probes
  • F is the speed of bed up/down movement. If it’s too slow the Probe pin might hit the bed and cause an error.
  • T is the movement speed between probepoints.
  • The X, Y and Z denotes which axes are used by the probe. X and Y are not used, while Z is.

M558 P5 H5 F500 T4000 X0 Y0 Z1 ; Set Z probe type/mode 5. H=Dive Height. F=Speed the bed moves

Probe Position

Next up we use G31 to define the Sensor’s offset from the nozzle in XY and the Bed in Z.

My carriage with hotend and BLTouch looks like this seen from below.

As you can see, the BLTouch is placed:

  • X is directly in line with the nozzle (X0)
  • Y is -25.3mm in front of nozzle (Y-25.3)
    • Note: if you build my xBot it most likely is further away due to the nature of the Carriage.
  • We start with a Z offset of 0.0mm in regards to actual probe activation and factual distance. This value will be adjust later on, to match our setup.
    • Important: It is important to have Z-offset at 0 before calibrating.
  • P is the value needed to trigger the BLTouch. I’ve seen and tried a lot of different values between 25 and 600 and havn’t noticed any difference. But put a pin on this one in case your probe results are inconsistent.

G31 P25 X0 Y-25.3 Z0.0 ; Z probe trigger value, offset in relation to nozzle. And trigger height adjustment

Define Mesh Grid

Next up we use M557 to define the grid on our printbed we want to probe, in order to create a Mesh the controller can use to compensate for surface inaccuracies.

We start by typing M557 then define start and end points on our X and Y axes. Example below shows how we probe from X5/Y5 to X205/Y165.

The Snn parameter defines the spacing between each probe point, where we have defined it to probe with 20mm interval.

Hint: It can be useful to start out with a big interval like 40mm, to make the probing sequence faster, and it is useful to do some manual leveling based on the probing result.
Afterwards, if you have individually driven motors, you do a fine mest for auto compensation when you can’t manually adjust it any better.

Note: There is a maximum of 400 points available for probing, so making it too fine will result in an error. If you get an error, try raising the Snn parameter.

M557 X5:205 Y5:165 S20 ; Define mesh grid

You could do your Mesh Probe sequence now, but it’s important to calibrate your BLTouch first, by calculating the Z-offset

Total Configuration – Summing up

  • Config.g changes Lets combine all our code snippets and put them in our config.g file at your current Endstop section.
  • M574 X1 Y2 S1 ; X home to min. Y home to max. NC microswitches.
    M574 Z1 S2 ; Define Z to use Probe. Home to Min.
    M558 P5 H5 F500 T4000 X0 Y0 Z1 ; Set Z probe type/mode 5. Not using on XY, but using it on Z.
    G31 P25 X0 Y-25.3 Z0.0 ; Z probe trigger value, offset in relation to nozzle. And trigger height adjustment
  • Disable the Heater PWN channel to free it up for our usage:
    ; BLTouch - Heaters
    M307 H7 A-1 C-1 D-1 ; Disable the 7th Heater to free up PWM channel 5 on the Duex board.
  • New Configuration Files
    Regardless of how your setup looks we also created a deployprobe.g  and a retractprobe.g file.

    • Deployprobe.g
      M280 P7 S10 I1
    • Retractprobe.g
      M280 P7 S90 I1
      These files are used to execute our probe as needed.

Note: If you use Duex2/5 you do not need the i1 parameter

    • Macros
      While not strictly necessary it comes in very handy to have created these:

      • Alarm Release + Pin UP
        M280 P7 S160 I1 ; Alarm Release and Push-Pin UP
      • Pin Down
        M280 P7 S10 I1 ; Send PWM channel 7 the s10 (angle) command
      • Pin Up
        M280 P7 S90 I1 ; Send PWM channel 7 the S90 (angle) command
      • Self-Test
        M280 P7 S120 I1; Send PWM channel 7 the S10 (angle) command
      • It isalso very usefull to creeate macros on various places on your bed. Ie in the front corners, center of bed and center rear and so on, depending on your setup.

Note: If you use Duex2/5 you do not need the i1 parameter

Calibrate our sensor.

Now is the time to define the Z-offset parameter in the G31 command in our config.g which looks like this right now:

G31 P25 X0 Y-25.3 Z0.0

Find Z-offset:

  1. Move your sensor to around the middle of the bed. You might even want to make a Macro for this, as it can be usefull for many different cases.
    1. Herer’s a simply macro I named Move to Centerbed, where I home X and Y first:
      G28 XY
      G1 X100 Y120 F4000 ; Move probe to middle of bed
  2. Move Z untill your nozzle is about 10cm (4 inches) from the bed.
    1. Be ready to click the Emergency Stop in case the probe misbehaves.
    2. Now issue G30 command.
    3. Your BLTouch should now send the Pin Down and your bed should now move up (or nozzle down) untill the BLTouch is triggered.
    4. Hit the Emergency Stop if it didn’t stop or the Pin didn’t drop down.
      1. Go through your deployprobe.g if the Pin didn’t drop down.
  3. With #2 successfull you put your sensor over the middle of the bed and jog Z axis untill your nozzle is touching the bed.
    1. Note: If it refuses to move as it has reached Z-minima you can type in G92 Z5 to tell it, that you are 5mm from Z=0.
  4. Once your nozzle just touched the bed tell the machine we are at Z=0 by issuing:
    G92 Z0
  5. Move Z 10mm away from nozzle
    G1 Z10
  6. Now send G30 S-1 at which point the Pin drops down and the z-axis closes the gap until the BLTouch is triggered. Z now stops moving and reports the current position without changing anything. Note down the reported value.
  7. You might want to repeat the steps 4-6 a few times to insure consistency. I personally just did it 2 times and later did final adjust by looking at print starts.
  8. Mine reported the following:
    G30 S-1
    Stopped at height 0.980 mm
  9. This means I’ll change the Z parameters in the G31 line from 0 to 0.98.
    G31 P25 X0 Y-25.3 Z0.98
    Important: The higher Z value the closer you move the nozzle and bed to each other! It’s better to have a value too low here than too high to avoid the nozzle and bed doing a mating game when homing. 
    Important: If you later redo the offset method you must set the offset to Z0 before starting or it might lead to strange results I’ve found on some occasions.

Run Mesh Grid Compensation sequence

Now that we have all our parameters in place we can run a Mesh Probe Sequence by clicking the “Run Mesh Grid Compensation” via the Drop Down Menu, or just type in G29

This Mesh Grid consists of a lot of X, Y and Z coordinates. It can be very helpfull to use this to do some manual adjustment of the Z plane. Ie, meaning you try to make your printbed as level as possible manually by running some faster rougher sequences, and then use a final high resolution mesh sequence when done.

The first Mesh Probe sequence I ran at 11:23 had a mean error of 0.182 and a deviation of 0.084. In normal words the rear bed was a tad higher than the front, so I gave the center rear screw half a turn and did the sequence again. This time the mean error went down to 0.077 and the deviation also decreased a good deal.

You can hover the mouse over the probe points to see the XYZ coordinates.

By Running the mesh grid compensation sequence by either clicking in the menu or typing G29 it will be saved into the file heightmap.csv and be activated.

Save Custom named height maps

If you use multiple different surfaces as I do, you might want to have several heightmaps on hand.

You can use M374 to save the heightmap with a different name than the default heightmap.csv. Below I’ve saved the heightmap as “bareplate.csv” as this is directly onto the surface of my PEI-Coated aluminium plate.

I’ll be making different files for when I’m using glass for printing Nylon, FlexiPlate for PLA and so on.

In order to use one of our custom named heightmaps we can not just use G29 S1 to load the default map, but instead we use M375 to call up our desired height map:
M375 P"bareplate.csv"

Before Printing

Before we can wrap up our configuration we need to adjust our homeing files to match.


The Gcode G30 is actually enough to deploy the probe and make your Z axis home. I’ve added a line to move the bed to Z=10 after probing like so:

; Homez.g
G30 ; Do a single probe to home our Z axis
G90 ; Make sure we are in absolute mode

G1 Z10 F6000 ; Rapidly move the Z axis to Z=10.

The G30 just probes and set Z to 0. The Offset we configured previously adjust the distance to match.


I’m a bit confused here actually as it seems the machine uses homeall and then issue homez even if we havn’t made references to it in the homeall.g file.

Can anyone shed light on this behaviour?

Slizer startup gcode

In order to actively be using our Mesh and use the Sensor when we print, we need to add some lines to our slizer’s startup gcode

  • Here I’m first homing my X and Y axis.
  • Then clearing any Bed Transform I might have in place, as it would otherwise affect the probing.
  • I’m then moving the probe to be at the middle of the bed. If it oozes, you might want to omit or change this.
  • I’m then issuing the G30 command which brings my Z axis to close the distance between nozzle and bed and do the single probe.
  • Now it’s time to load the heightmap we have created previsouly using our Mesh Grid. It is important this comes after the bed probe.
    • You either use G29 S1 to load the default heightmap.csv or you use the M375 to load a custom heightmap.
    • I’ve loaded my custom heightmap below.
  • Finally I’m moving the Z to 20

G28 XY ;Home XY
M561 ; Clear any bed transform that might be in place
G1 X104.5 Y130 ; Move Probe to middle of bed
G30 ; Do a single probe
M375 P"bareplate.csv" ; Load my custom heightmap. Otherwise use G29 S1
G1 Z20.0 F6000 ; Move Z to 20

Multi Z-motors setup using bed.g

Now we have all the common stuff in place we are ready to look at the functions where we use the bed.g file to define how our individual Z-motors are placed and react when probing.

Note: Remember I’m talking from a Box Printer perspective here, but you can use it just fine for Tower Printers  just keep my references in mind!

In order to use the multi z-motor functione we use he multi-probe gcode G32 when homing Z, which calls on the macrofile bed.g where we have multiple probe points instead of just using the single probe point defined via M557 in our config.g file, using the single-probe command G30.

Z-Leadscrew placements

In order to put in some meaningfull coordinates in bed.g we need to know where our Z-leadscrews are in relation to our probe.

Here we can see the placement of my 3 leadscrews on my xBot printer, in relation ot the fingerscrews on my bed.

I used the rear center screw to pinpoint the exact XY coordinate of the probe in relation to the screws.

The numbers in the red circles are the placement and numbering of my Z-motors, while the square boxes indicates the coordinate and probe sequence of my bed.g file.

  • The bed.g starts by issuing a M561 to clear any bed-plane fitting/transform we might have in place by a previous probing.
  • Next we clear any heightmap we might have in effect as the height map should only be loaded after performing our bed leveling probe sequence.
  • Deploy our probe using M401 which simply call on our deployprobe.g we created earlier.
  • Now we come to the business of defining where we probe our bed. We issue the G30 command 3 times, starting with motor 1 through 3.
  • It is 3 times as I have 3 independent Z motors.
    • Important: It is very important we use same sequence as we will be defining the leadscrews in our config.g (next step) file using M671
  • The S3 we have listed after our third line of G30 is crucial to the function, as it must be equal to the number of probe points/individual leadscrews we are using.
    • The strange Z-9999 is there as a Z value less than -9999 causes the machine to probe at the current point to get Z, rather than using the given value.
    • If an S field is specified (e.g. G30 P2 X100 Y165 Z-9999 S3) the bed plane is computed for compensation and stored which is exactly what we want here!
    • if using a Tower Printer with 2 individual Z motors, you would put S2 after the last line instead.
  • Now that we have probed one time pr leadscrew and set it up for computation we retract our probe using M402, which just calls our retractprobe.g file.

; bed.g
; Called using G32
; Called to perform True Autolevel using 3-point probe
M561 ; clear any bed transform
G29 S2; Clear bed height map

; Probe 3-point
M401 ; Deploy probe - deployprobe.g
G30 P0 X200 Y0 Z-9999 ; Front Right
G30 P1 X0 Y0 Z-9999 ; Front Left
G30 P2 X100 Y165 Z-9999 S3 ; Center Rear
M402 ; Retract Probe - retractprobe.g

Define XY Coordinates in config.g

When using the bed.g file to setup multiply points to probe in relation to the leadscrews, we need to define the XY position of the leadscrews in our config.g file.

These coordinates will be outside our printing area and can as such be much higher and even have negative values.

In order to define these, we use the M671 which I’ve placed above my Endstop section in the config.g file.

We obviously also need to know where our leadscrews are placed in relation to our nozzle, for which I’ve made this drawing:

The coordinates we fill in using M671 are the XY coordinates placed at each of the round numbers, in that order.

Remember you can do this with just 2 individual Z-motors, and as such do not need 3 for full autolevel. Using 2 motors will only level the bed on one axis though, but that is still very neat.

The actual syntax used here is a bit strange as we start by issuing the M671 command, then type the axis in question (X at first), followed by the 3 X coordiantes, seperated by :
Next up we do the same with the Y coordinates and terminated by the optional S3 parameter – not to be confused by the S3 we used above!

I used 3mm in the S as I had some issues with Z sync not working as I wanted it to do. It’s defaulting at S1, so you might do fine without specifying anything for S.

; Define the X and Y coordinates of the leadscrews.
; Must come after M584 (Set drive mapping), M667 (Select CoreXY Mode) and M669 (Choosing Kinematics type)
; Motor order: Front right (1), front left (2), rear center (3).
; Snn Maximum correction in mm to apply to each leadscrew (optional, default 1.0)
M671 X256.6:-53.6:100 Y239.10:239.1:65.50 S3

Lets have a look at Homing using a Probe

Now everything is setup according to our system and we are ready to do an autolevel for the first time.

I’m writing Autolevel as my machine is doing an actual true autolevel. If you use 2 z-motors you “only” level it on one axis where as the Mesh Grid applied after the autolevel is our Auto Compensation.

You need to have homed the X and Y axes before starting, but aside from this, you only really need to type in G32 to do the magic.

It will do a probe sequence on the 3 coordinates defined in the bed.g file and calculate the Z-plane based on these measurements and coordinates of the leadscrews as we just defined in our config.g using M671

If you wonder, my homez.g file just home using a single probe action and rapidly moves the bed down again. I have this in place if I want to redo offset.
; Homez.g
G91 ; Relative Positioning
G90 ; Absolute Positioning
G1 Z20 F4000

Slizer Startup and Endcode Examples

As a rounding up on this post I’m posting my start and end codes on 2 machines:

Single Z-Motor Machine

I’m using Cura as my slizer, so I do not need all the “wait for temperature” gcodes of some other slizers, as these are automatcially in place – except for Chamber Heater, which you must add manually if using such a one.

; Startup Gcode
G91                        ; Relative Positioning
G1 Z-1                     ; Move Z down 1mm
G90                        ; Absolute Positioning
G28 XY                     ; Home XY
M561                       ; Clear any bed transform
G1 X104.5 Y130             ; Move Probe to middle of bed
G30                        ; Do a single probe
M375 P"flexiplate.csv"     ; Load heightmap (you can use G29 S1 instead)
G1 Z20.0 F6000             ; Move Z to 20
G1 X5 Y5                   ; Move Head to front left
G92 E0                     ; Zero Extruder
G1 F200 E15                ; Prime the extruder
G92 E0                     ; Zero Extruder


; End Gcode
G10 P0 R-273.15 S-273.15     ; Turn off Tool0
G10 P1 R-273.15 S-273.15     ; Turn off Tool1
M140 S-273.15                ; Turn off Bed
M106 S0                      ; Object fan off
G1 Z210                      ; Move Z to Z210
G92 E0                       ; Zero Extruder
G1 E-2 F300                  ; Retract 2mm
G92 E0                       ; Zero Extruder
G28 XY                       ; Home XY
M84                          ; All motors Off

Triple Z-Motor Machine

And my startup gcode for my xBot triple Z-motor machine.

; Startup Gcode
G91                      ; Relative Positioning
G1 Z-1                   ; Move Z down 1mm
G90                      ; Absolute Positioning
G28 XY                   ; Home XY
M561                     ; Clear any bed transform
G1 X104.5 Y173           ; Move Probe to middle of bed
G32                      ; Start 3-point probe sequence
M375 P"bareplate.csv"    ; Load heightmap
G1 Z20.0 F6000           ; Move Z to 20
G1 X5 Y5                 ; Move Head to front left
G92 E0                   ; Zero Extruder
G1 F200 E20              ; Prime the extruder
G92 E0                   ; Zero Extruder

My Endcode for xBot

In this one I home it to XY and U. The U is my virtual axis I’ve made for Z in order for it to be able to home to Z max, which I can’t otherwise do.

This doesn’t work with the setup for the single Z-machine. I have not yet had time to see if I can get around this, by using bed.g even though I don’t need it for that one.

; End Gcdoe
G10 P0 R-273.15 S-273.15   ; Turn off Tool0
G10 P1 R-273.15 S-273.15   ; Turn off Tool1
G10 P2 R-273.15 S-273.15   ; Turn off Tool2
M140 S-273.15              ; Turn off Bed
M141 S-273.15              ; Turn off Chamber Heater
M106 S0                    ; Object fan off
G92 E0                     ; Zero Extruder
G1 E-2 F300                ; Retract 2mm
G92 E0                     ; Zero Extruder
G28 XYU                    ; Home XY and U to Z max
M84                        ; All motors Off


Gcodes Used

Here’s a list of (some of) the M and Gcodes introduced in this post:

  • G28
  • G29 – Detailed Z-Probe
  • G30 – Single Z-Probe
  • G31 – Set or Report Current Probe Status
  • G32 – Probe Z and Calculate Z-Plane


  • M280 – Set Servo Position
  • M374 – Save height map (with alternate name)
  • M375 – Load (custom) height map
  • M557 – Set Z Probe point or define probing grid
  • M558 – Set Z Probe Type
  • M561 – Set Identity Transform (Reset any Mesh probes or adjustments in place)
  • M671 – Define positions of Z leadscrews or bed levelling screws