Rotary encoder hookup

All that relates to the H/W
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

Rotary encoder hookup

Post by Zim »

Hi
Does anyone have experience with hooking up this encoder? It appears to have added circuitry which I hope is for debounce.
How to connect "Switch, Data, Clock" to these terminals?

Thanks
Zim
Switch Rotary Encoder Module.jpg
You do not have the required permissions to view the files attached to this post.
BeanieBots
Posts: 315
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 168 times
Been thanked: 102 times

Re: Rotary encoder hookup

Post by BeanieBots »

Sorry, don't know that one specifically but it shouldn't be too hard to work out.
It certainly looks like it has 10k resistor pullups and decoupling caps fitted.
No obvious silicon anywhere so I'd guess the pin labelled 5v can be 3v3 with no consequences.
You could use a DVM to detect the function of the other pins but I would have high confidence that S1 and S2 are the two phases and 'key' is when you push down on the knob.
Don't forget, if you are going to use interrupts to read it, the interrupt triggers on BOTH high and low transitions.
You will have to write code to ignore one of the state changes for each phase.
I don't know if this has changed over the years because the example code assumes a single interrupt trigger and will not work as expected with the current firmware 1.44.2

Just re-read your question.
What are you trying to connect that has "switch data clock"?
That looks like a quadrature encoder which has 2 phases and push button.
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

Re: Rotary encoder hookup

Post by Zim »

Hi
I am just using an example code and left the acronyms the same. All works well now. No bounce to speak of.
Thanks BeanieBots!


Code: [Local Link Removed for Guests]

D1=5:D2=4:D5=14
count = 0
SW = D5
DT = D1
CLK = D2

pin.mode SW, input 
pin.mode DT, input, pullup
pin.mode CLK, input, pullup


interrupt CLK, encoder
interrupt SW, switch

wait

encoder:
if pin(DT) = 1 then return   ' if the pin is high, returns back
if pin(CLK) = pin(DT) then count = count - 1 else count = count + 1
if count <= 0 or count > 10 then let count = 1 'gives a range of 1 - 10
  wlog "count", count

return

switch:
  wlog "switch", pin(SW)
return
BeanieBots
Posts: 315
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 168 times
Been thanked: 102 times

Re: Rotary encoder hookup

Post by BeanieBots »

Glad you got it all working OK.
That nomenclature is 'old-school' from before micros when counters were made using hardware flip-flops.
One phase being "data" and the other phase used to clock the data through.
Although it is possible to do debouncing in code, I personally still prefer to do it in hardware with Rs and Cs.
Good luck with the rest of your project.
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

Re: Rotary encoder hookup

Post by Zim »

Kudos to Dwight for suggesting this encoder!!

Thanks
Zim
Post Reply