Describe the bug
I'm using an RPi4 with an Octopi/Octoprint instance on it for 3D printer. In Octoprint software, i'm using
OctoPrint-PSUControl plugin to control a 3v3 relay on GPIO21 and through it power on and down 3D printer with Raspberry. And without the physical power button, this working as it must.
I successfully installed the power-button on GPIO3 from this repo and powering on and shutdown of raspberry is working well through the momentary button.
BUT. Then I touch the screen to power on the printer through PSUControl. The relay closes and the printer power on and at the same time raspberry seems to "receive" also the command to power off like if I push the new power button but I didn't touch it !
This behavior does happen too then I power on and off printer though PSUControl button on Octoprint webinterface.
There must be a kind of interference of signal between Pi Power Button and OctoPrint-PSUControl then I'm trying to power on printer by touching the OctoDash screen. But I don't know where to start in investigations...
Any help will be very kind !
Steps to reproduce the behavior:
- Install Pi Power Button Repo and a momentary button on GPIO3 and GND.
- Power On RPi and wait to octoprint startup.
- Activate function "Turn On Printer When Exiting Sleep" [by touching the screen] in OctoDash settings.
- Touch the screen.
Printer must power on through the relay AND raspberry stay ON.
- Hardware : Raspberry Pi 4 2Go, a 3v relay connected to GPIO21, a momentary button connected to GPIO3(SCL) and GND, a 5" capacitive HDMI screen (MPI5001) 800x480 USB touch interface
- OS Info : OctoPi 0.18.0
- OctoDash Version : 2.2.0
- OctoPrint Version : 1.7.2
- Python version : 3.7.3
I'd suspect that whatever that Pi Power Button tool is doing is triggering the state change of PSU somehow in a negative way. @kantlivelong may potentially have an idea of a setting possibly that might prevent the trigger.
Looks like a snake biting its tail here...
I am desperate...
I'm guessing the problem is EMI related. Try twisting the two wires that go to the button or use a bit of shielded twisted pair cable connecting the shield to another ground pin on the RPi. You will probably have to find a local electrical supply store that is willing to cut a "sample" off for you.
Try putting a capacitor between the switch pins. Smallest value electrolytic cap you have laying around. But do it at the pins, not at the switch (negative side of cap to GND).
Thanks b-margan for this option. I twisted two cables of the button then covered them with a layer of copper tape and then a layer of an isolant tape. Just tried, unfortunately same issue.
Thanks oerkel47 for your reply. What cap value do you suggest ?
Do you have any already?
I suggest 0,1 uF up to 1uF (which is usually the lowest you can get).
It seems you was right oerkel47. I put a 1nF cap between Pins (GPIO3/GND) on RPi side. Issue seems to be gone. No more unwanted off switching of RPI yet.
Will test a few days more to be sure then if it is still ok, I will close this topic.
Thank you very much for your help !
PS : just for my understanding, putting this cap is for the stability of the signal ? What is his purpose exactly by electronic view ?
Nice, glad to help. It must have been a problem of electrical interference. A GPIO configured as an input is very sensitive and doesn't disturb signals on the line (
low high impedence). Unshielded wires can easily pick up electrical fields from the surrounding (in this case probably from your relay) and the input receives this as a short high or low signal. A capacitor is a form of high pass filter which lets high frequency signals go to GND so that it doesn't reach the input.
I had a similiar setup with a button once with ~1m of unshielded cables. When the gas heating spark turned on, it turned on my printer. So I did the same.