Arduino Encoder Help

Hello everyone,
I have a super small non-contact rotary 12 bit absolute encoder (SSI, single ended, 5 V) and an Arduino 101. My goal is to read the angular position in the serial monitor if I turn my encoder. The encoder has 4 connections, one for power, one for ground, one for the clock (which i have connected to digital pin 13) and the other for the data (which I have connected to pin 12). I've written multiple iterations of arduino sketches but I have been unsuccessful in all of them - all of the bits have been high at every timestep even when the magnet on the motor is spinning. I have attached my most recent code as reference. I have also attached the datasheet (the encoder I am using is the RM08SD located on page 6). I am new to arduino and encoders so I am not sure if the problem is the wiring, the sensor, or if something is wrong in my code. I am hoping someone is able to help. Thank you!

const int CLOCK_PIN = 13;
const int DATA_PIN = 12;
const int BIT_COUNT = 13;

void setup() {
  //setup our pins
  pinMode(DATA_PIN, INPUT);
  pinMode(CLOCK_PIN, OUTPUT);

  //give some default values
  digitalWrite(CLOCK_PIN, HIGH);

  Serial.begin(19200);
}


void loop() {
  float reading = readPosition();

  if (reading >= -0.5) {
      Serial.print("Reading: ");
       Serial.println(reading,2);
  }

  delay(500);
}

//read the current angular position
float readPosition() {
  // Read the same position data twice to check for errors
  unsigned long sample1 = bitShift(DATA_PIN, CLOCK_PIN, BIT_COUNT);
  unsigned long sample2 = bitShift(DATA_PIN, CLOCK_PIN, BIT_COUNT);
  delayMicroseconds(25);  // Clock must be high for 20 microseconds before a new sample can be taken

  if (sample1 != sample2)
    return -1.0;

  return ((sample1 & 0x0FFF) * 360UL) / 4096.0;
}

//read in a byte of data from the digital input of the board.
unsigned long bitShift(const int data_pin, const int clock_pin, const int bit_count) {
  unsigned long data = 0;

  for (int i=0; i<bit_count; i++) {
    data <<= 1;
    digitalWrite(clock_pin,LOW);
    delayMicroseconds(1);
    digitalWrite(clock_pin,HIGH);
    delayMicroseconds(1);

    data |= digitalRead(data_pin);
  }

  return data;
}

ENCODERDATASHEET.pdf (1.41 MB)

I see no obvious problems with the code.

Are you really attempting, as the post suggests, to use the 3.3V Arduino 101 with a 5V sensor, and expecting this to work?

My power signal is connected to the 5V pin on the Arduino board. Is the board's operating voltage not really 5V? Sorry, I'm very new to all of this stuff. Thanks for your help!

Sadly, interface voltage mismatch is becoming more and more of a problem. You can buy level shifters but they have tradeoffs.

For experimentation and even long term implementations, it is impossible to beat the $2 eBay Pro Minis.

They always seem to work. Buy a couple in each of the 5V and 3.3V production versions. You will need a programmer than can handle either voltage, or two dedicated 5V and 3.3V programmers.

Please do not send PMs; keep discussions on the forum.

You MUST NOT connect a 5V sensor to a 3.3V computer, or vice versa, without a level shifter of some sort. Doing so can destroy both.