Skip to content
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

RuntimeError: Failed to add edge detection #9

Open
githubtobi opened this issue Jul 16, 2020 · 14 comments
Open

RuntimeError: Failed to add edge detection #9

githubtobi opened this issue Jul 16, 2020 · 14 comments
Labels
enhancement New feature or request
Milestone

Comments

@githubtobi
Copy link

githubtobi commented Jul 16, 2020

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
Copy link
Member

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
Copy link

willemk commented Jul 17, 2020

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:

  • Install the RPi.GPIO library through pip. I think this should live under the install_requires section in the setup.cfg file.
  • I also had to give permission to the mopidy user to access the GPIO ports by running sudo usermod -a -G gpio mopidy

@Gadgetoid
Copy link
Member

Gadgetoid commented Jul 17, 2020

@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:

@Gadgetoid Gadgetoid added the enhancement New feature or request label Jul 17, 2020
@githubtobi
Copy link
Author

githubtobi commented Jul 17, 2020

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
Copy link
Member

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.

Gadgetoid added a commit that referenced this issue Jul 17, 2020
This config is set by the Pirate Audio install script- https://github.com/pimoroni/pirate-audio/blob/master/mopidy/install.sh

Since this library is device agnostic, these defaults don't have to be here, and shouldn't be here. Users should have to explicitly configure and enable the plugin.

See #9 for an example of the default pin config being unexpectedly loaded and causing the plugin to bail.
@Gadgetoid Gadgetoid added this to the v1.0.3 milestone Jul 31, 2020
@gamecat69
Copy link

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
Copy link

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

@quozl
Copy link

quozl commented Jan 25, 2024

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;

@davidbenucci
Copy link

davidbenucci commented Apr 25, 2024

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
Copy link

quozl commented Apr 25, 2024

@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.

@davidbenucci
Copy link

davidbenucci commented Apr 26, 2024

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
Copy link

quozl commented Apr 26, 2024

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
Copy link

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
Copy link

quozl commented Apr 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants