Filament Sensor NG

I have a filament sensor connected to the pi. The switch is wired as normally closed, filament is present, so when the filament runs out the switch opens. I have tested it for continuity and it is good. I have test the voltage across the the Pi GPIO pins and that operates properly also. If I set the plugin for normally closed Octoprint ignores the state of the switch. While printing I can open and close the circuit continually and it keeps on printing. If I set the plugin for normally open and keep the circuit open it will print. If I close it during print it will pause. Also if the switch is closed I can't start a print either. This does not make sense. Why will it work in normally open mode but not normally closed mode?

Hi @Raymond_Cag!

How did you wired up the switch? From the GPIO pin to ground? Then keep in mind, that you have to activate the pull up resistor.
BTW: What plugin do you use for this on the Pi?

Filament Sensor NG. GPIO to ground. I assumed that as part of the plugin install that the pull up would be activated. I have a Pi 3b and remember reading that the pull up resistors are activated by default.

I have just read from the raspberry pi forum that upon boot up the first 8 GPIO pins are automatically set with pull up resistors enabled and the rest with pull down enabled. This is new information for me. I have been connecting to pins 10 and up. Now I will have to try 1-8 later and see what happens.

1 Like

Still having problems getting this to work.I have tried Filament sensor, filament sensor reloaded and filament sensor NG plugins. None of them will work. I check the API for the filament sensor and it always state filament present weather the switch is open or closed and doesn't seem to matter which pin I assign it. I am also running the PSU Control plugin and I'm wondering if that is interfering with the operation of the filament sensor being properly read.

I also have this same issue on all three of the filament plugins. I checked the voltage at the pin an it is already at 3.5 volts with nothing attached to it. I already killed one Pi trying to figure this out so I am switching to using the smoothieware option and having it pause it for me. If anyone has any helpful help I rather use the pi VS the printer BD

I will try to help. I was able to get Filament Sensor NG to respond to my filament sensor. You need to know how your sensor works, the pins you will connect to and the proper set up of the plugin. My sensor works with a snap switch with a roller on it. These switches generally have three terminals. One is a common, you need a wire attached to this terminal. Of the other two, one is normally open and the other is normally closed. I would suggest using the normally closed part as this will give proof your circuit is complete. If you have a broken wire or bad connection you will get a no filament indication. If you use a normally open contact and have a broken circuit you will not get a no filament indication. I have my sensor switch connected to ground and BCM(8) physical pin #24.
The plugin settings for me PIN 8, Poll time 250ms, Event Confirmation 1, Switch Type NC, Board Pin Type BCM mode. Make sure the box on the bottom, Pause print when filament is out, is checked. This should electrically work and should be read by Octoprint. Also check the Debug box. You will need to add GCODE to the GCODE scripts section under the printer heading. You will find a section to tell your printer what to do "After print job is paused" and "Before print job is removed". These are something you have to figure out as there are slight variations between printers. Search the internet and you will find a lot of examples, you have to find what works for you. You will probable need to experiment with this.
If you installed multiple filament plugins you may have to edit the Octoprint configuration file, config.yaml, in order to get it to work.

1 Like

Thank you mate your attitudes have saved my ass !!!

You are great...:wink:

I can't for the life of me get this to work either..

My setup:

The physical part:
Filament switch (Normal Open) on pins 18 (BCM 24) and 20 (GND).

The config part:
Mode: BCM
Pin: 24
Type: Normal Open
Poll: 500ms
Event Confirmation: 5

Every time I press "Print", the print insta-cancels with a "no filament detected" error.

If I read pin 18 (gpio -g read 24) with filament in the sensor, I get the expected "0", and vice versa, I get a "1" with the same command when filament is out. So everything seems to be in order, but it still fails to work. Also, To make the circuit fool-proof/safe, I think you should have the switch as Normal Open. This way you get the same state if the filament is out or the circuit is broken. With a Normal Closed switch, you'd only catch a shorted circuit. (Or am I completely wrong here?)

I've been staring at the code for this plugin for a while, and I'm wondering if I've found the problem...

I was looking at the no_filament function

def no_filament(self):
    return GPIO.input(self.pin) != self.switch

It's a very simple comparison between the state of the chosen GPIO pin and the value given to the different types of switches, which is this:

<option value=1>{{ _('Normally Open') }}</option>
<option value=0>{{ _('Normally Closed') }}</option>

I've got a Normal Open switch, which means that "no filament" means the GPIO reads "1", and "has filament" reads "0".

If we now look at the no_filament function, it should return true when there is no filament.
The test in the no_filament function is a XOR logic test which gives the following array:

A | B | Result
--------------
0 | 0 | false
0 | 1 | true
1 | 0 | true
1 | 1 | false
  • So in my setup, I've chosen a Normal Open switch, so self.switch is "1".
  • With filament in my sensor, GPIO.input is "0".
  • 0 != 1
  • This comes out of the no_filament function as "true".
  • Everything grinds to a screeching halt.

Should I have chosen Normally Closed for my switch since having filament in my sensor closes the circuit? No, the plugin description says the following:

Whether the sensor should trip when the switch goes HIGH or LOW.
Normally Open is LOW when filament is present, and Normally Closed is HIGH when filament is present.

So I believe the problem lies in the no_filament function, and it should be a XNOR logic test (X == Y).

A | B | Result
--------------
0 | 0 | true
0 | 1 | false
1 | 0 | false
1 | 1 | true
  • With the Normal Open switch, self.switch is "1".
  • With filament in my sensor, GPIO.input is "0".
  • 0 == 1
  • This comes out of the no_filament function as "false".
  • Printing should commence as expected!
1 Like

I think I would post that as an issue on the plugin author's repository. I'm sure they would know right away.

hey im having a slimier problem with my rspi 3b+ using the same switch contented to pin 7 and ground in normally open. using Filament Sensor ng. i have tried using several different pins with no luck, i have a atx power supply controller connected to gpio 2 (bcm 13) that works no problem, any help would be grate

Try to limit your queries to one thread please.

Thanks @Raymond_Cag just followed your decription and works like a charm! :grin:

I there any way of adding a delay?

My sensor is mounted on the top of the printer so once the filament runs out i would be nice to, say continue running for 5 mins or so to use the last bit up.

I don't know about a delay, but it might be possible with the G-code that is processed when the sensor is tripped.

Thats what I was thinking but then thought any delay added by gcode would just delay the inevitability pause.

Aiming to have it continue printing and then pause.:thinking:

Hello Fudd79, haven't looked into the plugin code yet, but what you say makes absolute sense. I agree it looks like it needs to be XNOR instead of XOR. I am just stumbling into this exact issue and was wondering if you got this working by modifying the code?

Unfortunately no, @Alfi66. Not because the plug-in is b0rked, but because I think my mobo just doesn't handle Octoprint commands fully.

Well, I dove into it and you were dead on. I use Filament Sensor Reloaded plugin and had exactly the same issue. All turned down to changing one '!=' into '==' and it worked correctly immediatly.

From the plugin config page:


Normally Open is LOW when filament is present (is an incorrect statement as the GPIO pin should be 0):

Self switch = A = 0 (normally open)
GPIO pin = B = 1 (not pulled to ground by switch)

So:
A B
0 1 = Only True when filament is present
0 0 = Only True when switch is triggered (out of filament)


Normally Closed is HIGH when filament is present (is an incorrect statement as the GPIO pin should be 1):

Self switch = A = 1 (normally closed)
GPIO pin = B = 0 (pulled to ground by switch)

So:
A B
1 0 = True when filament is present
1 1 = Only True when switch is triggered (out of filament)


In the pyton file from the 'Filament Sensor Reloaded' plugin:

An excerpt of the checking routine:

def check_gpio(self, channel):
     state = GPIO.input(self.pin)
     if state != self.switch:    # If the sensor is tripped do the pause thing

So assuming:

A = self.switch
B = state (state = GPIO.input(self.pin)), status IO PIN

if B != A:    		   # If the sensor is tripped do the pause thing	
        
Will never work as long as A is not equal to B because A != B means filament present no matter what!

if B == A: 

Means status is triggered and sensor is working as it should