I've removed the rotary encoder from the scroll button of a defect mouse. Let's see how we can use that in a microcontroller design.
In post 1, I wired up the electronics.
In part 2, I'm capturing the encoder's info on a Cypress PSoC4.
This time, I'm checking an existing example on an Arduino UNO.
Well, that was easy. I found a number of examples on http://playground.arduino.cc/Main/RotaryEncoders.
I bet the majority of the projects on that page will work. I chose rafbuff's implementation because it was clean code and uses interrupts (several examples on that page do that, but you have to make a choice).
It's less than 100 lines of code, provides additional in-software debouncing and doesn't require an external library.
And it works straight away.
The source is available on http://playground.arduino.cc/Main/RotaryEncoders.
Search for rafbuff.
If you think that I should have tried another implementation, post it in the comments.
Look back at my first post to check how to components are wired up.
Then connect the encoder with the board.
Ground to Ground, 5V to 5V,
PINA to Digital 3, PINB to Digital 2 (that's different than the code comments. My setup counted backwards when I wired it up as written in the code, but I used a different encoder).
Connect the Arduino, execute the program and open the Serial Monitor.
The count is logged to the monitor on every spin.
|Part 1: Electronics|
|Part 2: Capturing Input on Cypress PSoC4|
|Part 3: Capturing Input on an Arduino|
|Part 4: Capturing Input on a Texas Instruments Hercules LaunchPad with eQEP|
|Part 5: Capturing Input on an FPGA|
|Real World Application: Hercules LaunchPad and GaN FETs: Control Big Power with a Flimsy Mouse Scroll Wheel|