ESP32-Radio icon indicating copy to clipboard operation
ESP32-Radio copied to clipboard

Two rotary encoder

Open cypeks opened this issue 7 years ago • 21 comments

Is it possible to add a second rotary encoder? As in the traditional radio: one for volume control, the other for radio change, etc ...

cypeks avatar Nov 25 '17 19:11 cypeks

Yes, you need 2 free input pins. And you need to change the software. It's easier to use a potentiometer instead of a rotary switch for the volume.

Edzelf avatar Nov 25 '17 19:11 Edzelf

Can you tell me how to adjust the volume in the program? Using the vs1053player.setVolume() object?

cypeks avatar Nov 25 '17 23:11 cypeks

Just change ini_block.reqvol to a value between 0 and 100.

Edzelf avatar Nov 26 '17 09:11 Edzelf

I just realized that you may connect 2 second rotary switch for just the volume in parallel of the first. If you do not connect the SW-pin, the function of this switch will be limited to "volume" only. No need to change the software and no extra I/O pins required.

Edzelf avatar Nov 26 '17 11:11 Edzelf

Not exactly good because I need to connect two rotary encoders. One to adjust the volume, the other to change the station. I'll try to add enc2 support.

cypeks avatar Nov 26 '17 14:11 cypeks

Yes, that's what I meant. One for volume, one for the rest.

Edzelf avatar Nov 26 '17 17:11 Edzelf

Hello All, I started implementation of two encoders. Simply cloned ISR Routine and chk_enc routine. Also cloned all encoder variables. But there is an issue with preset switching. Original routine has a hard-coded timeout : "case PRESET: { waittime = 10;" because of this timeout preset change works really slow comparing to the web interface command. without timeout it works pretty fast, but I get another bug - encoder can skip presets. It would be great to have a flag which shows that preset is already in switch process. i tried : "if (datamode == STOPREQD) return; " but it does not help.

Even web interface command can switch two presets down without waiting for connecting to stream. how can I identify that connecting process is already finished to allow second preset change command?

DaniilMir avatar Mar 04 '18 14:03 DaniilMir

Yes, the rotary switch function is not very well implemented. I will redesign it.

Edzelf avatar Mar 04 '18 16:03 Edzelf

Here is a pretty good article I came across today in my inbox.. It shows only three shares, so I'm guessing it's new(ish). Although I haven't tried it, you might try this method out because I have found my encoder to be quite problematic (when using it, it will do any of the following: skip multiple increments, move in the wrong direction, or sometimes cause a crash/reboot).

This method sounds good on paper, from the description (the second method described) but as I haven't experimented with it, I do not know for sure. You might want to give it a try, since it would be as simple as copy/paste and could save you a bunch of time if it works well.

The author also claims that it is robust, unique & won't be found anywhere else on the Internet

http://www.best-microcontroller-projects.com/rotary-encoder.html

koskee avatar Mar 04 '18 21:03 koskee

That's exactly the method being used in the radio. The difficulty is how to handle the results of the movements.

Edzelf avatar Mar 04 '18 21:03 Edzelf

best option is to split all functionality first: split encoder rotation and encoder clicks second: spit encoder rotation and commands processing.

in current case we have scope to change volume and preset. We have commands like
"upvolume" - "downvolume"
"uppreset" - "downpreset"

on rotate action we can send this command and wait for a flag say"command process on" till flag is on - ignore all other rotations. from encoder rotation process we expect direction only (even in current implementation) flag processing can work even with existing setup with one encoder.
we can bypass this flag with define option.

DaniilMir avatar Mar 04 '18 22:03 DaniilMir

Well yes, it is similar in its use of tables, however I don't see any sort of denounce filter as he has described.

I think that many of the issues (that I'm running into, anyway) could logically be attributed to contact bounce.. Either way, I'll try it when I have a moment.

koskee avatar Mar 04 '18 23:03 koskee

No need for debounce if a state machine is used to detect rotation. I've improved the interface in the new version. Added some debug output to show the detected clicks and rotation.

Edzelf avatar Mar 05 '18 11:03 Edzelf

Hallo DaniilMir ,

have you finish the implementation of two encoders? i am interested for an test

Meinolf

dl6dbh avatar Apr 21 '20 09:04 dl6dbh

I just realized that you may connect 2 second rotary switch for just the volume in parallel of the first. If you do not connect the SW-pin, the function of this switch will be limited to "volume" only. No need to change the software and no extra I/O pins required.

Hi @Edzelf, Could you elaborate a bit more on this? Would like to implement it. Thanks!

greppp avatar Sep 09 '20 15:09 greppp

Plus, ground and the two rotation signals of the sevond encoder in parallel of the first. What can I say more?

Edzelf avatar Sep 09 '20 17:09 Edzelf

@Edzelf Thanks for your answer. Let's call "encoder A" the one that doesn't have the SW-pin connected and "encoder B" the one that has the SW-pin connected. If I turn encoder A, the volume goes up or down. I get it. If I turn encoder B (knowing the rotations signal are in parallel of the other encoder), how come it will change the stations and not adjust the volume? Thanks for your time, this is really appreciated.

greppp avatar Sep 12 '20 03:09 greppp

I just test the radio with 2 encoders. I put them in full parallel mode (all 5 pins). It worked as expected. I could use both encoders to change the volume.

Edzelf avatar Sep 15 '20 09:09 Edzelf

I'm looking add adding a second encoder – encoder A for presets only and encoder B for volume only.

Could any one explain running them in parallel – it's not clear from the above comments, are the encoders wired to seperate pins? Where would I declare the second encoder in the config? @Edzelf @greppp

mousemat86 avatar Aug 06 '21 17:08 mousemat86

Why not use a potentiometer for the volume? For an extra rotary encoder you need at least 2 free I/O pins. And some changes in the software.

Edzelf avatar Aug 06 '21 18:08 Edzelf

@mousemat86 I never finished the project, but if you use a potentiometer for volume control then the added bonuses are that:

  • It become more responsive
  • Smooth transition from low to high volume (no steps), which will give you a nicer feel.
  • No need for extra pins
  • Less software change

good luck!

greppp avatar Aug 06 '21 18:08 greppp