[PLUGIN] RotaryEncoder II

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

so i ve done the gpio read all. if I don’t want to use any resistor / capacitor I have to use only gpio in “alto” mode?

if i understand all the alt0 are for my use… but all are used by my hifiberry dac2 board…

and there s but I have to use two alto gpio for 1 encoder ?a software way to modify state without add any hardware ?

thanks so much

later i ve seen thia video. i ve connected same mode… volume rotary works but the button doesent work… why? the config seems right

@Whisper74
Its not just the ALT0 for you to use, the ALT0 have more than likely been set by your dac. You cannot use those as obviously are being used by your dac.

In the gpio readall chart
Mode. alt = alternative, in = input, out = output
V, 1=high 0=low or floating.
Physical are the physical pins on your rpi header
BCM (Broadcom) are GPIO numbers you enter into the software correlating to the physical pin you have used.

To use them without pull up/down restistor you are better off to choose one that is set high.
So you need to find one that says IN and 1 ie an input that has internal pull up already set.

The way I have my encoder wired.
Center pin of the group of 3 connected to 0v, left pin to gpio 7 (physical pin 26) right pin to gpio 8 (physical pin 24)

then the other side with just 2 pins, one connected to 0v and the other connected to gpio15 (physical pin 10)

All connections to the gpio go through a 1K resistor and also have 100nf capacitor between 0v and the gpio ( switch side)
The 1 K resistors are only there for current limiting to protect the gpio port, and the capacitors are there for debouncing ( ie prevent acidental double clicking)

when connecting the rest of your encoders ensure that you are not using any gpio’s that your dac is using. A quote from hifiberry

HiFiBerry DAC2 HD

GPIO2-3 (pins 3 and 5) are used by our products for configuration of the DAC and the clock circuit. GPIOs 18-21 (pins 12, 35, 38 and 40) are used for the sound interface. GPIO16 is used internally to reset the DAC. You can’t use these GPIOs for any other purpose.

Hope this helps :+1:

thanks. but another strange thing. volume up doen works. graphically goes up and down but in the stereo exit remains the same… ehy?

@Whisper74

Do you mean, you turn the rotary encoder, the numbers go up and down ok but the actual volume loudness stays the same.

Does the volume control work with the OSD ?

Do you have the correct setting in settings>playback options especially the volume options.

ok corrected the problem of volume

after some test all rotary encoders works but push button of no one works…

my setting.
encoder 1 - volume - gpio 4 - 17
encoder 2 - skip track - gpio 27 - 22
encoder 3 - seek on title - gpio 9 - 10

the problem is which gpio for press or long press. i ve tested gpio 12 works only one time…

As written further up, some people are having issues with the button press on some devices.

Works fine on mine though using 0v and gpio15 (physical pin 10)
Make sure you enable “button logic-level Active low” in the plugin settings.

thanks. enable but with no success. what do younmean 0v?

0v=Ground.

Look in your gpio readall chart under name. it shows all the pins that are 0v

mmm… i ve unite all 3 positive encoder pin and soldered to 3v
… now i have a doubt
… i ve done the same thing to gnd cable (3 merged together and soldered to 1 gnd pin)…

do i have to separate to 3 single negative encoder pin to enable the press button with combination 0v - gpio?

1 Like

rotary

This is your encoder …correct?

the 2 pins on the left are for the button
the 3 pins on the right are for the encoder
none of the pins are connected internally to each other.

So you are safe to use the 2 pins on the left for 0v and gpio15 (physical pin 10) and the 3 pins to however you want to connect it.

Just do not make it so that 0v connects directly to 3.3v

A diagram of how what you are attempting to do could be of help

i ve used this scheme but not connetct the vcc to 5v but connect to 3v


so on left attached 3v and gpio for command

on right side: right and left encoder and in the middle gnd

with this config all rotative works but no button

1 Like

That in theory should work.
But as above its not working in some configurations.

Heres a diagram of how mine is configured there is also 1k resistors in line with the GPIO ports and 100nf capacitors conected between all the GPIO ports and ground (switch side)
This works fine for me on a RPI 4, Volumio 3.251, and Rotary plugin 1.0.11