Hello Chris ! Great video ... I am wondering what types of encoders are used in modern stereo ( like in cars ) ... where the knob turns inderfinitely to the right and the left ( over 360 degres ) and also have push on switch function ... Wondering if you can help ! Many Thanks !
Search for "rotary encoder Switch" on Amazon and the first item to show up would be exactly what you describe. These are what are used in in car radios. Thanks and Cheers!
Great video. I have an issue though that you may be able to help with. I have my connections exactly as you have them - minus the resistors. When I turn the encoder knob it seems to short out the Pi for some reason. Could it be a faulty encoder?
Thank you! The resistors serve a very important purpose in that they prevent too much current going into the input, without those resistors, you could fry the RPi. Also, if it is shorting out the RPi, my guess is that the pin-out for your encoder switch could be different than the one I used. Try to find a datasheet for the encoder and make sure the pin out is the same as the one I used. Also, make certain of which pins you are connecting to on the RPI and that they are configured as inputs etc. That is about all I can guess at based on what the information provided. Chris
Thanks very much. Turns out the pins I had it connected to weren’t configured correctly. One additional question... Is there a way to reset the counter to 0 each time the encoder steps one click? I’d like to just capture one click clockwise or anti clockwise at a time.
@@roberttrottini9660 The library doesn't have that ability, however, you could add your own counter to handle that by comparing a previous read against a new read and then incrementing your counter up or down by one (or more). Chris
Thank you for referring me to this video, Chris (your reply to my comment under RPi PICO encoder video). The instructions here work for me on my Raspberry Pi 4B. This is great! However, I see that it works for only very slow speeds of rotation. I have a shaft encoder and it generates a value of 2400 (Encoder.read()) in one rotation in your code when I rotate it very slowly. In my use case I expect the maximum rotation speed of about 15 rotations per second (900 rpm). Apparently the Pi is not able to handle interrupts at that kind of speed (15 x 2400/4 = 9,000 per second). Would you have any suggestions how can I get the Pi and the code to work accurately for such speeds? This encoder is specified to be able to work up to 3000 rpm (50 rotations per second). I don't know how people handle that interrupt speed! (50 x 2400/4 = 30,000 per second) Basically, I am trying to build an odometer and a speedometer for a trolley that will run up to around 25 km/hour. Would you recommend some other approach for this purpose?
Hi @ankurbhatnagar4609, Unfortunately, Raspberry Pi, using an actual Operating System, doesn't lend itself well for this sort of thing. That is not to say it is impossible. Try searching for a Python library for Quadrature Encoders. Someone probably has written something in C++ and has made it accessible from Python via a library. I have not gone down that rabbit hole yet with the Raspberry Pi. Chris
Thank you @@MakingStuffwithChrisDeHut for your reply. In your other code, meant for rotary encoders for Raspberry Pico, I noticed your comment there that, that code running on Pico can handle interrupts up to 1,000 per second. Have you verified that number? I was thinking that if I use a 100 PPR encoder in place of 600 PPR, my maximum interrupt rate could drop to around 900 per second. If Pico can really handle 1,000 per second, I guess Raspberry Pi 4B (2 MB RAM) to should be able to handle 1,000 per second. What do you think?
Hi@@ankurbhatnagar4609 To get an idea how fast the PICO is while still being pretty accurate, this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-g4_ZpVmTi9g.html is explaining how a photoreflective sensor can be used to measure pretty high speeds - well within the range you are talking about. Chris
You can either clamp the values between 0-360 using Python, or start from zero when you've reached 360 using modulo. clamp: value = max(0, min(x, 360)) modulo: value = x % 360
@@MakingStuffwithChrisDeHut Thanks for the answer. I got the code. I just have a problem. The function tuner_push_button is triggered the hole time. But I don't press the encoder. Do you know why? I got a rotary encoder on a board with restistors installed.
@@tzabbiI would check with a multimeter to see if the switch is working on the encoder. I would then check to see if it is wired correctly, not all encoders have identical pinouts.
Hi Al, unfortunately I do not know that answer - I would ask that on the Raspberry Pi forum to see if someone there has the answer. I have only used the Raspberry Pi with Raspian OS.