BTT Smart Filament Sensor - Weird Behaviour

Basic Information:

Printer Model: HevoRS (DIY Printer)
MCU / Printerboard: BTT Octopus
klippy.log

Fill out above information and in all cases attach your klippy.log file (use zip to compress it, if too big). Pasting your printer.cfg is not needed
Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there

Describe your issue:

Hey,
I tried to setup the BTT Smart Filament Sensor and followed this tutorial:

The Sensor acts in a weird way. It does trigger in 80% of the time after starting without there being a clog. When resuming, however, it does not trigger although there being a jam or clog.

I set it up outside my enclosure and the filament then is guided to the Orbiter extruder through a PTFE-tube. But I think hardware is not the problem, I guess it must be a software problem.

So this is how I included the sensor in my printer.cfg

[filament_motion_sensor SFS_T0]
detection_length: 50
extruder: extruder
switch_pin: ^PC5
pause_on_runout: True
event_delay: 3.0
pause_delay: 0.5
runout_gcode:
    M117 FILAMENT OUT


[delayed_gcode DISABLEFILAMENTSENSOR] ; This will disable the SFS 1 second after klipper starts
initial_duration: 1
gcode:
    SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=0 ; Put your filament sensor's name after SENSOR= SFS=T0e

This is what I included at the end of my start-gcode:

SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=1 ; Put your filament sensor's name after SENSOR= 

This is my Pause and Resume Macro. What’s also weird is that the park position is on the right side in the back and not in the front on the left (X10 Y10).

[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
gcode:
    # Parameters
    {% set z = params.Z|default(10)|int %}                                                   ; z hop amount
    
    {% if printer['pause_resume'].is_paused|int == 0 %}     
        SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE={z}                              ; set z hop variable for reference in resume macro
        SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=etemp VALUE={printer['extruder'].target}    ; set hotend temp variable for reference in resume macro
                                
        SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=0                                           ; disable filament sensor       
        SAVE_GCODE_STATE NAME=PAUSE                                                          ; save current print position for resume                
        BASE_PAUSE                                                                           ; pause print
        {% if (printer.gcode_move.position.z + z) < printer.toolhead.axis_maximum.z %}       ; check that zhop doesn't exceed z max
            G91                                                                              ; relative positioning
            G1 Z{z} F900                                                                     ; raise Z up by z hop amount
        {% else %}
            { action_respond_info("Pause zhop exceeds maximum Z height.") }                  ; if z max is exceeded, show message and set zhop value for resume to 0
            SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE=0
        {% endif %}
        G90                                                                                  ; absolute positioning
        #G1 X{printer.toolhead.axis_minimum.x/2} Y{printer.toolhead.axis_aximum.y+5} F6000   ; park toolhead at front center
        G1 X10 Y10 F6000 
        SAVE_GCODE_STATE NAME=PAUSEPARK                                                      ; save parked position in case toolhead is moved during the pause (otherwise the return zhop can error) 
        M104 S0                                                                              ; turn off hotend
        SET_IDLE_TIMEOUT TIMEOUT=43200                                                       ; set timeout to 12 hours
    {% endif %}

[gcode_macro RESUME]
rename_existing: BASE_RESUME
variable_zhop: 0
variable_etemp: 0
gcode:
    # Parameters
    {% set e = params.E|default(2.5)|int %}
    
    {% if printer['pause_resume'].is_paused|int == 1 %}
        SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=1                                   ; enable filament sensor
        #RESETRGB                                                                    ; reset LCD color
        SET_IDLE_TIMEOUT TIMEOUT={printer.configfile.settings.idle_timeout.timeout}  ; set timeout back to configured value
        {% if etemp > 0 %}
            M109 S{etemp|int}                                                        ; wait for hotend to heat back up
        {% endif %}
        RESTORE_GCODE_STATE NAME=PAUSEPARK MOVE=1 MOVE_SPEED=100                     ; go back to parked position in case toolhead was moved during pause (otherwise the return zhop can error)  
        G91                                                                          ; relative positioning
        M83                                                                          ; relative extruder positioning
        {% if printer[printer.toolhead.extruder].temperature >= printer.configfile.settings.extruder.min_extrude_temp %}                                                
            G1 Z{zhop * -1} E{e} F900                                                ; prime nozzle by E, lower Z back down
        {% else %}                      
            G1 Z{zhop * -1} F900                                                     ; lower Z back down without priming (just in case we are testing the macro with cold hotend)
        {% endif %}                             
        RESTORE_GCODE_STATE NAME=PAUSE MOVE=1 MOVE_SPEED=60                          ; restore position
        BASE_RESUME                                                                  ; resume print
    {% endif %}

[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
    SET_IDLE_TIMEOUT TIMEOUT={printer.configfile.settings.idle_timeout.timeout} ; set timeout back to configured value
    CLEAR_PAUSE
    SDCARD_RESET_FILE
    PRINT_END
    BASE_CANCEL_PRINT
    SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=0 ; Put your filament sensor's name after SENSOR=

[gcode_macro M0]
gcode:
  PAUSE
  

Can someone explain or guess what the problem might be?
Thanks!

The first problem is that you did not follow the given instructions.

1 Like

Thanks for the quick reply.
I re-read the instruction and I dont really know what you are refering to. What did I miss?
I could only spot a missing

G92 E0

in the resume code?
Sorry, I am a bit lost

I really do not know what else we should do. In bold and underlined and nevertheless it is regularly ignored but happily left standing in the post.
Effectively, this is wasting the time of each supporter here, who are offering their help and expertise in their free time at no cost.

1 Like

Thanks for your feedback.
I did read this, yet I did not post it for a reason:
The sensor stopping the printer at the start of the print has not happend in week or so, so I have no log of this event. The printer not recognizing a clog has happend recently but can something that has NOT happened be found in a log file? I am a noob so I actually cannot answer that question but thought the log would not be helpful.
Therefore, I thought posting the important bits - like the code I use - was enough in this case.
I am very grateful for everyone’s help and as you correctly say it’s free and it’s sombody’s free time, which of course I do not want to waste. But as I said, I did not not do it because of ignorance.
Appoligies for this.
I will post a log file as soon as the sensor stops the print again.

I think I found the solution.
I think the problem is the PAUSE and RESUME macro I posted in my original post.
It was not called, which I could see because my printer would not idle in its custom pause position (x10 y10) but always in the back.

I uncommented the [include mainsail.cfg] in my printer config, made it pause and now the idle position is X10 Y10.
I assume that PAUSE always called the macro from mainsail.cfg and therefore not my custom macro, which included the command to switch off/ on the sensor.
I need to test this but I am quite certain that this was the problem.

According to the mainsail documentation I need the mainsail.cfg file? Is that true?

No, for proper working Mainsail just needs the macros. If you have your own macros that provide functions like PAUSE, RESUME etc then it is fine as well. This is just offered for convenience.

The [include ...] stuff is just offering you a way to keep things organized but has the pitfall in which you just stumbled: If you have double defines in the files, the one that Klipper reads last takes precedence.

This is why the klippy.log is essential: Only there you will see with what information Klipper is actually working and what is happening, for example just before an error.

1 Like

Alright, I see, you are right!
I tested the printer’s behaviour a bit and still it does not work.
I guess the problem is that the sensor changes its state from “detected” to “empty” once it is triggered.
After it changes its stae to “empty” it will not work again. Only if I restart frimware, the state of “detected” will be obtained again.
Any idea what the problem might be?
I fiddled around with the configuation a bit but nothing helps.

Now I also attached my klippy.log
klippy(1).zip (1009.0 KB)

I removed such a sensor quite some time ago because I found it not reliable and I have seen reports of a defect sensors.

But just to be on the same page: As far as I’m aware, this sensor only works and updates its status in combination with a running extruder. The logic checks how much the extruder has moved and if a signal from the sensor was received in due time. If this is not the case, it triggers.

1 Like

Yes, the sensor actually is optical. A little wheel inside of it spins and the sensor detects holes in this wheel. That’s how it works and that’s probably also why extruder movement is needed.
My guess is that it triggers on the first layer because my printer is levelled too closely and the wheel spins slower as calculated and therefore the sensor assumes that there is a clog.
That is easy to fix.
What I cannot fix, however, is that once the sensor triggers, it does not change its status back to “detected” when I resume the print. The status stays “empty” until the printer/ firmware is restarted.

I would disable the sensor at the start of the start gcode so things are not being (mis)handled during startup and enable it at the end of the start gcode.

Also the recommended detection length for the old BTT Smart sensor was 7mm I though and works flawlessly for me with a setting of 10 or 12 mm. 50 mm is huge so what would the point be then?

Yes, if you are dragging the nozzle close to the bed so it can’t extrude the sensor should trigger.

The output of the sensor toggles on and off so looking at the state of the pin is not that helpful (I put LED’s on the outputs so I could see them toggling.

If it stays disabled then you have something messed in your enable/disable stuff. I use a macro to turn it on and off and print out the state so I can see it in the console.

Thanks for your answer.
Just to clarify why I used 50mm: I thought I could handle the sensor triggering at the beginning with that option, I started with 10mm. Now I know it’s due to bed levelling.
Having the sensor be activated at the second layer might be a good idea. I know how to add a custom g-code in Orca Slicer (Prusa Slicer) at a certain layer but that has to be done manually everything I slice something. Is there an option to add this to Custom Machine G-Code?

Well, as I said, it does NOT stay disabled. When I start the print, the status is “detected”, when triggered it becomes “disabled” and when continueing it comes “empty”. And I can only change that state when restarting firmware.

This is the macro I use in my resume code:

[gcode_macro SFS_ENABLE] ; Add this to PRINT_START
description: Enable smart filament sensor
gcode:
    M117 ENABLING the Smart Filament Sensor
    G92 E0
    SET_FILAMENT_SENSOR SENSOR=SFS_T0 ENABLE=1 ; Put your filament sensor's name after SENSOR=

That should activate the sensor, but it only changes its state to “empty”

My understanding is:

  • A triggered sensor will not prevent you from continuing and extruding
  • The sensor will reset itself as soon as it detects extruder movement in combination with pulses from the sensor

Thanks for that hint, mate! That actually was the solution.
As the status did not change back to detected, there must have been something wrong with the signal/ input from the sensor.
I tried another endstop pin and now it seems to work!
Thanks, mate!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.