ROTARY ENCODER WITH INTERRUPTS - Arduino tutorial #12

  Рет қаралды 58,377

Bas on Tech

Bas on Tech

Күн бұрын

Пікірлер: 92
@BasonTech
@BasonTech 4 жыл бұрын
👉 Don't forget to check arduino-tutorials.net for more Arduino tutorials and projects. If you have questions, don't hesitate to ask them in de comments. Remember: There are no stupid questions 😃
@basvanvliet1970
@basvanvliet1970 4 жыл бұрын
Makker, ONZE NAAM
@BasonTechNL
@BasonTechNL 4 жыл бұрын
@@basvanvliet1970 😎
@sontayasaengtaw4908
@sontayasaengtaw4908 2 жыл бұрын
You can write coad convert to angle +/- ?
@naboulsikhalid7763
@naboulsikhalid7763 2 жыл бұрын
that explains all the things I wanted to know and settles down all the dust that cloud my understanding of rotary encoder. Great tutorial. thank you very much
@BasonTech
@BasonTech 2 жыл бұрын
Thank you! 😃
@allanminers1662
@allanminers1662 3 жыл бұрын
Best ever explanation of how a rotary encoder works.Two little dots fit it
@BasonTech
@BasonTech 3 жыл бұрын
Thanks! 😃
@MikeysLab
@MikeysLab 4 жыл бұрын
You should handle the denouncing in hardware, not software. Adding a couple resistors, a cap and a 74hc14 will give you a nice clean signal.
@BasonTech
@BasonTech 4 жыл бұрын
Thanks for sharing! 😃
@longdongsilver4719
@longdongsilver4719 3 жыл бұрын
I suppose you are kidding...
@MikeysLab
@MikeysLab 3 жыл бұрын
@@longdongsilver4719 not at all, bouncing is a hardware problem. Always solve the problem where the problem is. Pushing it off to software is just lazy engineering
@longdongsilver4719
@longdongsilver4719 3 жыл бұрын
@@MikeysLab The right solution is the simplest one. Adding some debouncing circuitry is just over-engeneering when it comes to a simple rotary encoder. Adding active or even passive components increase the risk of failure and the cost. Lazyness is not a criteria in engeneering but efficiency, production cost and MTBF are the real way to think your design.
@MikeysLab
@MikeysLab 3 жыл бұрын
@@longdongsilver4719 okay let's look at the "efficency" of your idea, on one hand we save about 7 cents per encoder. On the other we have to pay an embedded software engineer to write a complicated debounce function that will not use delays or hinder main program execution in anyway, or use a multi core micro controller and dedicate a thread to the ui alone, which as a embedded software engineer is going to take about 16 hours to design implement and effectively test before it should be released in a product. Factor in I charge $200/hr for dev time and your 7 cent savings just cost you a whole hell of a lot of money. The easiest solution is not always the right solution. This is what makes people use strings over char[] in Arduino and get into trouble with memory fragmentation
@Sparklift
@Sparklift 4 жыл бұрын
Great video. Clear instructions. Please do more and more videos
@BasonTech
@BasonTech 4 жыл бұрын
Thanks, will do! 😃
@soonfamous
@soonfamous 7 ай бұрын
Great video Bas :) i bumped into your channel and I immediately got hooked on the quality of your explanation! I did follow the tutorial with ease. Unfortunately my rotary encoder is still giving me false values (even when I try to move it slowly). I am thinking to apply some filter on the raw values (avg of 3) perhaps? Any pro advice on how manufacturers usually solve problems like that?
@BasonTech
@BasonTech 7 ай бұрын
I think averaging is not the way to go tbh. I am more wondering if the rotary encoder is malfunctioning or that some wiring is causing this issue. Have you tried with another rotary encoder?
@mrcanisters
@mrcanisters 2 жыл бұрын
thanks. just what was after. very well explained.
@BasonTech
@BasonTech 2 жыл бұрын
Great to hear, thanks! 😃
@stevenirish6160
@stevenirish6160 5 жыл бұрын
Thank you!
@tonholper6282
@tonholper6282 2 жыл бұрын
Hi Bas, wich Rotary encoder are u using, it has a pushfunction wich i need
@BasonTech
@BasonTech 2 жыл бұрын
Hi, in the description of every video is a list with all the components. Here you find links to Dutch and international stores.
@jaimeriquelme6727
@jaimeriquelme6727 3 жыл бұрын
Hi Bas on tech, how did you verify this program when ' digitalPinToInterrupt' was not declare in this scope, help me please to understand. Thanks for your time.
@BasonTech
@BasonTech 3 жыл бұрын
Hi Jaime, please make sure you have no typos in the naming of digitalPinToInterrupt and see if all the { and } are opening and closing at the correct place.
@jaimeriquelme6727
@jaimeriquelme6727 3 жыл бұрын
@@BasonTech, I've already checked many times, but I'm not the only one with this problem, someone said reinstall the IDE program and try again but it didn't work. Any other suggestion, I'm using an old Dell laptop with Windows XP. Thanks a lot for your patience.
@BasonTech
@BasonTech 3 жыл бұрын
@@jaimeriquelme6727 Did you copy my source code from the course material to make sure there aren't any typos?
3 жыл бұрын
I´ve tested it on other pins that arent 3 and 4 and it doesnt work, why does this happend? Before you ask, I´ve changed the code so that the pins are different. If there is something misssing please let me know!
@BasonTech
@BasonTech 3 жыл бұрын
Hi Elías, very good question! In the code you see we attach an interrupt to pinB. As www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ shows, for most Arduinos only pin 2 and 3 have external interrupts. So therefore you can only use these pins 😃
3 жыл бұрын
@@BasonTech Thank you soo much for answering this fast!! This means we could only use this method for 2 simultaneous digital encoders??
3 жыл бұрын
@@BasonTech Well I've seen that my arduino Leonardo has more than 2 pins with external interrupts. Thats means I only need one for each digital encoder? Thank you again and hope to see something from you soon!
@BasonTech
@BasonTech 3 жыл бұрын
Indeed 1 interrupt pin for 1 encoder. However there might be some PCB out there which can multiplex multiple encoders on a single pin
@longdongsilver4719
@longdongsilver4719 3 жыл бұрын
Thanks for your help. This video kept me surely from searching for the solution during hours. I was using the polling method to read my encoders and it was far from satisfying. I had lots of misreads and the reliablilty depended too much on the encoder quality. Interrupts was the way to go. BTW, your english pronunciation is perfect ;-)
@BasonTech
@BasonTech 3 жыл бұрын
Glad it helped and thanks! 😄
@_twich_8096
@_twich_8096 3 жыл бұрын
lets say i want to connect 2 encoder, i assume is possible to contec the pinA to arduino pin2 and 10 and the other encoder pinA to arduino pin3 and 11. i assume thinks will work the same way. of course by doublening the code, with deferent pins and names, will this work?
@BasonTech
@BasonTech 3 жыл бұрын
Correct, however it is better to not repeat code but split it up in reusable functions 😃
@ipadize
@ipadize 2 жыл бұрын
i have first added the encoder without interrupts- which worked semi okay (its not reading fast enough), so i added the interrupt. Now when i turn the encoder my whole program will stop. I call a switch case with the interrupt and the switch case calls another switch case inside, maybe using an interrupt is forbidden with nested switch cases?
@BasonTech
@BasonTech 2 жыл бұрын
I know that the code within the interrupt needs to be as small as possible. A switch adds logic so perhaps you are right and is it not advised to do so.
@ipadize
@ipadize 2 жыл бұрын
@@BasonTech i have changed my code to only use buttons - short press once and long press continuously change a value (i still have to add that long press tho).
@EricEllenbrook
@EricEllenbrook 4 жыл бұрын
Theoretically could you assign a count to the encoder so when you turn to the left it decreases and to the right it increases? And could you display that value on the LCD screen?
@BasonTech
@BasonTech 4 жыл бұрын
Hi Eric, that is not only theoretically but also practically possible 😃
@EricEllenbrook
@EricEllenbrook 4 жыл бұрын
@@BasonTech im new to arduino and this video gave me the inspiration I needed to get started! I hope to share a video with you one day :)
@BasonTech
@BasonTech 4 жыл бұрын
Hi Eric, if you're new to Arduino, I would really recommend to start with tutorial #1. You'll learn a lot of basics in the first few tutorials. Looking forward for your video! Use the hashtag #basontech 😃
@dreamseer2007
@dreamseer2007 3 жыл бұрын
I loved your video, but when implementing the interrupt, I am now getting left on left and mostly left on right. Before implementing the interrupt each direction is mostly correct.
@BasonTech
@BasonTech 3 жыл бұрын
Hi, make sure you have wires connected correctly. Sometimes the encoder is damaged and "slips" resulting in wrong output
@dreamseer2007
@dreamseer2007 3 жыл бұрын
@@BasonTech Thank you! I changed the encoder and the new one works perfectly. 🙂
@BasonTech
@BasonTech 3 жыл бұрын
Great! A disadvantage of rotary encoders is that they wear over time and start slipping
@AnakRantauan_NL-Industry
@AnakRantauan_NL-Industry 4 жыл бұрын
If led brightness control with two leds. How to code ?
@BasonTech
@BasonTech 4 жыл бұрын
Hi Anak, I am not sure what you want to achieve. Do you want to control the led brightness? You can use PWM for that. It is explained in this tutorial kzbin.info/www/bejne/Z5fLg5ljZberr7M
@unalakdogan9416
@unalakdogan9416 3 жыл бұрын
Perfect
@BasonTech
@BasonTech 3 жыл бұрын
Thanks! 😃
@mihalceaalexandru9114
@mihalceaalexandru9114 2 жыл бұрын
Where are interrupts used?!
@BasonTech
@BasonTech 2 жыл бұрын
at 9:32
@Leviathan0707
@Leviathan0707 2 жыл бұрын
my encoder bounce all the time and it is driving me crazy, how do you make it not bounce
@BasonTech
@BasonTech 2 жыл бұрын
Maybe there is a malfunction in the rotary encoder? Have you tried another one?
@Leviathan0707
@Leviathan0707 2 жыл бұрын
@@BasonTech I try all of it mate. From the rotary encoder with breakout board to the stand alone one, they all bounce the same way to me :((( it's pretty frustrating
@BasonTech
@BasonTech 2 жыл бұрын
If that is the case, it should be either your wiring, or your code. Please check the pin layout of your encoder to be absolutely sure the pins are not labeled different than mine in the video
@Leviathan0707
@Leviathan0707 2 жыл бұрын
@@BasonTech i double check everything for an entire month, I search on youtube a found that many people have the same problem as me. But it seems like you don't encounter such problem at all
@BasonTech
@BasonTech 2 жыл бұрын
Indeed not at all, it just worked. Are you using the Arduino Uno as well?
@djproducerty88
@djproducerty88 6 жыл бұрын
Kan je een video maaken over RBG led
@BasonTechNL
@BasonTechNL 6 жыл бұрын
Bedoel je RGB led met vier pootjes of de WS2812B adresseerbare LED strips?
@djproducerty88
@djproducerty88 6 жыл бұрын
Met vier potjes
@BasonTechNL
@BasonTechNL 6 жыл бұрын
@@djproducerty88 Die werkt precies hetzelfde als een gewone LED :) Een RGB led is eigenlijk een 3 in 1 LED. Je kunt hem dus aansluiten als een gewone LED. Afhankelijk van welk pootje je kiest wordt hij rood, groen of blauw zie sites.google.com/site/ardunitydoc/_/rsrc/1453009974510/getting-started/run-examples/rgb-led/RGB_LEDCircuit%28Analog%29.png
@djproducerty88
@djproducerty88 6 жыл бұрын
@@BasonTechNL maar je moet tog resistors gebruiken?
@BasonTechNL
@BasonTechNL 6 жыл бұрын
@@djproducerty88 Klopt, dat kan op precies dezelfde manier als in het plaatje. Over elke korte pin zet je een weerstand :)
@darrenmurrey637
@darrenmurrey637 Жыл бұрын
that annoying that there are only two interrupts . i want to run two encoders and just realised why 1 is having difficulties
@BasonTech
@BasonTech Жыл бұрын
I believe the Arduino Mega has more interrupts.
@shokdj1
@shokdj1 Жыл бұрын
Cheers mate I appreciate your info I may buy a few mega’s. Turns out there’s another way I found something a library that give you interrupts on any pin. There a catch it stops interrupts on everything but it doesn’t matter on my project as you’ll only use 1 thing at a time so it’s working pretty decent now. Although I’m trying to work on an optical rotary encoder and 3d printing the rotary ir blocker there’s just not enough ticks per rotation on a general encoder for what I need it for.
@startobytes
@startobytes 5 жыл бұрын
Can you make more videos please
@BasonTech
@BasonTech 5 жыл бұрын
I would really like to. Unfortunately I currently have quite a busy job, which makes it very hard to record new videos. When times are less rural I will certainly record new videos :)
@startobytes
@startobytes 5 жыл бұрын
@@BasonTech than can make the videos on the weekend, Not?
@startobytes
@startobytes 5 жыл бұрын
Can you make 1 Video per week? I Hope you can make it.
@BasonTech
@BasonTech 5 жыл бұрын
@@startobytes Unfortunately that is not going to work. Keep in mind that creating a video requires preparation, recording, editing, writing the code, artwork and updating the website. Topic getting more complicated as well, and therefore preparation will take more and more time before I can start recording :)
@startobytes
@startobytes 5 жыл бұрын
@@BasonTech thanks,
@محمددرارني-ف7ن
@محمددرارني-ف7ن 5 жыл бұрын
Teach us!
@BasonTech
@BasonTech 5 жыл бұрын
I will, don't worry. Unfortunately this is quite a busy time for me. I borrow the camera from a friend, so I am not always able to record new episodes. However, I have certainly plans to make new episodes this year :)
@muratcanbarut64
@muratcanbarut64 5 жыл бұрын
süperb
How to use rotary encoders
14:12
FriendlyWire
Рет қаралды 43 М.
#96 Rotary Encoder Update - Stepless & Software Debounced
37:46
Ralph S Bacon
Рет қаралды 41 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 75 МЛН
Menu with voice & rotary encoder - Arduino
15:01
Electronoobs
Рет қаралды 103 М.
Using Rotary Encoders with Arduino
32:10
DroneBot Workshop
Рет қаралды 722 М.
How to Use Arduino Interrupts The Easy Way
33:28
Rachel De Barros
Рет қаралды 93 М.
How to use a Rotary Encoder with an Arduino - CODE EXPLAINED!
21:11
I tried the Cheapest Arduino Alternative (that Nobody heard of)
13:31
How to use Rotary Encoder with Arduino
14:44
Mario's Ideas
Рет қаралды 48 М.
Stepper Motors with Arduino - Controlling Bipolar & Unipolar stepper motors
50:22
Уроки Arduino. Работа с энкодером
10:55
Заметки Ардуинщика
Рет қаралды 187 М.
This is the code that sent Apollo 11 to the moon (and it’s awesome)
19:09
Best code to use with a KY-040 Rotary Encoder? Let's find out!
9:13
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 75 МЛН