I have looked at several Rotary Encoder Video and you are the only one that explains that you need to use the Falling Edge of the CLK Signal to determine the direction of the encoder. Thank You Soooooo Much! You Rock!
Thanks for this video and explanation. The « hesitation » you can see from « falling » trigger mode might be induced by some electrical rebound when contacts are opened/closed. Put a small 10nF between GND and CLK and GND and DT it should solve it :)
Very good educational explaination. I finally understand how it works. I'm currently building a router lift and I will continue to try to connect a Stepper Driver and Stepper motor to make the rotations work correctly with absoule values (together with momentary push buttons) and fine tune the router bit with a rotary encoder in millimeters which would be displayed on a LCD or OLED screen. Thanks for an excellent video.
I found this on Google. "FALLING triggers an interrupt when the signal changes from HIGH to LOW. LOW fires the interrupt for the ENTIRE time the signal remains LOW. So, if your ISR returns while the signal is LOW, the ISR will immediately be called again, after executing only a single instruction back in the foreground task." I think what it is saying is with falling, if you have a bounce issue, it may false trigger, but if you force it to "LOW" then the bounce will be ignored. I believe that is what they are saying. UPDATE: Actually, after reading this and some other stuff a few more times, I think I have it wrong. So I am in the same place as you, not really sure why LOW is working better in this situation.
I think the ISR execution condition of >5ms since last interrupt makes the LOW mode work. This is because when the signal is LOW, the interrupts fires with the clock frequency, which is much faster than 5ms. Therefore, when not turning, ISR is not doing anything despite being fired all the time when the signal pin is low. When the signal pin is high, ISR is not fired anyway, so when rotating and passing from high to low, the >5ms execution time is fulfilled.
The skip in the digital count is probably caused by bouncing. A "debounce" circuit using CMOS 4093 Schmitt trigger ICs is better that having capacitors to ground - of course, this adds a layer of complexity, but it's doable. I am trying to use your Arduino code with a linear encoder (home-built) rather than a rotary switch for my application. Great easy to follow video and super graphics. Thanks.
I think the use of a 4093 for signal debouncing is a great idea, so much, that I just ordered 50 of them. I know that might sound excessive, but when I want to build a project I don't like waiting for parts. I like to get busy right away so I believe in keeping an inventory on hand. I hope you'll have a great day.
Thanks:) Give this video a like then:) Also If you want to see future content like this subscribe and set the neotification not to miss my upcoming videos. There are also ways you can support my channel if you choose to:)
I think you have to check in code if the shaft was turned a full click in the same direction. Example: First CLK goes low (interrupt trig) and DT is still high. When DT goes low you know the specific direction you turn, but first you wait for CLK to go high again and then check for DT to go high. When that happens you change your counter. And vice versa for the other direction. I got this principle to work with help from chatGPT but the code was much more advanced. After implementing this it worked great but it was only an example when I learned about rotary encoders so the extra code did not matter to me.
"I think you have to check in code if the shaft was turned a full click in the same direction." You don't have to, because CLK will only change if the shaft is rotating and DT will show the direction.
@@vinny142 Im sorry, this was an explanation to the jumping numbers you demonstrated on the 7-seg display. I noticed it to when testing the encoder in a sketch and found that if the shaft is moved slightly in the wrong direction this happens. And this happened to me every time I got a new grip of the encoder wheel. Thats why I coded the number to increase only after a full "tick". I suppose there are lots of different ways to get this to work. Thanks for the video!
This has been helpful but in my case I'm trying to use a mouse scroll wheel rotary encoder (which you can get from a computer mouse or buy from amazon). Setting it up in a similar fashion, I can get it to function roughly in the right direction - as I keep scrolling up or down, the counter reliably keeps increasing or decreasing as expected but sometimes it will go in the wrong direction as well. I tried experimenting with different resistors but haven't found a fix. Maybe there's something wrong with my wiring. I'm very new to this.
Once I move the knob on the encoder the output runs so fast I can't read it and keeps running even if I don't turn the knob anymore. Changed Serial.print to Serial.println and it starts a new line now, but the numbers don't change when I turn the encoder knob
I have looked at several Rotary Encoder Video and you are the only one that explains that you need to use the Falling Edge of the CLK Signal to determine the direction of the encoder. Thank You Soooooo Much! You Rock!
x2
Thanks.Means a lot to me. Consider supporting my channel:)
This was the best explanation about Rotary Encoder I have found!
Great to hear!
I agree
Thanks for this video and explanation. The « hesitation » you can see from « falling » trigger mode might be induced by some electrical rebound when contacts are opened/closed. Put a small 10nF between GND and CLK and GND and DT it should solve it :)
This worked beautifully thank you very much :D
bro I genuinely love you
And swap to RISING edge so the capacitor doesn't give you the exact same problem when it slowly discharges by leaking.
Very good educational explaination. I finally understand how it works. I'm currently building a router lift and I will continue to try to connect a Stepper Driver and Stepper motor to make the rotations work correctly with absoule values (together with momentary push buttons) and fine tune the router bit with a rotary encoder in millimeters which would be displayed on a LCD or OLED screen. Thanks for an excellent video.
Great Video...Would never have thought of using that kind of logic between the two pins with one interrupt handler.
I found this on Google. "FALLING triggers an interrupt when the signal changes from HIGH to LOW. LOW fires the interrupt for the ENTIRE time the signal remains LOW. So, if your ISR returns while the signal is LOW, the ISR will immediately be called again, after executing only a single instruction back in the foreground task."
I think what it is saying is with falling, if you have a bounce issue, it may false trigger, but if you force it to "LOW" then the bounce will be ignored. I believe that is what they are saying.
UPDATE: Actually, after reading this and some other stuff a few more times, I think I have it wrong. So I am in the same place as you, not really sure why LOW is working better in this situation.
EXACTLY:) I was digging myself and couldn't find reasonable answer
I think the ISR execution condition of >5ms since last interrupt makes the LOW mode work. This is because when the signal is LOW, the interrupts fires with the clock frequency, which is much faster than 5ms. Therefore, when not turning, ISR is not doing anything despite being fired all the time when the signal pin is low. When the signal pin is high, ISR is not fired anyway, so when rotating and passing from high to low, the >5ms execution time is fulfilled.
exactly what ive been looking for. Thumbs up👍
My pleasure:) like the video and subscribe to my channal. Also consider supporting it.
The skip in the digital count is probably caused by bouncing. A "debounce" circuit using CMOS 4093 Schmitt trigger ICs is better that having capacitors to ground - of course, this adds a layer of complexity, but it's doable. I am trying to use your Arduino code with a linear encoder (home-built) rather than a rotary switch for my application. Great easy to follow video and super graphics. Thanks.
I think the use of a 4093 for signal debouncing is a great idea, so much, that I just ordered 50 of them. I know that might sound excessive, but when I want to build a project I don't like waiting for parts. I like to get busy right away so I believe in keeping an inventory on hand. I hope you'll have a great day.
The best explanation ever.👍
Thanks:) Please give video a like if you enjoyed it
Awesome, nice explanation and great way of displaying the code
good explanation bro. ive found it easy than ever
Thanks:) Give this video a like then:) Also If you want to see future content like this subscribe and set the neotification not to miss my upcoming videos. There are also ways you can support my channel if you choose to:)
Great video, I have a much better understanding of encoders. Looking forward to using in a new project. Thank You!!
Glad the video was helpfull. Consider supporting my channel
finally i understood. a lot of thanks.
very good video. Well explained, good visuals.
I think you have to check in code if the shaft was turned a full click in the same direction. Example: First CLK goes low (interrupt trig) and DT is still high. When DT goes low you know the specific direction you turn, but first you wait for CLK to go high again and then check for DT to go high. When that happens you change your counter. And vice versa for the other direction. I got this principle to work with help from chatGPT but the code was much more advanced. After implementing this it worked great but it was only an example when I learned about rotary encoders so the extra code did not matter to me.
"I think you have to check in code if the shaft was turned a full click in the same direction."
You don't have to, because CLK will only change if the shaft is rotating and DT will show the direction.
@@vinny142 Im sorry, this was an explanation to the jumping numbers you demonstrated on the 7-seg display. I noticed it to when testing the encoder in a sketch and found that if the shaft is moved slightly in the wrong direction this happens. And this happened to me every time I got a new grip of the encoder wheel. Thats why I coded the number to increase only after a full "tick".
I suppose there are lots of different ways to get this to work.
Thanks for the video!
erratic behaviour is coming from contact bouncing. The simplest solution is to add caps to GND.
The LOW setting should not work at all, unless... you simply have the wires hooked up the wrong way round and you're triggering on the DT line.
Good Explanation , Thanks.
This is very informative, thank you so much for the video and explanation
Absolutely perfect explanation ❤❤
Glad you liked it
great explanation, I will try it
Cheers:) consider supporting my channel
This has been helpful but in my case I'm trying to use a mouse scroll wheel rotary encoder (which you can get from a computer mouse or buy from amazon). Setting it up in a similar fashion, I can get it to function roughly in the right direction - as I keep scrolling up or down, the counter reliably keeps increasing or decreasing as expected but sometimes it will go in the wrong direction as well. I tried experimenting with different resistors but haven't found a fix. Maybe there's something wrong with my wiring. I'm very new to this.
Thanks for this video, very helpful !
Thanks. Means a lot. Consider supporting my channel:)
Useful help !
Amazing! This is great help!! :)
Subscribe to the channal if you like this content
Muito bem explicado!!!Parabéns pelo vídeo!
Grandes mentes hein?! :)
Great video❤loved, awesome 🇧🇷😉👏👏👏👏👏👏
Big thanks. Like the video:)
great video
Thank you
Thanks!
Thank you for your contribution:) Means a lot
Nice work
Glad you liked it:)
Thanks
Thank you very much.
What happend if i connect the DT in the CLk, and The Clk in the DT ?
Then turning it clockwise would decrease the number and couterclocwise would increase it. So you would have opposite behaviour
Gold 😂
good
My pleasure:) like the video and subscribe to my channal. Also consider supporting it.
Where is the code sir
This should be now fixed:)
Once I move the knob on the encoder the output runs so fast I can't read it and keeps running even if I don't turn the knob anymore.
Changed Serial.print to Serial.println and it starts a new line now, but the numbers don't change when I turn the encoder knob
Which exact place in the video you are reffering to
@@marios_ideas I'm referring to the code I got from the link
Cd4026 et ne555 one kilo ehz
A word of explanantion?
:)
Excellent video, very didactic.. thanks..
Glad you enjoyed it!