Rotary incremental encoders / switches

Is there either a hardware module or software library that couples with rotary encoders? To make it easier to connect to the Arduino and spend less time checking digital pins and trying to sense what happened? I understand that a library would also tie down MCU resources just like user code would.

akis_t:
Is there either a hardware module or software library that couples with rotary encoders? To make it easier to connect to the Arduino and spend less time checking digital pins and trying to sense what happened? I understand that a library would also tie down MCU resources just like user code would.

That would be overkill, they are very simple to implement.

I should have quialified why I said that:


I read from the online help on the "attachInterrupt()":

"If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred."


In my estimation you'd need to be polling every 2-5ms and then have to deal with bounces, invalid sequences and so on. Not impossible, but tedious and hogging down the MCU IMO.

akis_t:
I should have quialified why I said that:


I read from the online help on the "attachInterrupt()":

"If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred."


In my estimation you'd need to be polling every 2-5ms and then have to deal with bounces, invalid sequences and so on. Not impossible, but tedious and hogging down the MCU IMO.

The truth of that statement really depends on the nature of your encoder implementation. There are only so many interrupts available so it's not practical to rely on interrupts if you have a large number of encoders. Also, if your encoder is not expected to move very fast, polling is fine.

Even if you choose to use an interrupt, this doesn't automatically need a library.

You might find this thread, where I have a simple sketch that reads an encoder without interrupts. I've never tested it "at speed" (whatever that means...) so I have no idea when it falls down in collecting all the signals, but it shows some principles.

YMMV....