8 Bit Rotary Encoder

Hello,

I have this rotary encoder that I am trying to hookup to my arduino. Here is the datasheet. http://www.farnell.com/datasheets/1856387.pdf
I have been looking around the internet and can’t find any useful information about it, most of the rotary encoders are two bit.
Could anybody help me with connect this up to the arduino and programming it. I would like to display the position on the serial monitor.

This encoder is not like the incremental encoders which have the two bit output and you are headed down a more complex path here with several decisions to make.

1) Do you want to directly read all the 8 pins of the encoder or do you want to use an 8 bit i2c port expander like the MCP23008?

2) What Arduino do you have or want to use? Anything other than the Mega, and I think you will be better with the i/0 expander route. I actually think it would be interesting to use the Mega, put all the 8 pins of the encoder on the arduino pins of PortK or PortB which have pin change interrupts on all 8 pins

2) Whichever route you go, you will have to know if a bit changes. You can do it with polling or interrupts. The port expander should have an interrupt output when a bit changes.

3) You will read the bit pattern and then compare it with a look up table of the 127 numerical values shown in the data sheet and their associated position. Since you can only move to an adjacent position, I think is should be possible to reduce the search to one position up or down from the current position.

4)How do you plan to use this encoder, and fast do you need to read it?

There is a library here which is written for a port expander which may give you some ideas.

http://redhunter.com/blog/2013/03/01/absolute_128_position_encoder_for_arduino/

Unless you need Auduino pins for other peripherals, simply connect the 8 outputs from the encoder to Arduino inputs.

You don't need the 8 resistors shown on the datasheet: use pinMode(INPUT_PULLUP).

Use a byte array for the table.

What a strange encoder!

They obviously use some sort of Gray code (only 1 bit changes per rotational increment), but why 8 bits for 128 values?

Gray codes were originally invented in the days of mechanical switches so that, even if there was some switch bounce, you never got a code that was more than +/- 1 position from the correct value.

These days they are used for error correction- if you find 2 bits have changed you know its not a real reading. The extra bit is the price of the error-correction function- think of it like a parity bit in serial codes.

rw950431: These days they are used for error correction- if you find 2 bits have changed you know its not a real reading. The extra bit is the price of the error-correction function- think of it like a parity bit in serial codes.

The extra bit is not for error correction; it's how the maths works out.

See: https://en.wikipedia.org/wiki/Gray_code#Single-track_Gray_code

OK thanks guys. I am a little unsure what the c pins do. Do I have to connect one of them to 5v and one of them to GND?

thomfur: OK thanks guys. I am a little unsure what the c pins do. Do I have to connect one of them to 5v and one of them to GND?

If you have just one of these encoders, connect one of the two common (C) pins to ground. Leave the other C pin open circuit; do NOT connect it to 5V.

If you have more than one encoder you can use the C pins of each encoder to select which one you want to read at any time.