volumio / volumio-plugins-sources-bookworm

2 stars 4 forks source link

GPIO library #2

Open supercrab opened 1 month ago

supercrab commented 1 month ago

What's the best gpio library to use?

My gpio_control plugin uses onoff but that doesn't work on Pi5. I did try to use gpiox library. That works with the Pi5 but not with the Pi Zero :(

https://github.com/iiot2k/gpiox/issues/2

ashthespy commented 1 month ago

From https://github.com/volumio/volumio-plugins-sources/issues/360#issuecomment-2420673297 Try node-libgpiod they says it's tested on the Zero :-)

supercrab commented 1 month ago

Nice one @ashthespy 😎😊

gvolt commented 1 month ago

Another alternative could be @bratbit/onoff as the readme states:

"@bratbit/onoff is a GPIO control and interrupt detection package for nodejs intended for use with Raspberry Pi.

The package strives to offer an API compatible to that of fivdi/onoff, while using native bindings."

However, I haven't tested it yet.

iiot2k commented 3 weeks ago

Hello @supercrab, I have installed Volumio on GPIO Control on Rpi Zero W. Unfortunately, I don't know anything about Volumio. I also installed your plugin (1.0.5). Is gpiox built into this version ? Need some support from you. Send with your e-mail address. You can find my e-mail address on my GitHub page.

supercrab commented 3 weeks ago

Hi @iiot2k

You have to install the beta version of the plugin in volumio. Volumio will automatically install gpiox when the plugin is installed.

To do this is very simple:

This will then install the beta version of the plugin that uses gpiox

Cheers

Darmur commented 3 weeks ago

the latest beta version does not have gpiox

the only version with gpiox is 1.0.7

please make sure to uninstall the plugin, reboot and then install the version 1.0.7

iiot2k commented 3 weeks ago

Hi @Darmur

I installed V1.0.7 (beta) und it works on Rpi Zero W.

For that I use "System Startup Event" and toggle "GPIO State" on pin 21, 20, 16.

Tip: Not all pins works on Rpi.

Don't use pin 0 and 1.

This pins are not enabled on gpiox.

This pins are reserved for i2c comm for hats.

Some other pins have special functions (i2c, spi..).

Derya

Darmur commented 3 weeks ago

I don't know how it's possible, but I can confirm that GPIO Control 1.0.7 (based on gpiox) works fine on Raspberry Pi Zero W and Raspberry Pi Zero 2W

maybe when the plugin was released on the first place, it was using an old version of the library, or maybe something is changed on Volumio in the time-being that made it working...

iiot2k commented 3 weeks ago

I'm very happy about that. Like libgpiod, I also use the official Linux API (V2) for control of GPIO. I would have been surprised if it hadn't worked. Maybe you got the wrong pin for test.

supercrab commented 3 weeks ago

I'm looking at the plugin and it appears after my last version. I did version 1.0.7. I'm looking at v1.0.9 and it has some extra code in it that I didn't write:

GPIOControl.prototype.getKernelAgnosticPinNumber = function(gpioPin){
    const self = this;

    var kVer = os.release();
    var gpioNumber = parseInt(kVer.split('.')[0]) >= 6 ? parseInt(gpioPin)  + parseInt(gpioPrefix) : parseInt(gpioPin);
    return gpioNumber.toString();
}

@Darmur is there a way to tell who has made changes to the plugin? I don't know who made the changes or why or if they've been tested properly 🤔

ashthespy commented 3 weeks ago

I'm looking at the plugin and it appears after my last version. I did version 1.0.7. I'm looking at v1.0.9 and it has some extra code in it that I didn't write:

GPIOControl.prototype.getKernelAgnosticPinNumber = function(gpioPin){
  const self = this;

  var kVer = os.release();
  var gpioNumber = parseInt(kVer.split('.')[0]) >= 6 ? parseInt(gpioPin)  + parseInt(gpioPrefix) : parseInt(gpioPin);
  return gpioNumber.toString();
}

@Darmur is there a way to tell who has made changes to the plugin? I don't know who made the changes or why or if they've been tested properly 🤔

This looks like the fix for new 6.6.y kernels from https://github.com/volumio/volumio-plugins-sources/commit/0a3131816e9fa78914fc78f53c0046a53413c6d2

It shouldn't be applicable for older kernels?

Darmur commented 3 weeks ago

with the fix for the new kernel 6.6, GPIO control works if GPIO Button plugin is not enabled, and vice versa. with 1.0.7 I can have them working together

iiot2k commented 3 weeks ago

Hi, I took a look at the source files. It is very logically structured. But where can you find source of the beta versions? The gpio driver in gpiox is written in c++. The gpiox manual is here: https://github.com/iiot2k/gpiox/blob/main/API.md

Here are some tips: After calling init_gpio(), check the return value and write it to the log. If, for example, a pin already has a special function, the return value is false. You can also make an output blink with blink_gpio(pin, period). The change in a GPIO input is detected with watch_gpio(pin, mode, debounce, edge, callback). The "callback" function is called. Maybe it will help you.

Darmur commented 3 weeks ago

I think the beta code for beta 1.0.7 is in this fork https://github.com/volumio/volumio-plugins-sources/compare/master...supercrab:volumio-plugins-sources:master