Modify filament sensor plugin to use with encoder sensor

Hello community.
I have built a filament sensor with rotary encoder and Arduino. I read the pulses with the Arduino.
Until first movement and when moving Arduino sends HIGH. If no pulses after first movement for 15sec then it sends LOW.
It's working nice so far.
My problem is that after the print is finished or stopped it sends LOW. So I can't start a new print unless I restart the system or press RESET on Arduino.

I have thought an easy fix. I want to enable the sensor after first layer or if Zheight>something.

In the filament sensor reloaded plugin that I use there is an if that tells to Octoprint if it should listen the sensor. So it listens only at the presence of events PrintStarted and PrintResumed. Out of this events the state of the sensor is ignored.

if event in (
        Events.PRINT_STARTED,
        Events.PRINT_RESUMED
    ):

Coding in python is beyond my skills and after searching a lot I couldn't find the way.
Is there a line add I can do to this plugin?

Something like Events.CurrentZ>0.3 ?
or Events.CurrentPosition.Z>0.3
I ll then modify my gcode from Cura to send M114 at start and after first layer.

I saw many people requesting a plugin for encoder filament sensor. I do the pulse reading from Arduino so no reading of pulses is needed for Raspbery . With this solution I will only miss sensing filament in first layer. Loosing one layer is not that bad if filament jams or tangles.

With this I will not need to interact at all with the sensor. I am pretty sure in a while someone will create an awesome plugin with timeouts and even measuring filament passed from the sensor. So even partial clogs will be traceable. Prusa has done it in firmware and others. Untill then Arduino does the job for me.

1 Like

The events you're looking for would be within gcode-processig. Probably PositionUpdate to process the results of the M114 command you add to the gcode.

1 Like

Yes. Position Update would be perfect. What's the syntax of it? I don't have way to compile it first. I didn't find it written in code. Only in Octohelp events but the syntax is not clear for a dummie. I only need someone to tell me the correct syntax. I suppose it would look like this.

if **Events.POSITION_UPDATE.z>0.3 and** event in  (
        Events.PRINT_STARTED,
        Events.PRINT_RESUMED
    ):

Logic here is tricky because you're dealing with the event versus the payload in the callback. I think what your looking for is something like this.

if event =  Events.PRINT_RESUMED or
        (event = Events.POSITION_UPDATE and payload.z > 0.3):

The idea here is that you're trying to replace the print started event with the position check using the payload.

Thank you. Yes replacing the started event will do the job. That was what I was looking for. I ll give it a shot and tell you if it works. I ll have to find how to clone a plugin etc but I ll manage to do it I suppose

Use the fork button on github on that plugin's repository.

1 Like