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

Set initial state of pin #38

Closed
wants to merge 3 commits into from
Closed

Set initial state of pin #38

wants to merge 3 commits into from

Conversation

agreen
Copy link
Contributor

@agreen agreen commented Jun 16, 2017

Set Initial state of pin to off. Previously, when you would invert the PSU pin, the PSU would be on at startup.

agreen added 2 commits June 15, 2017 21:08
Set initial state of relay to off. Accounts for pin inverted state.
Set initial state of relay to off.
@kantlivelong
Copy link
Owner

kantlivelong commented Jun 16, 2017

Makes sense to me. Will merge it into devel when I get a chance to test it out.

Thanks

PS: Next time make a branch and submit the PR to devel. 😄

@agreen
Copy link
Contributor Author

agreen commented Jun 16, 2017

Gotcha, will do. :)

This reverts commit e91e5f2.
@kantlivelong
Copy link
Owner

kantlivelong commented Jun 28, 2017

Hey there! I've finally had a chance to take a look at this.

So far I've set up an inverted circuit without adding the changes from this PR and I've ticked the invert option on. The PSU does indeed default to being on when [re]booting the Pi due to the default state of the GPIO pins being set to low. Is this PR supposed to simply turn the PSU off when OctoPrint starts after the Pi [re]boots or are you expecting it to work during [re]boots as well?

PS:
It is possible to set the default state of GPIO pins and I think it would be good to present the option to people but I don't think it's something I'd peruse doing in the plugin. See https://www.raspberrypi.org/documentation/configuration/pin-configuration.md

@agreen
Copy link
Contributor Author

agreen commented Jun 28, 2017

The pins are high impedance on powerup. They should be set as neither high nor low (with a caveat listed here https://www.raspberrypi.org/forums/viewtopic.php?t=7443&p=93865) - On my raspberry pi B v1 this is how they function, however I don't see the transient spike mentioned in that post...

When I boot, or reboot my system, nothing happens to the PSU. As soon as octoprint (and this plugin) starts, due to setting the GPIO default state, the PSU turns on. My attempt is to have the default state continue to be whatever the "off state" of the PSU is, as in either case, the PSU SHOULD be off until the GPIO is configured.

In your test circuit, did you add a pullup/pulldown resistor to the pin? That could influence your results. I'm using a relay like this one http://www.ebay.com/itm/Blue-5V-2-Channel-Relay-Module-With-optocoupler-For-Arduino-PIC-AVR-DSP-ARM-HYSG-/311560796461?epid=1376439117&hash=item488a78792d:g:p8EAAOSwAuNW22hK This uses an optocoupler to tie it to the relay, which is also why the output is inverted.

If you combine this with the Auto PSU on/off options, you wind up with the PSU ONLY coming on when it actually needs to.

@kantlivelong
Copy link
Owner

Ah ha! I was using two NPN transistors and due to this the state would be HIGH when powered off. Luckily I had a similar relay PCB and I now see where this PR comes into play. I've tested it and it looks good.

I noticed a commit made after the PR was submitted changed the version and then later the fork/branch was deleted entirely. Would you be able to branch from the latest devel, recommit the change, and update the PR with the appropriate fork/branch against devel? If you have an issue changing the fork/branch in this PR you can just open a new one and reference this one. I only ask because I think you wouldn't get credit in the commit log if i merged a PR from deleted fork/branch.

Thanks 👍

@agreen
Copy link
Contributor Author

agreen commented Jun 28, 2017

Sure. I'll manage that. :) Also, I'm working on a sister update for the issue #36 I opened. I fixed that too. Should have a PR for it coming your way for that also. (seperate PR's).

@AfromD
Copy link

AfromD commented Jan 23, 2020

I would like to propose a change.

In my setup, the PSU of the printer powers a raspi via a buck converter. The raspi then controls a relay that powers the rest of the printer. So the way it is setup right now, I need to operate the physical power switch, wait for the octopi web interface, and then switch the rest of the printer on. Cumbersome.

I do not always want to control the printer via Octopi. I also want to be able to have local control over the printer when I switch it on. So I would like to either use it as a locally operated printer, or when I don't use it for 15 minutes then PSUControl takes over and saves power until I either reboot the pi by means of the power switch or start operating the printer via octopi. That way, I can either have it on standby for longer periods, or quickly fire it up for a local print job or maintenance.

The proposed change is to add a preferred initial state configuration. For now I have hardcoded it as follows, but that is just a hack:

                GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=GPIO.HIGH)
                self._configuredGPIOPins.append(self.onoffGPIOPin)
                self._stop_idle_timer()

proper implementation would like something like this

                if self.poweruponBoot:   #Invert initial state in case the PSU should be switched on on boot
                    initial_pin_output=not(initial_pin_output) 
                    self._stop_idle_timer()

                GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=initial_pin_output)
                self._configuredGPIOPins.append(self.onoffGPIOPin)

Plus a checkbox in the config dialog

Note that I had to destroy the idle timer, because in my case it was switching off the PSU right away after boot again.

forgive me for not coding a complete pull, I do not feel confident that I'm not screwing up more than I'm fixing...

@agreen
Copy link
Contributor Author

agreen commented Jan 23, 2020 via email

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

Successfully merging this pull request may close these issues.

3 participants