🇺🇦 We stand with Ukraine! 🇺🇦

PSU Control with OPI H6

Hello,
my problem with this Plugin is, that I can not get it to work with my relay which is switching with GPIO pin 117. I tired it in PSU Controll ( Switching -> System Command) with system functions like e.g. gpio write 117 1 or echo 1 > gpio117/value (to switch the relay on) but did not work.

By doing it in Armbian with following commands it works with no problems:

root@orangepioneplus:~# cd /sys/class/gpio
root@orangepioneplus:/sys/class/gpio# ls
export gpiochip0 gpiochip352 unexport
root@orangepioneplus:/sys/class/gpio# echo 117 > export
root@orangepioneplus:/sys/class/gpio# ls gpio117
active_low device direction power subsystem uevent value
root@orangepioneplus:/sys/class/gpio# echo out > gpio117/direction
root@orangepioneplus:/sys/class/gpio# cat gpio117/direction
out
root@orangepioneplus:/sys/class/gpio# echo 1 > gpio117/value
root@orangepioneplus:/sys/class/gpio# echo 0 > gpio117/value

I hope someone can help me to get this to work in PSU Control.

are you sure it's gpio 117 and not gpio 17?

Are you able to do this as a non-root user or ideally the user running OctoPrint? There's likely a permission issue. Also why are you not using the built in GPIO support?

@PrintedWeezl Yes it´s GPIO 117 (Orange PI one plus)

@kantlivelong You are right it is only working in root. In user mode I have no permissions. Till now I tried it with this settings (see attached pictures)

Take a look at Notes to installing Octoprint on Armbain

Thank you @kantlivelong. I tried to get it to work with the notes of your link. Now I have a gpio group and added my root and my username to it. I also have permissions but still there is no GPIO Device at the PSU-Control available :frowning:
weix@orangepioneplus:~$ ls -l /dev/gpiochip*
crw-rw---- 1 root gpio 254, 0 Apr 26 15:00 /dev/gpiochip0
crw-rw---- 1 root gpio 254, 1 Apr 26 15:00 /dev/gpiochip1

After installing libgpiod.git/ I also tried some code of the Sunxi page -> GPIO - linux-sunxi.org
GPIO pin 117 is working when calling in root and also in usermode (after password input):

sudo gpioset gpiochip1 117=1 //switching on
sudo gpioset gpiochip1 117=0 //switching off

but lines like these do not work?!:

root@orangepioneplus:~/octoprint# sudo gpioset gpiochip0 117=1
gpioset: error setting the GPIO line values: Invalid argument

root@orangepioneplus:~/octoprint# modprobe gpio-sunxi
modprobe: FATAL: Module gpio-sunxi not found in directory /lib/modules/5.15.25-sunxi64

Do I need this to set the rules which are described at the notes from your link above?

# /etc/udev/rules.d/96-gpio.rules
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
    chown -R root:gpio /sys/class/gpio && chmod -R 0770 /sys/class/gpio &&\
    chown -R root:gpio /sys/devices/platform/sunxi-pinctrl/gpio && chmod -R 0770 /sys/devices/platform/sunxi-pinctrl/gpio'"

And here my octoprint log which is maybe also important:

2022-04-27 09:32:35,991 - octoprint.plugins.psucontrol - INFO - Periphery version: (2, 3, 0)
2022-04-27 09:32:35,992 - octoprint.plugins.psucontrol - INFO - Using GPIO for On/Off
2022-04-27 09:32:35,992 - octoprint.plugins.psucontrol - INFO - Configuring GPIO for pin 117
2022-04-27 09:32:35,992 - octoprint.plugins.psucontrol - ERROR - Exception while setting up GPIO pin 117
Traceback (most recent call last):
  File "/octoprint/plugins/lib/python3.8/site-packages/octoprint_psucontrol/__init__.py", line 190, in configure_gpio
    pin = periphery.GPIO(self.config['GPIODevice'], self.config['onoffGPIOPin'], initial_output)
  File "/octoprint/plugins/lib/python3.8/site-packages/periphery/gpio.py", line 496, in __init__
    self._open(path, line, direction, edge, bias, drive, inverted, label)
  File "/octoprint/plugins/lib/python3.8/site-packages/periphery/gpio.py", line 503, in _open
    raise TypeError("Invalid path type, should be string.")
TypeError: Invalid path type, should be string.

Thanks in advance!

For the sake of testing does the plugin work in a separate venv running as root?

The post I linked likely won't apply to your environment exactly the same as it's different hardware.

This was also very recently published to the plugins repo. Might be worth trying as well.

Installed Octoprint in a "new way" and now I see my GPIO-Device at the PSU-Control plugin :slight_smile:
With your link I got the whole thing to work - Thanks again!