Skip to main content

Installing the BDsensor

Connect the sensor cable to the mainboard or CAN bus toolhead board.

  • Note: The SB2040 cannot use the BDsensor.
  • Note: For the SHT36, the BD sensor's CLK/SCL (Input) needs to be connected to the high-voltage input port, and the jumper must be installed.
  • The BDsensor's CKL and SDA wires can be connected to any GPIO pin on the board. You can also connect the BD sensor cable directly to the BLtouch port, for example:
BLtouch    |    BDsensor
5V --> 5V
GND --> GND
S --> CLK/SCL (Input)
GND --> GND
Zmin --> SDA (Input/Output)
  • Some pins in the mainboard connectors may not be directly connected to the MCU's GPIOs (e.g., they might have filtering capacitors or be isolated via MOSFETs, diodes, or optocouplers, though isolation via resistors or pull-up/down resistors is acceptable). Therefore, they cannot be used with the BDsensor, and the firmware will report a connection error. For example:
  • Fan and heater connectors are isolated via MOSFETs.
  • Connectors for temperature thermistors and endstops/probes on some boards are often connected to GND through filtering capacitors.
  1. Install the BD sensor near the hotend as shown in the image below. STL of mount, STL_mount_VzBot_Goliath short

    Loading...

Apply the patch to the Klipper firmware.

  • Discard any previously modified Klipper files and update Klipper.

    cd
    cd ~/klipper
    git checkout .
    git pull
  • Clone the latest BD sensor code.

    cd && git clone https://github.com/markniu/Bed_Distance_sensor.git
  • Install.

    cd  ~/Bed_Distance_sensor/klipper/
    ./install_BDsensor.sh
  • Compile the firmware.

    cd ~/klipper/
    make menuconfig
    make clean
    make
  • Flash the firmware to the MCU or CANbus toolhead board where the BD sensor is connected.

If your printer runs Moonraker, add the following section to moonraker.conf. Then you can update the BDsensor with one click via the web interface or KlipperScreen.

[update_manager BDsensor]
type: git_repo
primary_branch: new
channel: dev
path: ~/Bed_Distance_sensor
origin: https://github.com/markniu/Bed_Distance_sensor.git
install_script: ./klipper/install_BDsensor.sh
is_system_service: False
managed_services: klipper
info_tags:
desc=Bed Distance Sensor

Edit printer.cfg

  • Copy this section into your printer.cfg and edit the [BDsensor] sda_pin and scl_pin. Also, don't forget to disable other probe sections like BLtouch. You can connect the BD sensor to the mainboard or the toolhead CAN module.

  • In [BDsensor], change speed to 0.8. This only applies to Z tilt and the PROBE_ACCURACY command. A smaller value increases accuracy during probing because the MCU reads the BD sensor in the main loop during homing, unlike a normal endstop which is read in real-time.

  • To use the BD sensor as a limit switch during Z homing, change the endstop_pin in [stepper_z] to endstop_pin: probe:z_virtual_endstop.

  • Ensure printer.cfg contains [safe_z_home].

  • Change the horizontal_move_z value in [bed_mesh] and [z_tilt] or [quad_gantry_level] to 1 (recommended 0.7-1.0 mm). Klipper's default is 5 mm, which can easily exceed the sensor's range.

  • Nozzle height should only be adjusted using z_adjust: in the [BDsensor] section. Positive values move the nozzle closer to the bed, negative values move it away. Other methods for adjusting nozzle height may have bugs.

  • To enable fast bed leveling, remove the # before no_stop_probe:true.

  • Below is a configuration example.

    [BDsensor]
    scl_pin: PC6 # Servo signal port
    sda_pin: PC3 # Limit signal port
    delay: 20 # 20us per pulse, this value should be >=20 but must be below 50
    z_offset: 0 # this `z_offset` must be set to 0.
    z_adjust: 0.0 # z axis adjustment, replaces the z_offset function. Range -0.3 to 0.3mm
    x_offset: -34
    y_offset: 0
    #no_stop_probe:true # enable this for fast probe, the toolhead will not stop at the probe point.
    position_endstop: 0.8 # the Z axis will stop at this position (mm) while homing Z, recommended value is 0.4~1.0
    #speed: 0.8 # this speed only works for the z tilt and PROBE_ACCURACY command.

    [stepper_z]
    endstop_pin: probe:z_virtual_endstop
    #position_endstop: 0.5
    homing_speed: 5
    second_homing_speed: 0.8

    [bed_mesh]
    speed: 200
    horizontal_move_z: 1
    algorithm: bicubic

    [quad_gantry_level]
    horizontal_move_z: 1

After installation, check by sending the following G-code commands.

M102   S-1     # Read sensor information
M102 S-2 # Read a distance value

Check the connection.

  • Send M102 S-1 via the console. Here is an example of the returned message. If it returns blank or other strings, check the connection and wire order.

    Send: M102 S-1
    Recv: V1.0 pandapi3d.com

Calibration.

  • Clean the nozzle, then move the Z-axis via the console until the nozzle just touches the bed (the BDsensor will use this position as zero, so z_offset is not needed. This is why it's set to 0 in the [BDsensor] section).
  • Send the G-code command M102 S-6 via the console. The printer will slowly move the Z-axis up 0.1mm at a time until it reaches 4mm. Do not run M102 S-6 before installing the sensor, and do not power off the printer during calibration, or the old calibration data will be lost. If this happens, simply calibrate again.
  • Afterwards, you can check if the BD sensor has been successfully calibrated by using M102 S-5, which returns the raw calibration data stored in the BD sensor.

Notes:

  • The Z-axis homing speed is best set to 5.
  • If the first raw calibration data returned by M102 S-5 is greater than 400, it means the sensor is installed too high and needs to be reinstalled closer to the bed. The recommended value for the first data point is 100. Also, ensure the second data point's value is at least 10 greater than the first.
    • FAQ: What does it mean if the calibration data starts with 1, the second value is 9, and the third is 24?
    • It means the resolution between 0-0.1mm is only 9, and between 0.1-0.2mm it's 15. It is recommended to recalibrate so that the first resolution (0-0.1mm) is greater than 10.
  • Do not forget to adjust the Z-axis height after running G28 or for the Z_tilt and quad_gantry_level commands.
  • Section names must be correctly capitalized; otherwise, Klipper will report Unknown pin chip name 'probe'.
Loading...