I was originally going to control power to my printer with an external relay, but realized it uses a MKS PWC, which basically is a relay. Does anyone connect a Pi GPIO pin to it for power on/off? Or disable it, and do it externally?
If I remember right, the plugin PSU control can do something like this. I recommend having a search on the plugin repository, this has definitely been done lots before.
I am looking for something like this .... The plugin I would need should simply show me an off button on the octoprint web ui so that when I press it the state of a gpio changes to turn off the MKS PWC module (which gives me the ability to shut down the entire system, including the ruspberry remotely). Along with this I would like to use the psu controll plugin to control another module with relay to turn the printer off and on only remotely. In this way when I am remotely I can decide whether to turn off all or only the printer so that I can also turn it back on remotely.
Yeah, pretty sure the PSU Control plugin does exactly that.
i don't think it allows to use two gpio to control 2 relays? or am I wrong?
unless there is a way to turn off the raspberry remotely, by doing so I can use the 5V of the raspberry to make the mks pwc module understand that it must turn off. in this way I remotely turn off the raspberry safely and with the normal procedure of turning off a computer (and not brutally by removing the power supply) and once the raspberry is turned off it will no longer have 5V on its pins and the MKS module PWC will shut down accordingly.
I figured out how to do exactly this. I'm not in front of Octoprint right now, but I ran system commands for on and off, and those system commands turns on a GPIO, waits 5 seconds, and turns off. After a lot of trial and error, and mistakes, it works perfectly. I thought I had a MKS 2.0, but it turned out I had a Koonovo 2.0, which has no onboard 5v regulator.
but from the web ui, when you press shutdown system is there any gpio that switches the state?
That's what I'm saying. In the PSU CONTROL Plugin, under SWITCHING METHOD, set SYSTEM COMMAND. Then, you run one command to start up, and another to shut down. To set GPIO pins with system command, I do this:
To turn ON my printer:
gpio -g mode 22 out ; gpio -g write 22 1 ; sleep 4 ; gpio -g write 22 0
To turn OFF my printer:
gpio -g mode 27 out ; gpio -g write 27 1 ; sleep 4 ; gpio -g write 27 0
If you just want to turn the same GPIO on and off, use GPIO PIN as switching method.
I don't know if there's another way to do it, but I know this works well.
I suppose it's odd you want to turn off the Raspberry pi as well, there's no remote turning on things. You could set a command to shut down the Pi, but when it's shut down, you won't be able to switch a GPIO. Does the Pi HAVE to shut down? Can you use a separate power supply? Then, you can shut down the printer with GPIO, then shut down the Pi with a system command.
Thanks for the info you're provided here. I have the same Koonovo PWC 2.0 and I'm trying to figure out the right way to connect everything.
Are you connecting gpio 22 to the NO pin on the left header and gpio 22 to the S pin on the right header?
Do you also need to connect the 5v pin to a 5v power pin on the Raspberry Pi?
I'm guessing the G and C pins can both go to Ground on the Pi, right?
I was hoping to use a single gpio pin to control the relay but I don't see an obvious way to do that. Am I right in assuming this relay doesn't really allow that?
My solution was an evolved mess. I first assumed a high in one place would turn the unit on, and a high in another location would shut down. I should have just used off-the-shelf relay modules, but I made my own circuit using a few transistors that supplies 5V at around 100mA, converting 3.3v to 5V.. Shutting down was relatively easy, but without an onboard 5V regulator, I thought of two choices to power it on. I could put a relay's NO output across the power button, which involves dealing with AC (Which I didn't want to do considering this was not very mechanically secure), or I could just power the PWC from the 5V 100mA, which is what I chose to do. I think it was also trying to power the Robin Nano board through the PWC, so I added some diodes, threw in some resistors and a transistor, and tweaked. It works great now, but I wouldn't recommend you follow my path exactly. Likely the best thing to do is replace the Koonovo PWC with a PWC that has an onboard 5V regulator. Then, you can put 5V in one location to power on, and 5V in another to shut down. Of course, I connected the printer's 5V PS to the Pi through a few resistors and 3.3v Zeners to detect when it's on. Also, on the circuit I built, I put LED's for turning ON, turning OFF and power detect. It made life MUCH easier, and I could even troubleshoot remotely by the camera.
Also, I personally would never connect Raspberry Pi pins directly to anything. For one, the Pi is 3.3v, and the PWC is 5V. I've heard rumors and legend that the Pi can handle 5V, but that's really not the right way to do things, especially if reliability is important to you. I originally tried using off-the-shelf level shifters, but they didn't work right and in hindsight were a dumb idea. I'd probably go with the relay modules. Some even have an optocoupler onboard, and they are cheap.If you really don't want to replace your PWC, you could use the relay, but you're switching 120V AC instead of 5V, so make sure your wiring is quality and insulated.
Also, if you want to use a single GPIO pin, you could short out the pushbutton, so it's always powered on, and then have the single GPIO pin power the AC input to the printer. A few issues: If there is a slight quick glitch, your printer could shut down, possibly in the middle of a print. Also, if you have to reboot the Pi, pins may go low, which would shut down your printer. You also would not be able to shut down by the LCD Touch screen. One advantage is that you wouldn't need to drill holes or run wires into the printer.I added a connector, and it looks like it was factory installed.