Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normally closed switch #10

Open
cbusillo opened this issue Sep 2, 2016 · 18 comments
Open

normally closed switch #10

cbusillo opened this issue Sep 2, 2016 · 18 comments

Comments

@cbusillo
Copy link

cbusillo commented Sep 2, 2016

My switch is a normally closed switch. When polling the API it shows 0 when the filament is loaded and 1 when it is not loaded. Is there a variable I can set for a normally closed switch?

@MoonshineSG
Copy link
Owner

MoonshineSG commented Sep 2, 2016

At the moment there isn't a way to invert the behaviour. Let me think over the weekend and I'll get something done.

If you need smth fast, you can change the code so that the api returns reverse values and instead of FALLING it should check for RISING and the safety check should be positive not negative (if state)

@cbusillo
Copy link
Author

cbusillo commented Sep 2, 2016

Thanks for the quick response! I will keep an eye out for your next release! Maybe a variable that says up or down? If I were to simply changed the installed code do I have to recompile? I haven't used Python in a long time.

@MoonshineSG
Copy link
Owner

no, you don't need to recompile but you need to restart octoprint so it's loads the changed code

@cbusillo
Copy link
Author

cbusillo commented Sep 3, 2016

I am able to get the correct status returned from the API by swapping the status var. Do you have a good suggestion for code to pause the printer?

@MoonshineSG
Copy link
Owner

please try the new codes that allow both type of switches. set filament to reflect your system

(codes not yet as a release, so you need to deploy manually)

@cbusillo
Copy link
Author

Super awesome. It works!!! My printer is pausing randomly though. Does the script set a software type pull up or do I need to put a capacitor into the wiring harness?

The light on my sensor stays on the whole time there is filament inside it. The print will pause every once in a while and I have to hit resume on the octo print interface. I have the sensor plugged directly into the PI 3.3v, ground, and GPIO pin 2. From reading it seems like the PI has a built in pull up or pull down resistor that can be selected with software, but I kinda got lost after reading that.

@MoonshineSG
Copy link
Owner

Thats not good.... It means the switch gets false reads.... You can try to increase the bounce value and see if it helps....

If you're using one of those endstop switches you dont need software pull (up/down). Since you mentioned there is an LED indicator on your switch, I guess you use one of theses :

endstop

I'll check the codes again. QUite difficult for me to test, as I am not actually using this plugin :D. I wrote it just as an example. And it stuck.

@cbusillo
Copy link
Author

I increased the bounce to 800 with the same results. I have the switch pictured. I might just buy the sensor you designed it for. I think you even posted a housing!

Again thanks for all the hard work, especially on something you don't use yourself.

@MoonshineSG
Copy link
Owner

The housing is not by me, but thats how the plugin became a little popular...

You might try to move to a different RPi pin, maybe a generic one (without a secondary function)

@MoonshineSG
Copy link
Owner

@cbusillo I added a tiny delay in the reading to try avoiding fake reads... Try the latest code and let me know... Please check if it really pauses when filament runs out.

@cbusillo
Copy link
Author

After updating the print does not pause at all. It does correctly show if the filament is loaded or not.

@MoonshineSG
Copy link
Owner

can you paste your plugin settings and the relevant logs ?

@cirobertson
Copy link

cirobertson commented Dec 28, 2016

Hi, thanks for making and sharing this plugin.

Did you test the input signals with an oscilloscope yet? I recently made my own sensor (http://www.filamentroller.com) which *had* a 600 microsecond blip on power-on which was falsely triggering pause. I assume "bounce" was a millisecond debounce value but trying values 4 to 4000 had no effect. Am I making the wrong assumption here?

In any case, I added time.sleep(0.100) to the first line of check_status (100 ms manual software debounce) and the problem was solved.

I later modified my circuit so that my sensor no longer needs the software debounce (no more blips, very clean signal); however, I think this may be the answer to your issue here.

@BETLOG
Copy link

BETLOG commented Mar 22, 2018

I'm confused.
Have you added an NO/NC option yet? Surely that's fairly trivial to do.
I have the same kind of sensor as you posted in the image above.
It's connector is wired green, null, black, red ( pins from closest to microswitch to furthest away from it).
And yet I get 0 when filament is in it, and the red led is active.... and 1 when i remove the filament and the led is not on.
...what?

I tried moving the green signal wire from:
green, null, black, red
to:
null, green, black, red
.. I was sure that would flip NO/NC, and yet it didnt work at all. As if the switch doesnt even connect it's NC circuit or something. Would I need to reinitialise octoprint or the Pi? for it to recognise that?... Surely not.

@MoonshineSG
Copy link
Owner

should work... just do a manual deployment

@BETLOG
Copy link

BETLOG commented Mar 22, 2018

Should work, and yet....
I've also been trying to add the simple inversion flag, but python isn't something i'm familiar with, so i'm getting frustrated by something being syntactically broken and not knowing how to debug.
Is it obvious to you where i'm breaking this?

nano /home/pi/.octoprint/config.yaml

plugins:
  filament:
    pin: 16
    bounce: 400
    invert: 1

nano /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filament/__init__.py

        def on_after_startup(self):
                self.PIN_FILAMENT = self._settings.get(["pin"])
                self.BOUNCE = self._settings.get_int(["bounce"])
                self.INVERT = self._settings.get_int(["invert"])

                if self.PIN_FILAMENT != -1:
                        self._logger.info("Filament Sensor Plugin setup on GPIO [%s]..."%self.PIN_FILAMENT)
                        GPIO.setup(self.PIN_FILAMENT, GPIO.IN)

        def get_settings_defaults(self):
                return dict(
                        pin = -1,
                        bounce = 400,
                        invert = 0
                )

        @octoprint.plugin.BlueprintPlugin.route("/status", methods=["GET"])
        def check_status(self):
                status = "-1"
                if self.PIN_FILAMENT != -1:
                        if self.PIN_INVERT != 1:
                                status = "1" if GPIO.input(self.PIN_FILAMENT) else "0"
                        else:
                                status = "0" if GPIO.input(self.PIN_FILAMENT) else "1"
                                self._logger.info("Filament Sensor Plugin [%s] RETURNING INVERTED VALUE..."%self._identifier)
                return jsonify( status = status )

@BETLOG
Copy link

BETLOG commented Mar 22, 2018

Oh... sorry. I didn't realise this plugin was as inactive as it is...and I can see the reason.
My bad :)
It might be useful to preface the intro with an 'out of development' note to keep people like me from blundering in here expecting stuff.

Also, thanks for indirectly forcing me to look at yet another bit of python, it's one of those things I keep meaning to learn properly. :)

@MoonshineSG
Copy link
Owner

most firmware now support filament sensors, so this is kinda obsolete... but it's woking, if one wants to have it working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants