Setup filament sensor with rpi and Mainsail

I’m trying to set-up a simple filament sensor that uses a micro switch (same switch as the ender3 z-axis) and connected to a raspberrypi. It’s wired as NC, with one wire going to gpio17 and the other going to ground.

The relevant parts of my printer.cfg…

[mcu host]
serial: /tmp/klipper_host_mcu

[filament_switch_sensor FilamentStatus]
pause_on_runout: True
switch_pin: host:gpio17

I’m fairly certain the MCU part is working correctly because I also have an ADXL345 wired to the rpi and it works.

So far in Mainsail I can see that the sensor is there but it always reads like I’m out of filament (whether the switch is closed or open).

Any thoughts?

EDIT: it’s actually wired NC, I updated it above.

Hi, I think you have to enable the gpis in the raspberry pi configuration. Run
sudo raspi-config then go into “Interface Options” and enable I2C and SPI in each submenu.

Hope this helps.

1 Like

Thanks for the reply! Both are now enabled, but unfortunately it still does not work.

Here’s a little more detail…

When I enter gpioinfo it looks like gpio17 has been claimed by Klipper…

gpiochip0 - 54 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed       unused   input  active-high
        line   7:      unnamed   "spi0 CS1"  output   active-low [used]
        line   8:      unnamed   "spi0 CS0"  output   active-low [used]
        line   9:      unnamed       unused   input  active-high
        line  10:      unnamed       unused   input  active-high
        line  11:      unnamed       unused   input  active-high
        line  12:      unnamed       unused   input  active-high
        line  13:      unnamed       unused   input  active-high
        line  14:      unnamed       unused   input  active-high
        line  15:      unnamed       unused   input  active-high
        line  16:      unnamed       unused   input  active-high
        line  17:      unnamed    "klipper"   input  active-high [used]
        line  18:      unnamed       unused   input  active-high
        ...

Most likely you will need a pullup as well, like
grafik

1 Like

Yes, this is the way! Thx @Sineos!

For reference, this is how it’s now wired…

I’m using a microswitch that already has this resistor…

image

…and I’ve wired Signal → gpio17, GND → ground, +VCC → 3.3V

I also updated my printer.cfg like this:

[filament_switch_sensor FilamentStatus]
pause_on_runout: True
switch_pin: !host:gpio17
4 Likes