Red-M / Octoprint-Filament-Sensor-ng

GNU General Public License v3.0
11 stars 5 forks source link

Which pins can I use? #2

Closed kwoot closed 4 years ago

kwoot commented 4 years ago

Hi, Probably a stupid question but since this is my first attempt to do basic electronics with a Pi I seem to have to ask. What pins can I use? I choose (randomly) pin 25 and shorted it to ground. The printer works, but removing the connection has no influence.

In the logfile I see:

2020-03-21 11:17:03,248 - octoprint.plugin - ERROR - Error while calling plugin filamentsensorng Traceback (most recent call last): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/init.py", line 224, in call_plugin result = getattr(plugin, method)(*args, **kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filamentsensorng/init.py", line 105, in on_event if event is Events.PRINT_STARTED and self.no_filament(): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filamentsensorng/init.py", line 97, in no_filament return GPIO.input(self.pin) != self.switch ValueError: The channel sent is invalid on a Raspberry Pi

What am I missing here?

Red-M commented 4 years ago

No question is stupid as long as you learn from it :)

Pin 25 on a raspberry pi's GPIO is a ground. If I remember correctly, I used the BCM 17 pin AKA pin 11 because it was right next to a ground pin. I think any of the "green" pins on this diagram shorted to ground should work. as long as they don't have an extra function such as being an I2C or UART port (no brakcets next to the pin number/name). Screen-Shot-2017-10-30-at-5 00 06-PM 1

kwoot commented 4 years ago

Thanks. Sorry to bother you again. I changes it to pin 17. And it still has no effect. Changed Board Pin Mode to BCM mode. No effect. I have no clue why this does not work.

The logging says: 2020-03-22 09:35:07,936 - octoprint.plugin - ERROR - Error while calling plugin filamentsensorng Traceback (most recent call last): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/init.py", line 224, in call_plugin result = getattr(plugin, method)(*args, *kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filamentsensorng/init.py", line 129, in on_event GPIO.remove_event_detect(self.pin) ValueError: The channel sent is invalid on a Raspberry Pi 2020-03-22 09:35:07,989 - octoprint.plugins.filamentsensorng - INFO - PrintFailed: Disabling filament sensor. 2020-03-22 09:35:07,990 - octoprint.plugin - ERROR - Error while calling plugin filamentsensorng Traceback (most recent call last): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/init.py", line 224, in call_plugin result = getattr(plugin, method)(args, **kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filamentsensorng/init.py", line 129, in on_event GPIO.remove_event_detect(self.pin) ValueError: The channel sent is invalid on a Raspberry Pi

kwoot commented 4 years ago

So. Setting the pin to 17 and doing a reboot seemed to fix it somehow. Not that it worked, mind you. Using Octoprint 1.4 as soon as the contact is broken/open Octoprint receices only one event. I tried several forks of this code. Some of those even result in a broken setup where you can't print anymore. Every started job is immediately cancelled. But after setting the number of needed events to 1 makes this pluygin workable. So, thanks for this code.

Red-M commented 4 years ago

If you're getting an instant cancelled print after starting that means you need to change the open/close to the other option as it is currently set, the option is shown below. image

Changing the pin and rebooting allowed the config change to go through to octoprint as it was most likely stuck in a loop after the pin was set to a ground pin.

I'd highly not recommend setting the number of events to 1 as even plain switches can have erroneous triggers most likely due to the way that the RPi's GPIO works.

As an example, my settings are below. image