how to read a rotary encoder?

Is there any usable documentation about how to interface with a rotary encoder? There are some sources floating around the web on how to do it in PICAssembler... http://www.cc5x.de/files/Verschiedenes/Encoder.htm but has anyone (please) done a library for the arduino yet, perhaps?
(that would be so great)

max

Max,

I can think of two kinds of rotary encoders. One that produces two square wave signals that are offset by 90º. This gives you a timing of the rotary motion ( how fast the pulses come in are indicative of the speed) And the direction that rotary motion is traveling in. The direction is determined by which of the waves is leading the other.

This is of the type that the old Mice with the ball in it use. For a more concise discription of this, go to the website

In this page, it has a link to another that explains the direction portion.

The other is a discreet position encoder. This will use a pattern printed or screened onto a clear plastic disc. Probably in a binary progression pattern. This type of encoder will tell you exactly where it is in it's rotation by reading said bit pattern. The more bits used the higher resolution you will get. 8 bits will give you 256 postions or ~ 1.4º per.

For this, you will need as many i/o lines as bits of resolution you have.

Admitedly, it has been quite some time since I have seen the latter type. For the most part, if you need discreet positioning, I think stepper motors are used. Though, they may be used in a motor that has an optically encoded shaft.

Hope this helps.

ñ

there is an "Encoder.h" under lib/targets/wiring, which seems like it should be pretty close, and in lib/avrlib there is "encoder.h" and "encoder.c" ,which have some interesting comments, so there is no reason to start from scratch! If I get it to work, I'll tell you all about it!

YAY. I solved it. I'm so proud of myself!

wrote it down here. It doesn't use any interrupts, so consider this a suboptimal solution, but it works for me:

http://www.arduino.cc/playground/Main/RotaryEncoders

excellent tutorial :slight_smile:

he max

just had a look at your code...
why are the pins set to output....this can't be right

chris