Reading a Bourns Magnetic rotary encoder EMS22A50-D28-LT6

Hi, I am trying to read the values from this absolute encoder and would appreciate some help...I do electronics as hobby and got the basics, but I am having some trouble understanding how to connect the pins of the device to Arduino and how to code it to read the values. Sorry, I know it is a lot to ask, but I would really appreciate the help so I can move forward.
Datasheet for the device says (
Pin 1 = Digital input
Pin 2 = Clock
Pin 3 = Ground
Pin 4 = Digital output
Pin 5 = Vcc
Pin 6 = CS

From previous posts I see that clock and data are assigned, but the way they are called in the datasheet and how the would correspond to "data" and "clock" is what is confusing me. Also, not sure what Digital Output and CS would be for...?

This seems to be SPI interface.

Digital Input    = MOSI
Clock            = SCK
Ground           = GND
Digital Output   = MISO
Vcc              = VCC +3,3V .. +5V

Thank you, I didn't even know about SPI communications. I am reading documentation about it now...much appreciated

There is an excellent reference here

Here's some simple code which shows how to clock out the bits with digitalWrite() on the clock pin.

const int PIN_CS = 5;
const int PIN_CLOCK = 6;
const int PIN_DATA = 7;

int zeroCross = 0;
int pos;
int oldPos = 0;
byte bitStream[16] = {0};

void setup() {

  pinMode(PIN_CS, OUTPUT);
  pinMode(PIN_DATA, INPUT);

  digitalWrite(PIN_CLOCK, HIGH);
  digitalWrite(PIN_CS, LOW);

void loop() {
  digitalWrite(PIN_CS, HIGH);
  digitalWrite(PIN_CS, LOW);

  bitStream[16] = {0};
  for (int i = 0; i < 16; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);

    bitStream[i] = digitalRead(PIN_DATA);

  digitalWrite(PIN_CLOCK, LOW);
  digitalWrite(PIN_CLOCK, HIGH);

  oldPos = pos;
  //extract 10 bit position from bitStream
  pos = 0; //clear previous data
  for (int i = 0; i < 10; i++) {
    pos = pos << 1;
    pos += bitStream[i];    

  if(oldPos > 1021 && pos < 3) zeroCross++;
  if(oldPos < 3 && pos > 1021) zeroCross--;

  //print position 0-1023
  Serial.print(pos, BIN);

  //extract 6 bits of status
  //for (int i = 10; i < 16; i++){
1 Like

This is a great example!! Thank you so much.

two questions about the example code above:

  • The "Transition Testing" is for testing if the shaft has done a full turn?
  • At the bottom of the code there is a section that has been commented out "extract 6 bits of status". I assume that is for reading the "status" information being sent by the rotary encoder?
    My Bourns encoder also has 10 bits for angular information and 6 bits for status, so I guess I could basically use your code as-is :slightly_smiling_face:

Yes. But its also to tell which direction the rotation crossed zero degrees.

Use or don't use the status bits at your pleasure.