There are a bewildering number of examples, libraries, and opinions about how to write routines to read values from a rotary encoder. I found one that that looked particularly elegant and easy to generalize, so adapted it to the Atmega328 that I’m using for my current project. I used a pretty popular rotary encoder, Adafruit #377, although I think the demo code would work with other quadrature encoders.
Most of the work in done in a relatively light interrupt service routine that receives information from both directional pins on the rotary encoder. I did not do any addition software or hardware debouncing and I didn’t notice any jitter or erratic behavior.
With wintertime (and remember, it is winter where I am) comes soldering – I can spend more than ten minutes in the garage without being drenched in sweat. I have a three week travel break before going on summer leave, so I’m trying to wrap up various projects. I have one project breadboarded and wired up to my arduino duemilanove, but I needed another arduino to work on another project in parallel, so I built one up on perf board: the Antananarivoduino.
The Antananrivoduino is about a simple as I could make it: an ATmega328, 16Mhz crystal oscillator, and 5V power. The one frill I added was a 28-pin ZIF socket that I’ve had kicking around for a couple years. The socket lets me seat a chip, program it, and eject it. It’s ideal for cranking out copies of a project or a burning a final chip that will go into an embedded project and won’t need any more programming.