pimoroni / mopidy-raspberry-gpio

Mopidy GPIO Control Plugin for the Raspberry Pi (Using RPi.GPIO)
Apache License 2.0
21 stars 25 forks source link

RuntimeError: Failed to add edge detection #9

Open githubtobi opened 4 years ago

githubtobi commented 4 years ago

I tried to install the plugin on my Raspberry 1 Model B+.

Mopidy is running fine with serveral exenstions.

I got the following error:

RROR 2020-07-16 22:39:36,062 [1441:MainThread] mopidy.commands Got un-handled exception from RaspberryGPIOFrontend Traceback (most recent call last): File "/usr/lib/python3/dist-packages/mopidy/commands.py", line 241, in _actor_error_handling yield File "/usr/lib/python3/dist-packages/mopidy/commands.py", line 438, in start_frontends frontend_class.start(config=config, core=core) File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 91, in start obj = cls(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/mopidy_raspberry_gpio/frontend.py", line 42, in __init__ bouncetime=settings.bouncetime, RuntimeError: Failed to add edge detection

I tried it with a Raspi 3 and it works.

Maybe, the edge detection is working in another way on the Raspi 1? Do you have more information or a hint how I can get it to work on the Raspi 1?

Gadgetoid commented 4 years ago

Wow... an original B+! Feels like those came out forever ago now. I haven't tested anything on one in quite some time!

Could you post the config section for Mopidy-Raspberry-GPIO detailing which pins you're using? It will probably be easier to write a minimal test script to reproduce this that just uses RPi.GPIO than deal with the whole Mopidy stack.

willemk commented 4 years ago

I happened to run into the exact same issue today with my RP1 board. In my case I was using pin 4, and it was throwing the same error. It turns out that some of the default gpio config uses ports that are used by something else on the Pi. I blanked out the default config after adding my own GPIO pin, which did the trick. My config now looks like the following:

[raspberry-gpio]
enabled = true
bcm4 = play_pause,active_low,250
bcm5 =
bcm6 =
bcm16 =
bcm20 =

Sidenote for @Gadgetoid , in order for me to get the plugin to run, I had to do the following steps manually after running the pip command:

Gadgetoid commented 4 years ago

@willemk that's a good spot regarding the pins that are already used. My guess is that the offending use is - and I'm rummaging in the depths of my memory here - dtoverlay=w1-gpio. BCM4 was/is the default 1-wire pin, and IIRC 1-wire always used to be activated by default for some reason. The default pin config is for our Pirate Audio products: https://shop.pimoroni.com/collections/pirate-audio

I wonder if I can trap this and produce some more useful error.

I tend not to include RPi.GPIO in install_requires since - as far as I'm aware - it's part of the default Raspbian/Raspberry Pi OS packages list, and the pypi version might trample the apt version (oh sheesh I hate this package management mess we're in) but maybe I should add it. While I built this library to support our products, I'm eager for it to be widely usable across a range of distros/use cases so my usual modus operandi might be redundant here.

So, TODO:

githubtobi commented 4 years ago

Hi @Gadgetoid,

yes the original B+ :-). Found the in a box and thought it might be cool creating a web-music-box. The install took a while but so far it's working great.

I investigated a bit more and could find the issue thanks to @willemk .

This config is not working and displaying the "failed to add edge detection":

[raspberry-gpio]
enabled = true
bcm23 = play_pause,active_low,250
bcm22 = next,active_low,250
bcm17 = volume_up,active_low,250
bcm27 = volume_down,active_low,250

This config works:

[raspberry-gpio]
enabled = true
bcm23 = play_pause,active_low,250
bcm22 = next,active_low,250
bcm17 = volume_up,active_low,250
bcm27 = volume_down,active_low,250
bcm5 =
bcm6 =
bcm16 =
bcm20 =
Gadgetoid commented 4 years ago

Definitely a combo of Mopidy using the default configuration for any pin not explicitly defined in the config file and the somewhat weird set up I have for pin configuration.

That's... a bit of a nuisance. I can certainly update the documentation to point this out, but it feels wrong to have to explicitly unbind keys.

I think the only correct solution is to blank out all of the default configuration, removing any inclination this library has toward our Pirate Audio range, since our Pirate Audio installer explicitly sets up the configuration anyway. This would also guard against any unexpected pin changes and ensure nothing like #5 happens.

gamecat69 commented 3 years ago

Thanks for the help on this thread. I just noticed this error on a RPi 2B and fixed it by running sudo usermod -a -G gpio mopidy as mentioned in the post above.

jonathanmassehsj commented 2 years ago

On raspberry 4 ubuntu 22.04 I fixed it by adding : usermod -a -G gpio ggc_user usermod -a -G dialout ggc_user

quozl commented 7 months ago

Issue has happened a few times for me, but it is rare and random, as if there is a race condition with something else on my system. A way to find the conflicting pin is to edit frontend.py to report it;

                try:
                    GPIO.add_event_detect(
                        pin,
                        edge,
                        callback=self.gpio_event,
                        bouncetime=settings.bouncetime,
                    )
                except RuntimeError:
                    logger.error(f"add_event_detect fail: {key}")

Goes here; https://github.com/pimoroni/mopidy-raspberry-gpio/blob/fe06125046f2d138c74a2a9686b649600be93928/mopidy_raspberry_gpio/frontend.py#L52

davidbenucci commented 4 months ago

I'm try to install Pirta eaudio with Mopidy. I followed this guide https://github.com/pimoroni/pirate-audio/tree/d9d7cadf1686860dcbfe42b74d34454942cba2d4/mopidy (I had to use --break-system-packages on pip commands). Everything went well but when I try to start mopidy service I got this error and none of the buttons work. Apr 25 15:32:50 pirate-audio mopidy[976]: File "/usr/lib/python3/dist-packages/mopidy/commands.py", line 445, in start_frontends Apr 25 15:32:50 pirate-audio mopidy[976]: frontend_class.start(config=config, core=core) Apr 25 15:32:50 pirate-audio mopidy[976]: File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 86, in start Apr 25 15:32:50 pirate-audio mopidy[976]: obj = cls(*args, **kwargs) Apr 25 15:32:50 pirate-audio mopidy[976]: ^^^^^^^^^^^^^^^^^^^^ Apr 25 15:32:50 pirate-audio mopidy[976]: File "/usr/local/lib/python3.11/dist-packages/mopidy_raspberry_gpio/frontend.py", line 52, in __init__ Apr 25 15:32:50 pirate-audio mopidy[976]: GPIO.add_event_detect( Apr 25 15:32:50 pirate-audio mopidy[976]: RuntimeError: Failed to add edge detection How can I fix this? I'm a Raspberry Pi Zero 2 with Raspi OS Bookworm 32bit on If I Install Raspi OS Bullseye, the problem disapeear. Maybe the newer version of python is the point.

quozl commented 4 months ago

@davidbenucci, your error shows the system package for Mopidy is loading the Mopidy Raspberry Pi frontend from your pip collection. Mixing old and new versions. You might try removing the system package for Mopidy and use pip to install Mopidy instead. https://github.com/pimoroni/pirate-audio/issues/98 has some more interesting detail that may help. I've not yet upgraded my unit to these versions.

davidbenucci commented 4 months ago

I follow your suggestion and install all packages with sudo pip <packages list> (exception for pip and pil) but I got the same error evene launching mopidy as root.

@davidbenucci, your error shows the system package for Mopidy is loading the Mopidy Raspberry Pi frontend from your pip collection. Mixing old and new versions. You might try removing the system package for Mopidy and use pip to install Mopidy instead. pimoroni/pirate-audio#98 has some more interesting detail that may help. I've not yet upgraded my unit to these versions.

quozl commented 4 months ago

Thanks. I suggest you try what I did in January (above) and change the plugin code to report which pin is failing, run it to have it fail, and then remove that pin from your Mopidy configuration. Repeat until it runs properly. Or remove all pins from the configuration and add them back one at a time. A pin may not function because the operating system has been configured to dedicate it to another purpose, or another application is using it.

davidbenucci commented 4 months ago

Thanks. I'll try this. But one thing: if I use Raspi OS Bullseye everything works fine. It's a bit strangethat a frash install of a OS use some pins by default, inn't it? I have only pirate audio hat on my Pi Zero 2

quozl commented 4 months ago

Yes, it is a bit strange, presumably Bullseye and Bookworm have enough differences to break this for you. I'm loath to upgrade to find out for myself that it breaks. I've had a look at another Raspberry Pi that I've upgraded to Bookworm that doesn't have a Pirate Audio Hat, and it isn't clear to me yet if there's any pins allocated to some other use, or if the numbering has changed. You could also try stopping mopidy and then using the pins in some other way, such as with Python. That might indicate a cause.