[PLUGIN] RotaryEncoder II

Ahhhh. That explains it. There are only two pull-ups not 3. Then I can understand why it works when we enable the internal pull-up and it also explains the erratic behavior (floating input).
Thanks for the picture!
I will look into your other question toward the weekend. Too tired today and too busy over the next days. Your setup is quite different from mine, so I have to study your log in detail

Glad I could help.

Sounds good, I’ll poke around myself and see what I can find as well.

Yeah, my board is exactly the same. Did not see that one resistor is actually missing, fck, very confusing shit, that 040 :grin:

How about putting that hint for configuring that pullup stuff in userconfig.txt inside the plugin-config-page by a nifty little info-mouseover-button, he? Since I’ve failed also with kinda alps-encoder it’s not only a ky-040 issue.

And since people are about to install a hardware plugin, it is to expect they don’t “paddle on a noodle-soup”, like we austrians say :sweat_smile: and are able to fiddle with config.txt’s.

On the other hand, when you do so, how in future do we get magic people like me into the community :thinking::joy:

Using a normal playlist of locally stored media the rotary plugin is working as expected?
If so, it’s more likely a spotify-plugin-issue, I guess.

I don’t have any local media, end goal is to create a Spotify connect speaker system. I did use a local web radio and I believe it did work properly. I’ll confirm tomorrow.

But, the toggle command through the API works perfectly for Spotify. So I would also assume this plugin is doing something different since it’s throwing the error in the logs.

Maybe a combination of both? But so far the only error I can create is from the “play/pause toggle” of this plugin while using Spotify connect.

Local ui play/pause button works and API toggle works.

Had a look at your log. The first six lines look completely good. We send toggle play/pause and Volumio’s CoreCommandRouter acknowledged receipt of the command on line 7: volumioPause.
At 19:18:57 the same block occurs, when you press the button again and in the 7th line the CoreCommandRouter acknowledges again: volumioPlay.
There is no error message from the plug-in nor any other message.

In your other method you are calling volumioToggle while the plug-in uses pause and play. However, you should be able to select sending a Websocket command for your button in the plug-in settings and put „toggle“ into the Command field and leave the data field empty. See if that does the trick.
However, it’s still strange, if the Spotify plug-in reacts correctly on toggle and pause, but not on play. I am not using Spotify, so I never tested your scenario. Might still be worth to check, why the Spotify-plug-in does not react on play. If there is a good reason, I could modify my code to use toggle as well.

I‘ll add it to the readme.md and the context help with the next update.
However, as somebody working in semiconductor reliability, I am still a big fan of external resistors on systems, where the user can change the IO-pad configuration easily :wink:
I may even be able to make the internal pull up configurable from the plug-in settings on one of the long winter nights to come.

Sadly i have yet to figure out what is wrong with the Emit Websocket Message as it will crash the system everytime I try to use it.

—LOG

-- Logs begin at Mon 2022-08-22 21:15:14 UTC. --
Aug 23 14:38:44 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:44 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:44 yamaplayer volumio-streaming-daemon[2439]: Environment: production
Aug 23 14:38:44 yamaplayer volumio[2221]: info: Fetching Streaming Services browse cache
Aug 23 14:38:45 yamaplayer volumio[2221]: error: Failed to add MyVolumio device: {"message":"USER_NOT_FOUND"}
Aug 23 14:38:45 yamaplayer volumio[2221]: info: Updating MyVolumio device info
Aug 23 14:38:45 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:45 yamaplayer volumio[2221]: error: Failed to update MyVolumio device: {"message":"DEVICE_NOT_FOUND"}
Aug 23 14:38:46 yamaplayer volumio-streaming-daemon[2439]: Environment: production
Aug 23 14:38:46 yamaplayer volumio[2221]: info: Fetching Streaming Services browse cache
Aug 23 14:38:49 yamaplayer volumio[2221]: info: MYVOLUMIO: Adding device
Aug 23 14:38:49 yamaplayer volumio[2221]: info: MYVOLUMIO: Evaluating Server
Aug 23 14:38:49 yamaplayer volumio[2221]: info: Setting Geolocation for MyVolumio to us3
Aug 23 14:38:49 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:49 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:49 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:49 yamaplayer volumio[2221]: error: Failed to add MyVolumio device: {"message":"USER_NOT_FOUND"}
Aug 23 14:38:50 yamaplayer volumio[2221]: info: Updating MyVolumio device info
Aug 23 14:38:50 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:50 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:50 yamaplayer volumio[2221]: info: CoreCommandRouter::executeOnPlugin: system , getConfigParam
Aug 23 14:38:51 yamaplayer volumio[2221]: error: Failed to update MyVolumio device: {"message":"DEVICE_NOT_FOUND"}
Aug 23 14:38:52 yamaplayer volumio[2221]: info: [ROTARYENCODER2] Push Button 1 pressed.
Aug 23 14:38:52 yamaplayer volumio[2221]: info: [ROTARYENCODER2] Push Button 1 starting timers.
Aug 23 14:38:52 yamaplayer volumio[2221]: info: [ROTARYENCODER2] Push Button 1 released after 170ms.
Aug 23 14:38:53 yamaplayer volumio[2221]: info: [ROTARYENCODER2] Push Button 1 doublepush timer elapsed. (false, 1)
Aug 23 14:38:53 yamaplayer volumio[2221]: info: [ROTARYENCODER2] Push Button 1 sending single push command.
Aug 23 14:38:53 yamaplayer volumio[2221]: |||||||||||||||||||||||| WARNING: FATAL ERROR |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Aug 23 14:38:53 yamaplayer volumio[2221]: SyntaxError: Unexpected end of JSON input
Aug 23 14:38:53 yamaplayer volumio[2221]:     at JSON.parse (<anonymous>)
Aug 23 14:38:53 yamaplayer volumio[2221]:     at rotaryencoder2.emitPushCommand (/data/plugins/system_hardware/rotaryencoder2/index.js:725:17)
Aug 23 14:38:53 yamaplayer volumio[2221]:     at Timeout._onTimeout (/data/plugins/system_hardware/rotaryencoder2/index.js:532:18)
Aug 23 14:38:53 yamaplayer volumio[2221]:     at listOnTimeout (internal/timers.js:554:17)
Aug 23 14:38:53 yamaplayer volumio[2221]:     at processTimers (internal/timers.js:497:7)
Aug 23 14:38:53 yamaplayer volumio[2221]: |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Aug 23 14:38:53 yamaplayer sudo[2490]:  volumio : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/journalctl --since=2022-08-23 14:37
Aug 23 14:38:53 yamaplayer sudo[2490]: pam_unix(sudo:session): session opened for user root by (uid=0)
Aug 23 14:38:53 yamaplayer sudo[2490]: pam_unix(sudo:session): session closed for user root
Aug 23 14:38:53 yamaplayer volumio-remote-updater[491]: [2022-08-23 14:38:53] [error] handle_read_frame error: websocketpp.transport:7 (End of File)
Aug 23 14:38:53 yamaplayer volumio-remote-updater[491]: [2022-08-23 14:38:53] [disconnect] Disconnect close local:[1006,End of File] remote:[1006]
Aug 23 14:38:53 yamaplayer systemd[1]: volumio.service: Main process exited, code=exited, status=1/FAILURE
Aug 23 14:38:53 yamaplayer systemd[1]: volumio.service: Failed with result 'exit-code'.
Aug 23 14:38:53 yamaplayer systemd[1]: Started dynamicswap service.
Aug 23 14:38:53 yamaplayer systemd[1]: dynamicswap.service: Succeeded.
Aug 23 14:38:54 yamaplayer systemd[1]: volumio.service: Service RestartSec=100ms expired, scheduling restart.
Aug 23 14:38:54 yamaplayer systemd[1]: volumio.service: Scheduled restart job, restart counter is at 3.
Aug 23 14:38:54 yamaplayer systemd[1]: Started dynamicswap service.
Aug 23 14:38:54 yamaplayer systemd[1]: Stopped Volumio Backend Module.
Aug 23 14:38:54 yamaplayer systemd[1]: Started Volumio Backend Module.
Aug 23 14:38:54 yamaplayer systemd[1]: dynamicswap.service: Succeeded.
Aug 23 14:38:55 yamaplayer volumio[2501]: info: -------------------------------------------
Aug 23 14:38:55 yamaplayer volumio[2501]: info: -----            Volumio3              ----
Aug 23 14:38:55 yamaplayer volumio[2501]: info: -------------------------------------------
Aug 23 14:38:55 yamaplayer volumio[2501]: info: -----          System startup          ----
Aug 23 14:38:55 yamaplayer volumio[2501]: info: -------------------------------------------

Did not try it myself yet, because my test-system is not workable at the moment. Websocket works normally in another setup I‘m heavily using, but I never tried the toggle command. Will check toward the weekend why it crashes, but currently have no time. Will respond asap

yea it is strange, nothing for websocket works for me. I originally followed the steps exactly and tried doing volume + & - via the emit command. Same results of crashing.

Hi! Thanks for the bug report - it is acutally my fault - apologies. I implemented the websocket emit functionality for something more complex (sending commands between the rotary and another plugin I am working on).
When I wrote the docs, I wanted to show a very simple example, but after I improved my code to do the complex stuff, I broke the simple stuff explained in the docs. Unfortunately, I never tried it again, because it is not really important for me.
I made a quick and simple fix (beta 1.0.17) that will work with the complex and the simple stuff. It works on my test system. For the moment that should solve your issue, if you put toggle into command and nothing into data, as shown above.
Currently I cannot do more… will see if I can also implement toggle in the drop-down later with more than 30 minutes time.
Let me know if it works.

Works perfectly, toggle now pauses / plays spotify connect without any issues.

I also got next track to work with double click via the websocket.

Thank you!

Just to finish with my KY-040 issue, and for your list of compatible encoders, the conclusio:

No capacitors or resistors on any pins needed, the KY-040 has two 10k resistors onboard for clk/dt, but obviously not for the switch, so the gpio-pullup needs to be enabled for the push button gpio.

A debounce value of 40ms is good and has no negative effect by rotating. Below that value or zero only every second/third push works.

Regards,
Phil

1 Like

Thanks,will add it in the next update of the docs! (Including the setting for the internal PU)

Hello,

I have an RPi4 + AMP100 (Hifiberry) with Volumio 3.378. I installed the Rotary Encoder II plugin but it looks live I have issue with my rotary encoder (KY-040 I guess).

Here is what I get with : journalctl | grep -i encoder*

Dec 10 18:26:06 litra kernel: bcm2835-codec bcm2835-codec: Loaded V4L2 encode
Dec 10 18:26:36 litra volumio[814]: info: Loading plugin "rotaryencoder2"...
Dec 10 18:26:37 litra sudo[974]:  volumio : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/dtoverlay rotary-encoder pin_a=22 pin_b=17 relative_axis=true steps-per-period=2
Dec 10 18:26:38 litra kernel: rotary-encoder rotary@16: gray
Dec 10 18:26:38 litra kernel: rotary-encoder rotary@16: unable to get gpios: -16
Dec 10 18:26:38 litra kernel: rotary-encoder: probe of rotary@16 failed with error -16
Dec 10 18:26:39 litra volumio[814]: error: [ROTARYENCODER2] addEventHandle: stderr: /bin/cat: /dev/input/by-path/platform-rotary@16-event: No such file or directory

1 Like

Quote from Hifiberry website https://www.hifiberry.com/docs/hardware/gpio-usage-of-hifiberry-boards/

HiFiBerry Amp100

GPIO2-3 (pins 3 and 5) are used by our products for configuration. If you are experienced with I2C, you might add other slave devices. If you a a novice, we don’t recommend this at all.
GPIOs 18-21 (pins 12, 35, 38 and 40) are used for the sound interface. You can’t use these for any other purpose.
GPIO4 is used to control the MUTE function of the power stage. Pulling it to high will mute the output.
GPIO17 is used to reset the power stage (active low).

Seems from your diagram you are trying to use GPIO 17 with the rotary encoder, which is also being used by the Hifiberry.
Maybe the Problem ?

1 Like

@M1ck I’ve changed DT GPIO 17 to GPIO 5. When I tried to update the plugin to change the value “PIN B GPIO” to 5, the plugin didn’t save it.

So I edited “/data/configuration/system_hardware/rotaryencoder2/config.json” to change the value. After I reboot the Raspberry, the value in PIN B GPIO update correctly to “5”.

What I get now for : journalctl | grep -i encoder*

Dec 10 19:26:53 litra kernel: bcm2835-codec bcm2835-codec: Loaded V4L2 encode
Dec 10 19:27:28 litra volumio[825]: info: Loading plugin "rotaryencoder2"...
Dec 10 19:27:29 litra sudo[1026]:  volumio : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/dtoverlay rotary-encoder pin_a=22 pin_b=5 relative_axis=true steps-per-period=2
Dec 10 19:27:29 litra kernel: rotary-encoder rotary@16: gray

But still the volume control doesn’t work.

Rotary encoder settings:

PS : Sorry I forgot to mention I use Spotify Plugin.

can you give these gpio numbers a try.
what plugin version are you using?

can you try not to make multiple posts, otherwise it will be a bit unclear :wink:
@Wheaten

Rotary Encoder II version is 1.0.15

I just tried this, when I turned down the volume, it looks like the sound did turn down and then the raspberry shutdown.

`

What I get for journalctl | grep -i encoder*

Dec 10 19:53:53 litra kernel: bcm2835-codec bcm2835-codec: Loaded V4L2 encode
Dec 10 19:54:24 litra volumio[814]: info: Loading plugin "rotaryencoder2"...
Dec 10 19:54:25 litra sudo[975]:  volumio : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/dtoverlay rotary-encoder pin_a=23 pin_b=24 relative_axis=true steps-per-period=2
Dec 10 19:54:26 litra kernel: rotary-encoder rotary@17: gray
Dec 10 19:57:30 litra volumio[814]: info: CALLMETHOD: system_hardware rotaryencoder2 updateEncoder [object Object]
Dec 10 19:57:30 litra volumio[814]: info: CoreCommandRouter::executeOnPlugin: rotaryencoder2 , updateEncoder
Dec 10 19:57:30 litra sudo[1672]:  volumio : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/dtoverlay rotary-encoder pin_a=23 pin_b=24 relative_axis=true steps-per-period=2
Dec 10 19:57:30 litra kernel: rotary-encoder rotary@17: gray

I found at that my config.json at data/plugins/system_hardware/rotaryencoder2 doesn’t seems to save my values:


    "enabled0": {
        "type": "boolean",
        "value": false
      },
    "rotaryType0": {
      "type": "number",
      "value": 0
    },
    "pinA0": {
      "type": "string",
      "value": ""
    },
    "pinB0": {
      "type": "string",
      "value": ""
    },
    "dialAction0": {
      "type": "number",
      "value": 0
    },
    "socketCmdCW0": {
      "type": "string",
      "value": ""
    },
    "socketDataCW0": {
      "type": "string",
      "value": ""
    },
    "socketCmdCCW0": {
      "type": "string",
      "value": ""
    },
    "socketDataCCW0": {
      "type": "string",
      "value": ""
    },
    "pinPush0": {
      "type": "number",
      "value": 0
    },
    "pinPushDebounce0": {
      "type": "number",
      "value": 0
    },
    "pushState0": {
      "type": "boolean",
      "value": false
    },
    "pushAction0": {
      "type": "number",
      "value": 0
    },
    "socketCmdPush0": {
      "type": "string",
      "value": ""
    },
    "socketDataPush0": {
      "type": "string",
      "value": ""
    },
    "longPushAction0": {
      "type": "number",
      "value": 0
    },
    "socketCmdLongPush0": {
      "type": "string",
      "value": ""
    },
    "socketDataLongPush0": {
      "type": "string",
      "value": ""
    },
    "delayLongPush0": {
      "type": "string",
      "value": "1500"
    },
    "doublePushAction0": {
      "type": "number",
      "value": 0
    },
    "socketCmdDoublePush0": {
      "type": "string",
      "value": ""
    },
    "socketDataDoublePush0": {
      "type": "string",
      "value": ""
    },
    "delayDoublePush0": {
      "type": "string",
      "value": "700"
    },
    "enabled1": { ... ... . ...
.... .... ... ...

Is this normal?

I changed it with the one with correct values. But when I use the rotary, the raspberry shutdown.