Read a high resolution encoder


I am attempting to use an ArduinoMega to read from two high resolution encoders. Each encoder has 15 wires, so produces a 15 bit number at each position. I can alternate the reading of the two of them.

I cannot find a way to read all 15 pins at the same time, or one after the other, but produce a single number at the end. Any suggestions?

This will then be manipulated to the angle required, and output to a display (but I will get to that part, I hope). I am very new to this, so any help would be much appreciated. :)


I would use a MCP23S17 port expander chip to give you 16 I/O pins. This connects to SPI and is quick to read. It also contains an output flag that changes when ever any input changes that way you don't need to be constantly reading the chip to see if anything has changed.

The other alternative is to use shift registers.

I think from the way you phrased your question that YOU understand the following, but for others learning from this tread:

It is important to realize with things like this that there is no (correct me if I’m wrong!!) QUICK, EASY way to read even 8 input bits all at once. You read the first, the second, the third… and so on with digitalRead… with a slight delay between reads. And a word of data on those pins may be changing during the "slight delay"s.

Now this isn’t always a problem… but it can be, might well be in the case this thread is about. Hence Grumpy Mike’s suggestion, the “answer” I would use. But the above is, I hope, a helpful expansion of why it is The Right Way To Go… for this.

(15 bit rotary encoders?? Cool!)

The mega has lots of I/O pins, so you can certainly read 15 bits one at a time and then with code convert it to a single variable. You can also, using direct port access, read two 8 bit ports in two operations and then assemble them into a single variable. It really all comes down to how fast the encoder is moving as to if you can read it without missing data changes. Do you have any idea what the maximum is of how fast your encode will be turning in RPMs or steps per second?