[PLUGIN] RotaryEncoder II

Hi , is it possibile to have an “how to “ wire encoder stec11b03. Thanks

1 Like

There are examples on this page of the documentation

1 Like

Hi @T0MR0

the plugin has been included in the official repository!

thanks for your great work!

Yes - seen it already! Nice :blush:

Good afternoon.
So far I have used the plugin version from Saiyato. It worked very well. Volume, button.
Yesterday I installed Volumio 3.251. Only RotaryEncoder II is among the plugins. I have installed. The volume works perfectly, but the push button doesn’t work at all. Sometimes it will work once - right after starting Volumio, then not. Sometimes pressing causes a reboot the respberry.
My encoder is KY-040, all lines have a pullup and a 100nF capacitor. Changing the GPIO does not help, the effects are the same.
Platform: Raspberry Pi 3A+. I don’t use a DAC, only an LCD on i2c.
UPDATE!
The problem only occurs on the internet radio!
When listening to music from a NAS, everything works perfectly!

Hi elpaul,

Sorry to hear it is not working. I’d like to try and help, but need a little more info from your side.

  1. “Pressing causes a reboot” sounds bad - but unlikely to be software related. For the button press I rely on the npm onoff module. Would not know, how I can make the Pi crash via that… unless you have selected “reboot” as one of the button press options :wink:
    By the way, if you have ‘reboot’ on the double-click and bouncing, this may actually be the case. But with pullup and 100nF, unlikely.

  2. You do not even mention, which commands you are sending to Volumio by push-button. I am actually using the plugin on my Tube Radio project, that is only playing Internet Radio - all actions like Start, Stop, Pause, Mute are working on my system - so I need more info.

  3. To see, if there is a problem with the logic of the plugin, that does not generate problems for the other users, but in your case does, it would help if you can enable logging and generate a log-file while the problem occurs (ideally not too much additional log stuff around that occurence). I already just added a step-by-step instruction to the top post of this thread in a collapsible section.

I must already ask for some patience - family and work keep my time limited.

hi I need help with me rotary encoder. I have 3 encoders but doesn’t work well. does someone have my config and can share the gpio used? thanks
i have three stec 11b03 tried at 5 and 3 v without resistance … sometimes works but press button never works… thanks for any help
my hardware pi3 with hifiberry dac2hd board

please provide some more details about the hardware connection of the push-button.

I am using this plugin with a 10 kOhm -pull-up resistor to 3.3V and a 10 nF capacitor, the push-button of the encoder works like a charm with the following setting:

here below the complete schematic

Hi Whisper 74.
You should never connect the GPIOs to 5V.
They are specified at 3.3V and should be operated there. 5V will damage them sooner or later.
That said: if the rotary‘s rotational function is ok, then the switch should also be. Basically they are both just Switches.
If you do not use „any resistance“ that might be the problem: an open input is floating and can have both high and low state. Try to Google for „pull-up/-down resistor“ to get explanations. There are internal pull-ups in the Pi, but they are not always enabled.
In principle you could also refer to the debouncing tips I compiled in the Docs, they will also work for buttons.
Feel free to come back if you still see issues. You can refer to the topmost post on this thread, if you want to provide logs.
I suppose your problem is wiring related, so a small sketch of your schematic will help.

I just realized I was using the old version 1.0.7

with the latest one 1.0.11 I also have problems with the push-button

@T0MR0 how can I help you to debug this issue?

Here some log information

thanks. can you share your gpio connection of your 3 encoders? i have no resistor on my encoder… but if i know the gpio a viable for encoders…

Not all the gpio’s are set “high” or “low” some may be floating this is why you should use pull up/down resistors.

That said…If you can find which are normally high after boot, then you can get away with using those without a pullup resistor. But it is advisable when pulling them low ( ie when switched) to do this through a resistor to prevent the risk of overloading the port and damaging your kit.

You can find out which way your ports are set by SSHing into the pi and doing a gpio readall
that will give you a nice little chart showing you which state your ports are set.

Capt

bare in mind though if you are using a pi 4 you’ll need to update to be able to read the ports

cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb

Also bare in mind that you will also need 100nf capacitors across all the switches otherwise they will be as erratic as an erratic thing.

Hi all,

wanted to verify this and try to install the plugin from the store. But obviously they changed the package.json during the merge, to no longer support v3.179. Unfortunately I did not just change the package.json but tried to install the latest version, which ended in a mess with my WiFi dongle.
Will have to re-setup my development system and downgrad to an older version first, to fix the WiFi problem that exists with 3.251.
Probably wont have the time to look into it before Easter again - so please be a little patient.
Not sure, what the problem might be. I am basically relying on onoff for the pushbuttons. Need to have a look myself. On my V3.1x system it worked with the version from my local Repo

Hi @T0MR0

Just to clarify, I have V3.251 clean install and installed your rotary encoder 2 plugin 1.0.11 from the store.
I am only using one encoder but it all works fine and as expected, no erattic behaviour, button works every time too.

Hi, did not have time to bring my test-system back up yet - seems to be a bigger issue with the WiFi dongle and the last working version is not available anymore and even 3.198 is not working anymore. Need to dig some further.
However I looked at your log and at my code. The code is just creating an instance of the GPIO object from onoff per button and then setting up a watch callback that reacts on the rising and falling edges of the GPIO. Depending on the active-high/active-low setting, a button press is either a rising/falling edge and a release is the opposite.
Normally, rising and falling edge will always alternate, but the log shows 5 button presses in a row and afterwards 5 releases in a row (I assume, you did not press 5 times within 1 second). As the message says, this is not normal and may have different reasons:

  • bouncy button (if the spikes are faster than the reaction time of onoff, but I remember, you had hardware debouncing, right?)
  • node being too busy with other things to react fast enough
  • race conditions in my code, which I did not observe during testing
  • debounce time and long-press, double-press time are not matching

The first item should be solvable by increasing the setting for the debounce-time (e.g. 50 or 100ms), the log tells us, that the releases seem to be detected after ~200ms, so the 5 presses seem to come within under 200ms, i.e. at 40ms intervals.
The second and third might be the case, if the current versions of Volumio are running things differently from the Beta I tested with (can only verify once I fix my test system).
The fourth item you can try by yourself (or at least post your settings here). If you are not actively debouncing, you need to set at least 50ms of debounce time and the double-click and long-press times should be significantly longer (at least factor 2 better 4, I’d suppose).

Generally, JS seems not perfect for real-time applications. If the processing of button events is stuck in the Node eventLoop, it may lead to strange behavior.
If it turns out, that onoff is really too slow for the button now, a possible solution would be to abondon onoff and move to a similar approach as for the rotation (using Kernel dtoverlays). But so far I sticked with the easier implementation, because the button events seemed slow enough. Need to ask for some more patience until after the Holidays until I can look into this.

Hi @T0MR0 ,

many thanks for having a look

I can confirm I have hardware debouncing on the switch. The very same setup was working fine with v1.0.7, as soon as I updated to 1.0.11 the buttons did not work anymore.

Increasing the debouncing time up to 200ms does not solve the problem.

Hi @T0MR0 ,

I just found out that the button works again if I disable this plugin on my Raspberry Pi Zero 2

I also found out the v1.0.11 does not have any problem on my CM4, even if i keep the Music Services Shield plugin active

Hi!
Looked at the code a bit more. I suspect that this is a timing issue due to the added functionality with the double-press.
I suspect that it is unstable depending on the system loading/ node eventLoop. That might explain, why it is not observed by everybody and did not show up when I tested it.
I have my test system up again and luckily it shows the same behavior, while my main system works.
Will give it some thought how to modify the implementation. But can only start to test it next week.
Sorry for the inconvenience!

Hi @T0MR0,

no problem at all, please take your time!

2 Likes