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

Rotary Encoder Support for Volume Control #11

Closed MeltyMakes closed 3 years ago

MeltyMakes commented 3 years ago

Hello, I was wondering how easy it would be to implement support for rotary encoders for volume control including possibly push to toggle mute/unmute. I took a look at the source code and it looks like you could add wrapper handlers tied to the A/B pins that call either handle_volume_up/down once the direction is determined. However, I'm not super familiar with how these scripts work on Raspberry Pi so I'm not sure whether storing state variables to decode the encoder would cause problems or not.

TheBigFudge commented 3 years ago

@SidewaysFinch did you get any further? can a rotary encoder be used to set the volume up/down?

MeltyMakes commented 3 years ago

@TheBigFudge I haven't had time to look into it on the software side yet sorry. You could probably get it done in hardware if you made a decoder circuit and had it pulse to two GPIOs and set those to trigger the volume up/down events.

Gadgetoid commented 3 years ago

The linked PR solution looks pretty tidy- if either of you has the hardware set up to give it a go, I'd appreciate some feedback. I'm still using a perched-on-the-end-of-a-kitchen-table office and don't have a Pi set up for testing at the moment.

MeltyMakes commented 3 years ago

I can't promise results within the week but I'll see if I can't try and get things running soon. Thanks for the update!

martinfelis commented 3 years ago

This issue likely can be closed. I have been using the code for the last two months without an issue.

MeltyMakes commented 3 years ago

I managed to get some time this week to test my setup, it mostly works except it only seems to go in one direction for me? My mopidy.conf has the following:

[raspberry-gpio]
enabled=true
...
bcm23 = volume_up,active_low,10,rotenc_id=vol,step=1
bcm24 = volume_down,active_low,10,rotenc_id=vol,step=1

Whichever action is assigned to bcm23 is what happens, in this case it'll always increase in volume. I'm doublechecking my wiring today since it's likely that there's a short somewhere but I think this is otherwise good. If you have any ideas what I might be missing though @martinfelis I'd really appreciate it! Thanks.

martinfelis commented 3 years ago

@SidewaysFinch It could be a timing issue, specifically the bouncetime value. I am using the following related settings in my device:

bcm21 = volume_down,active_low,2,rotenc_id=vol,step=1
bcm20 = volume_up,active_low,2,rotenc_id=vol,step=1

Also maybe try using different gpio pins?

MeltyMakes commented 3 years ago

Huh I thought I commented last week but seems like I might've forgotten. The bouncetime was the issue, things are working fine now. I'll close the issue now, thanks all.