Getting rotary encoder working

I struggled with the rotary encoder plug-in with a cheap KY 040 encoder off amazon … very spurious and unpredictable volume and switch behaviour, probably caused by using interrupt-driven code with no hardware de-bouncing. To get over it I wrote a very basic (less than half a page of code) and simple python script that works very reliably (albeit not very elegant) as follows. You may need to play with the sleep times and you will need to change the GPIO pin numbers depending on your set-up. I used the REST API (see here to control things because it was so easy and didn’t need any extra libraries:
Once you’ve tested this, you will need to add it to the boot startup script. I just use update-rc.d and it works fine.

Thank you for your post. I have some issue with rotary encoder too. You have interesting approach :slight_smile:. I have pair tips:

  • you can paste code. It’s better as image. Volumio forum has button for this. It called “Code”
  • This code takes very much compute power. When is rotary encoder idle, so your code checks the state of pins 200 per second. You can use diffrent approach. Operation system can call your function, when processor detects a change on GPIO. … coder.html
  • Play/Pause functionality. It will be better use toggle functionality.
1 Like

Hi there,

It’s also good to mention which versions you are running on, i.e. which versino of Volumio and which version of the plugin.
I can confirm the behaviour being choppy, this has greatly improved in recent versions. :wink:

Hi Saiyato,
first thank you for your work on plugins. Today I retested rotary encoder in my sestup. It works! :slight_smile: But I had some trouble.

  • notes in plugin are little confusing
  • in notes contains word “pin”. I think, you mean raspberry pins on 40 pins connector and not GPIO. Please, can you change it.
  • some GPIOs aren’t proper for this work. I mean GPIOs for I2S or for I2C. It’s my case, I use DAC hat. You can recomand some GPIOs. I think GPIO 20, 16 and 12 are ok.
  • plugin works after restart (I think first setup. Maybe, can you add this information to main text on top.
  • I have oposite direction for volume. I use ky040 rotary encoder. I set clk to 16 and dt to 20, coding is ky040. When I make a turn clockwise then volume make a step down. It’s correct?

Hi mate,

The pins are actual GPIO numbers, not the header numbers.
You are correct in the sense that some GPIO pins are unusable if you’re using a HAT DAC. However, not everyone uses a HAT DAC, some people prefer USB, therefore all pins are selectable. I’ll try to clarify.

Which version of the plugin are you using? I just published a new version on github, the one in the store is out-dated. There have been various patches to that version after intensive testing. When connected correctly rotating clockwise will increase the volume, but again, the code on github is way more stable.

Yes some people use USB DAC, but for a novice is hard to understand which hadrware pin must connect and whitch GPIO must set as number in plugin. I had to print raspberry’s pinout ( … 3_gpio.png). I’m beginner in this field. I try to say, when you change a little texts in your plugin, then you help many users.

I don’t know what version number. I use this plugin from volumio GUI (store version). I didn’t download plugin from github. I read michelangelo post about don’t use a zip file instalation. How hard is upload new version of plugin into volumio store?

I understand i’m bumping up an old thread but I feel this is the correct thread to seek help after searching around a bit. I don’t want to open a new thread because for all you know I might be missing something obvious :stuck_out_tongue: .

I’m new to the Rpi based media-player world and I recently moved to Volumio from piCorePlayer [using Rpi 4B - 4GB version with 7inch touch screen - latest version of Volumio downloaded couple of days ago] . I managed to add 2 Rotary Encoders to the Volumio with partial success- one for controlling volume/mute and other for track next/previous/pause.

Issues faced:
1. Volume can not be increased beyond 58 count on the player using encoder. However the same can be increased on touchscreen or from phone/laptop. I'm able to decrease the volume from 100 [if set on from phone] to any number. -sorted , see below!
2. None of the push actions on the encoders are being recognized [for Pause/Mute/Shutdown]

Are these known bugs? If not, can you please redirect me to correct thread?

EDIT: I can still edit my post!
Volume increase issue has sorted itself magically after playing around with Playback settings with multiple different options. But I still can’t get it to recognize push/long push actions though!

TIA :slight_smile:

Which DAC ist attached?
Hifiberry? Allo?