-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add gpio access and control #37
Comments
The more native way of accessing things would be to use the sysfs interface. It's possible that's how PSU Control and other plugins work (via whatever python packages they use), and we merely need to map in |
looks like at least PSU Control imports and uses RPI.GPIO to do what it does. |
Looks like no matter what we do, even adding udev rules to hosts and giving the user godlike permissions, the final result is that the specific library i'm using to test (PSU Control) uses RPI.GPIO module. Even with all permissions between host and container fixed, it will throw an error:
@OctoPrint/octoprint-maintainers something to consider here... It might be a best practice moving forward if plugins avoid the use of libraries that make an assumption about the OS they are run on. For example we could recommend to use https://github.com/vitiral/gpio Not sure what next steps to go for this one just yet, as there is still some of the documentation pieces that are good to cover. @OctoPrint/docker-maintainers any thoughts here?
I also saw an opportunity to improve some guidance in the wiki for your plugin. The troubleshooting question "can't access /dev/mem" links to a SO post has a technically correct answer, but only under a small number of conditions. The best fix for that problem is to create a udev rule for gpio devices assigning them the group and controls required to survive reboots. Let me know if that sounds ok to you and I'll drop the changes in gist that you can copy. |
@LongLiveCHIEF I turned it off as people were abusing it as support instead of a tracker. I was actually looking at replacing RPi.GPIO with generic GPIO support using python-periphery. Have even thought of creating a separate GPIO plugin with exposed helpers to be used by other plugins. I believe the biggest problem would be compatibility with other plugins that continue to use RPi.GPIO. |
PS: I'm generally in #octoprint on Freenode if you want to discuss it. 😄 |
Regarding the RPI detection and the error For the GPIO I'm not an expert but can't we just mount devices and volumes ? I don't think we need to do anything specific (except maybe document it). |
@gaetancollaud It's not the plugin that throws this error, it's the https://sourceforge.net/p/raspberry-gpio-python/code/ci/default/tree/source/py_gpio.c The changelog for that module has some notes about updating detection for aarch64, and also some open issues about this. |
so yeah... looks like it's not specific to docker, which is good to know. |
I'll give another scenario... Raspberry clones, specifically Intel-based ones. I have a large collection of UP Boards (Intel Atom, Celeron, and Pentium x64 powered). They are direct RPi formats, using the same 40-pin GPIO. I've done some development on RPi hats for these boards, and it basically comes down to:
I think root is because of the GPIO hacks to the x64 Linux kernel that requires root to access the GPIO bridge's DMA across these Intel-based boards. To sum up, just an FYI to not prevent things running as root as there are use cases that we may have to. I'm going to set this up soon, with the docker work I see in this repo. Most likely will be using Klipper's GPIO access instead of Octo though. |
yeah, doesn't surprise me. I already wrote some stuff that uses the new character device libraries instead of relying on wiringpi. Forgot where I put it though. @kantlivelong and I were tossing around some ideas using python-periphery (utilizes the native character device interface of recent kernels), but at the time octoprint was still python v2, and arm64 hadn't really become officially supported by Ubuntu yet, meaning wiringpi worked for most things, so it wasn't too much of a problem. Might be about time to take a closer look now though. |
The python 2 will be dropped in the next octopi release 0.18, whenever that is. The nightlies are already building python 3 only images. |
Hi all,
and this commands under PSU Control plugin:
|
@albertopc that is the deprecated interface we're talking about. |
@albertopc, what exactly needs to install PSU Control plugin? I get an error:
|
added |
I just got this working thanks for advise in this thread. @albertopc I see you are setting mode=input to turn off relay. I was struggling with the same issue and couldn't get it to work normally. Turns out it should be powered by 3.3v not 5v. After changing vcc to 3.3v it triggers normally - even though product spec says it should have 5v power. Setting direction=input with 5v powered board could damage your Pi according to comments at https://raspberrypi.stackexchange.com/questions/59668/5v-relay-will-not-close-unless-using-gpio-cleanup With this issue resolved I got the following system commands working:
Also running See https://www.kernel.org/doc/Documentation/gpio/sysfs.txt for gpio sysfs documentation. |
@morganchristiansson This kernel interface (sysfs) is deprecated, and tools that support it RPi.GPIO for example, have also dropped support or discontinued development. The new interface for gpio manipulation is the chardev interface. |
Oh yeah it says in gpio/sysfs.txt
It does seem to say it will be maintained and included in future kernels but no new features.... But yeah. Deprecated. There's a bunch of shell tools: raspi-gpio gpio gpioset etc that do the same thing. I wasn't sure they're in the docker image so it was nice to use just echo and grep. Hopefully PSU control plugin can just support running inside docker in future version. Btw the auto-power on/off by relay is like magic. So satisfying when it turns off 10 minutes after print. And turns on when you click print button in your slicer. |
I know the PSU Control plugin has a version that kantlivelong has been working on that utilizes periphery instead of RPi.GPIO which may open it up to better docker compatibility. |
For what it's worth, I've completely decoupled power features in octoprint from the printer and the octoprint host, and instead use home assistant with an esp01 to control a relay. OctoPrint can send a mqtt message when print is finished, and that auto-switches the printer to off. This also means I can control shutdown in case of crash of octoprint as well. |
I also considered this. I've seen you can integrate octoprint with homeassistant. And I have a couple Sonoff S20 plugs which have esp8266 inside and you can flash your own mqtt firmware on them. But I'm quite enjoying my integrated 3d printing tower with 2x Ender 3 pro connected to single Pi4 with 2x octoprint docker containers. I hotglued the relays inside the original PSU and turn the printers off by sending the 3.3v signal. Here's my build log https://imgur.com/a/y5Rth03 I'm going to attach ws2811b LED strip to my SKR Mini E3 2.0 boards next and get better lighting for the 2x connected cameras. |
Nice. Here's mine. The photos at the bottom are the most recent. https://photos.app.goo.gl/ZiyXs526jnhR8kLz6 |
Fyi, with the new version of PSU-Control I found that it's enough to mount /dev/gpiochip0 nothing else necessary for me. |
I saw PSU Control 1.0 was released with python periphery which should fix this. Thanks for testing it! https://github.com/kantlivelong/OctoPrint-PSUControl/releases |
On a test of the OctoPrint PSU control plugin via docker, I believe it is necessary to enable and document a few things related to using GPIO for our users.
The following 2 docker container settings are required for gpio dependent plugins to work:
cap-add SYS_RAWIO
--device /dev/mem
Additionally, the gpio device tree needs to be made writeable, and any pins that are controlled by octoprint plugins need to have corresponding INPUT/OUTPUT modes set, and the pin number registered in the /sys/class/gpio device tree.
This can be done manually with the
gpio
ubuntu package available from thewiringpi
package in the default ubuntu registry.I'm not sure if these plugins use this program, as I can't remember if I had to set things up manually the first time I installed PSU Control on a normal Octopi Raspbian image.
Tasks:
Documentation:
cap_add
and--device /dev/mem
The text was updated successfully, but these errors were encountered: