firmware:klipper:bltouch-with-raspberry-pi

This is an old revision of the document!


HowTo Run BLTouch connected to RPi microcontroller

  • some printer board dont support the control signal for the bltouch, or need to remove some components. in this case you have to fiddle a little with software, but
  • BLTouch
  • a plier or smth to remove one pin from the dupon-connector
  • remove the red pin from the triple-connection cable and put it into a single dupont case
  • connect the pins to the gpio pins:
    • white → GPIO12
    • black → GND next to GPIO12
    • yellow → GPIO27
    • brown → GND
    • red → 3.3V
    • Todo: Add a picture of the wires
  • you can choose whatever pins you like, but it's easier to follow if you choose the same
  • add the following to your printerconfig.cfg (also see the config reference
  • printer.cfg
    [mcu rpi]
    serial: /tmp/klipper_host_mcu
     
    [bltouch]
    sensor_pin: ^rpi:gpio12
    #   Pin connected to the BLTouch sensor pin. Most BLTouch devices
    #   require a pullup on the sensor pin (prefix the pin name with "^").
    #   This parameter must be provided.
    control_pin: rpi:gpio27
    #   Pin connected to the BLTouch control pin. This parameter must be
    #   provided.
    z_offset: 0.2
    #pin_up_touch_mode_reports_triggered: False
    #probe_with_touch_mode: True 
  • thats not the best way to do it, but it works, so here is how and why
  • klipper is unable to set the pullup-resistor for GPIOs on a raspberry pi because thats not implemented in the raspi-kernel (and thats where Mcu runs).
  • So, to fix that up, we will use a script that sets the gpio as pullup and monitors the mcu firmware. if the firmware changes (restart) it will set the pullup to the gpio again
  • sudo apt install inotify-tools
  • cd /home/pi
  • nano pgio.sh

    and paste the following

  • pgio.sh
     #!/bin/sh
    set_gpio () {
      raspi-gpio set 12 ip pu
    }
    set_gpio
    while true; do
      while inotifywait -e create /tmp/klipper_host_mcu; do
        set_gpio
      done
    done
  • make the script executable
    chmod +x gpio.sh
  • next we will add our script to cron, so it will run after reboot
  • sudo nano /etc/cron.d/gpio
  • and paste this inside (make sure there is a newline at the end)
  • @reboot pi /home/pi/gpio.sh& > /dev/null
  • thats it, reboot your pi and check if you script is running
    pi@mainsail:~ $ ps aux | grep gpio.sh | grep -v grep
    pi         457  0.0  0.0   1940   376 ?        S    02:28   0:00 /bin/sh /home/pi/gpio.sh
  • replace your endstop_pin under [stepper_z] with
    endstop_pin: probe:z_virtual_endstop
  • set your correct nozzle offset following the official guide
  • firmware/klipper/bltouch-with-raspberry-pi.1647308566.txt.gz
  • Last modified: 2022/03/15 02:42
  • by vidschofelix