I have written a program that is supposed to print out the position of my encoder;However, I am only getting zeros in my serial monitor. I want to be able to use interrupts. I would like to actually return the position in degrees of my encoder as we rotate it.
Could anyone of you tell me the difference between CHANGE AND RISING? my original code had change because I thought if a detect a change in both channels I can interrupt. However I just changed it to RISING and seems to input more "accurate" number. It is still missing some pulses if I go to fast.
Since my encoder is 256 cpr I should get (input in the serial monitor) in one rotation 256 right?
I feel like since I don't have a clear understanding of encoders my code is not efficient.
I hope you can help me guys! thanks
I feel like since I don't have a clear understanding of encoders
Read it again.
Could anyone of you tell me the difference between CHANGE AND RISING?
A RISING interrupt will be triggered by an input going from LOW to HIGH
A CHANGE interrupt will be triggered by both a RISING or FALLING (input going from HIGH to LOW) signal.
I suggest you look at this tutorial on interrupts. You should not use Serial printing within an ISR, and you should understand how to transfer "protected" data from an interrupt variable to the main program without risk of the value changing.
Try some sample code you find for your encoder. Get it to work. If it doesn't work, your circuit is wrong. If it works, edit the sample code in small steps that work, until you get to what you want.
I get it to work forward and not backward. I added a print statement to see if I am hitting my else in my isr_2 , it does print but it never decrements my counter. Not sure why.
Quick question for this great community. I was able to read the position of my encoder and converted that position to an angle. However when I rotate the encoder right it gives me a negative output and when I rotate it left it gives me a positive output. It is backwards, I checked my Code and I can't find the issue.
Output rotating right starting from zero:
-1
-2
-4
-5
-7
-8
-9
-11
Output rotating right starting from zero:
0
1
2
4
5
7
8
9
11