Тёмный

E003 Using Rotary Encoder Switches on the Raspberry Pi 

Making Stuff with Chris DeHut
Подписаться 11 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

22 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@dykrock
@dykrock 8 месяцев назад
Actually, I tried this out on a Raspberry Pi Zero 2W. Worked out of the box. Thanks for this tutorial.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 8 месяцев назад
Awesome! very glad to hear it helped you. Cheers! Chris
@HanD_1964
@HanD_1964 Год назад
Thx Chris! This information helps a lot!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Happy to help! Cheers Chris
@mojibake7868
@mojibake7868 Год назад
Thanks! I'm a total beginner and couldn't get my encoder with click to work. I've added some 10K ohm resistors and using your code example it works!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Awesome! Glad you got it working. Cheers! Chris
@rfresh1011
@rfresh1011 3 года назад
Hi Chris, great, detailed video!! Question: can we put the encoder knob turning into an interrupt (event) as well instead of using polling?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
I don't see why not, so I would assume so! Once I get caught back up on some projects, I will try to revisit that video with a follow up.
@Testing-sx7gv
@Testing-sx7gv 3 года назад
Excellent introduction!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
Thank you for the kind words, much appreciated!
@jpdenat1
@jpdenat1 2 года назад
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 !
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 2 года назад
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!
@roberttrottini9660
@roberttrottini9660 3 года назад
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?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
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
@roberttrottini9660
@roberttrottini9660 3 года назад
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.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
@@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
@roberttrottini9660
@roberttrottini9660 3 года назад
Thanks again. I figured it out and did exactly that. Works great. Once again, great tutorial. Was extremely helpful.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
@@roberttrottini9660 Outstanding! Glad it all worked out for you!
@ankurbhatnagar4609
@ankurbhatnagar4609 Год назад
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?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
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
@ankurbhatnagar4609
@ankurbhatnagar4609 Год назад
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?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
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
@cwaidelich1
@cwaidelich1 3 года назад
Do you know how to limit the encoder? For example, I want the values to be within 0 - 360. Would you know how to keep the values between 0 - 360?
@mojibake7868
@mojibake7868 Год назад
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
@tzabbi
@tzabbi 3 года назад
Hey such a nice video! It help me a lot. I can't see the link to the source code.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
Very sorry for that! I will check and see if I can find the source code from that video an post it. Unfortunately, I don't think I still have it.
@tzabbi
@tzabbi 3 года назад
@@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.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
@@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.
@tzabbi
@tzabbi 3 года назад
@@MakingStuffwithChrisDeHut Ok thanks for the tip!
@alheeley
@alheeley 3 года назад
Can this be installed and run within Win10 environment? I have no idea about installing libraries or why I would need to ?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
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.
@alheeley
@alheeley 3 года назад
@@MakingStuffwithChrisDeHut I think that means linux os, not win10.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 года назад
@@alheeley Correct.
Далее
How to use a Rotary Encoder in CircuitPython No. 4
23:48
Cool Wrap! My Book is OUT 🥳
00:27
Просмотров 930 тыс.
Using Rotary Encoders with Arduino
32:10
Просмотров 714 тыс.
How to use rotary encoders
14:12
Просмотров 38 тыс.
Raspberry Pi Pico: Inputs & Servo Control
17:20
Просмотров 133 тыс.
How To Use A Rotary Encoder With Raspberry Pi Pico
9:59
Getting Started with LIDAR
47:27
Просмотров 1,4 млн