Skip to content

Installing Bed Distance Sensor

Mark edited this page Oct 24, 2023 · 90 revisions

This installation is for the printers running Marlin firmware.

Step1. Attach the sensor cable to the mainboard

the wires CKL and SDA of BDsensor can be connect to any GPIO pins of your mainboard. You can also connect the BDsensor cable into the Bltouch port directly(except the MKS board),for example:

BLtouch    |    BDsensor
 5V       -->     5V
 GND      -->     GND
 S        -->     SCL/CLK
 Zmin     -->     SDA

Since some of the pins on the mainboard maybe not connected to gpio of MCU directly (e.g. there is a filter capacitor on it or isolated by mosfet, diode or optocoupler, but it's OK if they are isolated by resistors or pullup/pulldown by resistors), they cannot work with BDsensor. and the firmware will report connection error. For example

  • The connectors for FANs and Heaters are isolated by mosfet,
  • The connectors for temperature thermistors and Endstops/Probe in some boards like MKS are normally connected to GND by filtered capacitors,

Please feel free to send me or share your connection picture if you are not sure.

Step2. Mount the BDsensor near to the hot end. STL of mount

https://raw.githubusercontent.com/markniu/Bed_Distance_sensor/new/doc/images/Connection1.jpg

Step3. Configure & flash Marlin firmware

The BDsensor have been integrated to Marlin2.1.x(Since 2022.8.27),

you can download the release version. but now recommend downloading the latest bugfix version: https://github.com/MarlinFirmware/Marlin

What do you need is change the configure file and pins file.

Edit Configuration.h

1. Enable BD_SENSOR

Uncomment

#define BD_SENSOR
#define Z_SAFE_HOMING

#define BD_SENSOR_PROBE_NO_STOP //adding this new line for fast bed leveling without nozzle stop,

the BD_SENSOR_PROBE_NO_STOP is a new feature only in the

latest marlin bugfix:https://github.com/MarlinFirmware/Marlin

Description: https://github.com/MarlinFirmware/Marlin/pull/25847

2. Homing with probe

make sure the Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is disabled and USE_PROBE_FOR_Z_HOMING should be enable like the following

//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
// Force the use of the probe for Z-axis homing
#define USE_PROBE_FOR_Z_HOMING

3. Slow down the second homing Z speed

#define Z_PROBE_FEEDRATE_SLOW (Z_PROBE_FEEDRATE_FAST / 16)

Here we have to slow down bump homing speed and Z homing speed, because the endstop read from BDsensor process is not in the real time like normal endstop.

Edit Configuration_adv.h

#define BABYSTEPPING // enable this for the feature of real time leveling

#define HOMING_BUMP_DIVISOR { 2, 2, 8 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)

Edit pins_boardname.h

Configure the pins for the SDA and SCL of the BDsensor in your pins file pins_boardname.h (E.g. pins_PANDA_PI_V29.h) by adding the following 3 lines:

#define  I2C_BD_SDA_PIN    PC6   // Please change to the actual number which the SDA wire is connected to your mainboard
#define  I2C_BD_SCL_PIN    PB2   // Please change to the actual number which the SLK wire is connected to your mainboard
#define  I2C_BD_DELAY  20      // default value is 20, should be in the range [20,50].

if you want to do the auto bed leveling probe (G29) before print like normal BLtouch, Uncomment

#define AUTO_BED_LEVELING_BILINEAR

and edit the value like the following

#define Z_CLEARANCE_DEPLOY_PROBE   0 // Z Clearance for Deploy/Stow
#define Z_CLEARANCE_BETWEEN_PROBES  1 // Z Clearance between probe points
#define Z_CLEARANCE_MULTI_PROBE     1 // Z Clearance between multiple probes

in the Configuration.h

Step4. Display BD sensor value on LCD

For the printer has status display(support gcode M117) like LCD12864 or some uart screen like ender3V2 ...

Step5. Calibration

1)Clean the nozzle, then manually move the Z axis until the nozzle just touches the bed plate(The BDsensor will use this position as the 0 point,so the z_offset is no needed and we set the value as 0).

2)Reboot the printer, Send gcode M102 S-6,then it will move the z axis slowly up 0.1mm everytime until it reach to 3.9mm.done Don't run M102 S-6 before you install the sensor and don't power off the printer while calibration, or else the old calibrate data will be erased. if in that case just do calibration again.

3)You can check whether the BDsensor has been calibrated successful by M102 S-5 that will return the raw calibration data which stored in the BDsensor.

There is also a Calibrate Tools to do that: https://github.com/markniu/Bed_Distance_sensor/raw/new/marlin/BD_Config_Tool_Marlin.zip

Note: data value 1015 or > 1010 that means out of sensor range. if the value of the first 5 points(0~0.5mm) or more are in the range 0 to 1000, and the increased value delta is >=10 that means calibrate successful. like the graph shown above.

If the first raw calibration data returned by the M102 S-5 is greater than 400, that means the sensor is mounted too high and needs to be remounted closer to the bed. also make sure that the second data is greater than the first data value by more than 10

Step6. Test and printing

Menu bed level

Auto bed level

There are 2 ways to do auto bed leveling:

1.Real time leveling at first few layers with M102

we can easily enable or disable this auto level by sending gcode command or and adding gcode in the gcode file.

To enable bed leveling in Cura, add the M102 G-Code right below the G28 (Home All Axes) G-code in the Start G-code section of your printer’s Machine Settings. For example M102 S2 below the G28 , that means it will only do bed leveling below 0.2mm of Z axis height.

Send M102 S0orG28or M18 will disable bedlevel with BDsensor,BTW,this is disabled by default.

M102   S-1     //Read sensor information, and we can use this for connection checking.
M102   S-2     //Read current distance value
M102   S-5     //Read raw Calibrate data
M102   S-6     //Start Calibrate,before that make sure the nozzle is just touched the bed,and then the printer restarted. don't home z axis before this.
M102   S4      //Set the adjustable Z height value,e.g. M102 S4  means it will do adjusting while the Z height <=0.4mm , disable it by M102 S0.

2. Auto Bed Leveling with G29

Another way to do auto bed leveling is like BLtouch with G29,just add a line G29 below G28.

Installation Video

Installation Video from Chris's Basement

Check the Z endstop by M119

Please do not Homing Z until you have checked this step or else the nozzle maybe cashes the printer bed.

This is the return message after sending M119 command(Reporting endstop status).

Send: M119
Recv: x:open y:open z:open

if the z min is not in open,please check #define Z_MAX_ENDSTOP_HIT_STATE HIGH in your configuration.h

  • make sure the z motors off/unlock

  • move the z axis down with hand until the nozzle close the bed

  • send M102 S-2, the return value should be 0.00mm and then send M119 again, you can see the z endstop is triggered now.

Send: M119
Recv: x:open y:open z:TRIGGERED

Check the connection

Check the connection by M102 S-1. Here is an example of the return message, please check the connection and wire order if it return blank or other string.

Send: M102 S-1
Recv: V1.0 pandapi3d.com
  • If all above steps are right, then you can homing z axis now.

Note:

  • If the first raw calibration data returned by the M102 S-5 is greater than 400, that means the sensor is mounted too high and needs to be remounted closer to the bed. also make sure that the second data is greater than the first data value by more than 10
    • FAQ: if calibration data begins with 1 and second value is 9 and third 24 what that means?
    • that means the resolution between 0-0.1mm is only 9,and the 0.1-0.2mm is 15.so recommend to calibate again let the first resolution 0-0.1mm bigger than 10