Notifications
Clear all

KY-040 Rotary Encoder Alternatives  


Chrissy
(@chrissy)
New Member
Joined: 1 year ago
Posts: 3
Topic starter  

Was looking at projects making use of the KY-040 encoder as well as it's electrical schematic, both of which raised a couple of questions with me.

Basically the KY-040 is just a regular/common Gray code encoder with a couple of 10K pull-ups fed by the Vcc pin. 

Given that, I assume there is no reason a common (non-powered) encoder with external pull-up resistors would be a viable alternative.

However, this also begs the question of why not simply forgo the external pull-ups and/or the KY-040 completely and simply configure the clock and data pins using Input_Pullup and use a common (non-powered) encoder?

Am I missing something here, something "between the lines" that I am not intuiting?

This topic was modified 1 year ago by Chrissy

Quote
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 2 years ago
Posts: 1855
 
Posted by: @chrissy

However, this also begs the question of why not simply forgo the external pull-ups and/or the KY-040 completely and simply configure the clock and data pins using Input_Pullup and use a common (non-powered) encoder?

That's what breadboards are for.   Just wire up the circuit you are proposing and see if it works as you expect.  There's often more than one way to do things.  Let us know what  you discover.  We'd love to hear the results.

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Chrissy
(@chrissy)
New Member
Joined: 1 year ago
Posts: 3
Topic starter  

@robo-pi

An excellent idea!  :p

Interesting enough, once I stopped shooting myself in the foot (more on that in a bit), I found that setting the clock and data pins to internal pullup, the code worked perfectly .

Initially, I was using a non-powered encoder mounted to a PCB which I had laid out a couple of years ago, which included bypass capacitors (100nf) on the clock and data pins.  This was done to minimize bouncing when using an interrupt based encoder library I had used on another project.  When I used that encoder with your example code (modified to enable the internal pullups), the results were all over the place. 

My initial reaction was that the encoder was defective.  However, as I thought about why I had originally used the capacitors, I considered the possibility that they might be the real issue.

So, I "killed two birds with one stone", grabbed a new (identical model) encoder and wired it into the circuit (without the bypass capacitors).

As noted above , it worked perfectly!

It is, as I suspected it would be, identical in functionality as the KY-040.  Indeed, I just could not fathom how it could have had any other result, given the basic circuitry. However, as I stated in my original post, I could not help but wonder if there was perhaps something I was overlooking.  When I see others doing things the same way, it makes me wonder if there is a reason, hence the question.

🙂


ReplyQuote