# arduino uno + AEAT-6012 rotary encoder

**URL:** <https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817>\
**Category:** Arduino\
**Created:** [November 17, 2014, 1:35pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817 "2014-11-17T13:35:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrei](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@andrei](https://community.sparkfun.com/u/andrei)\
**Post date:** [November 17, 2014, 1:35pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817/1 "2014-11-17T13:35:23Z")

</div>

Hello all,

I’m trying to implement an SSI interface between an arduino uno and a rotary encoder (AEAT-6012 [http://www.avagotech.com/pages/en/motio … -6012-a06/](http://www.avagotech.com/pages/en/motion_control_encoder_products/magnetic_encoders/aeat-6012-a06/)

i’m using this code example: [http://www.circuitsonline.net/forum/view/112693](http://www.circuitsonline.net/forum/view/112693)

i have just modified it for 12 bits instead of 10

```auto
// Definitions for the AEAT-6010
int SSI_CLK = 7;
int DataIN = 8;
int NCS = 4;
int Test = 13;
 
// Definitions for variables
unsigned int reading;
 
// program starts here
// **************************
 
void setup() {                
 
  Serial.begin(9600);
 
  // initialize the digital pin as an output.
  pinMode(NCS, OUTPUT); // Chip select
  pinMode(SSI_CLK, OUTPUT); // Serial clock
  pinMode(DataIN, INPUT); // Serial data IN/OUT
  pinMode(Test, OUTPUT);   
 
  digitalWrite(SSI_CLK, HIGH);  
  digitalWrite(Test, LOW);   
}
 
// ***********************************************************************
// Main program loop
// ***********************************************************************
void loop() {
 
unsigned int reading;
 
  ReadSSI();
  Serial.println(reading,DEC);
  delay(10);
 
}
 
 
// ***********************************************************************
// Main Loop ends here
// Start of subroutines
// ***********************************************************************
 
void ReadSSI(void)
{
int i;
char Res = 10;
unsigned int mask;
 
	reading = 0;
        mask = 0x0200;
	digitalWrite(NCS, LOW);
	delayMicroseconds(1);
	digitalWrite(SSI_CLK, LOW);
 
	for(i=(Res-1);i>0;i--)
	{
  	digitalWrite(SSI_CLK, HIGH);
  	delayMicroseconds(1);
	if (digitalRead(DataIN)) reading |= mask;	
	digitalWrite(SSI_CLK, LOW);
	mask = mask >> 1;
 
	if (i == 1) 
          {
          digitalWrite(SSI_CLK, HIGH);
 	  if (digitalRead(DataIN)) reading |= mask;	
          }
	}
 
	digitalWrite(NCS, HIGH);
}

```

for some reason i get nothing on the data output.

i have also tried another encoder of the same type and the 10bit version with the same results.

i have tried using a modified spi interface, that also didn’t work, but this version with bit banging as clock seems much more reliable so i would like to make it work.

does anybody have an idea what might not be working?

Thank you

---

<div class="post-metadata">

**Author:** ![Mee\_n\_Mac](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mee\_n\_Mac](https://community.sparkfun.com/u/Mee_n_Mac)\
**Post date:** [November 17, 2014, 8:43pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817/2 "2014-11-17T20:43:25Z")

</div>

I think the code is violating the 500 ns min timing btw a clock falling edge and a clock rising edge. I think you should put a **delayMicroseconds(1)** after every command to write a LOW to the the clock pin (2 places).

I’m a little unsure about his shifting technique, I guess it depends on whether D9 is the MSB of a 10 bit reading or if D0 is. I’d have thought the former, the code looks (to me) to assume the latter. If your data looks responsive to motion but odd, that might be the cause.

Lastly you need to change the values for Res and the mask to do 12 bits.

---

<div class="post-metadata">

**Author:** ![andrei](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@andrei](https://community.sparkfun.com/u/andrei)\
**Post date:** [November 18, 2014, 12:19pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817/3 "2014-11-18T12:19:19Z")

</div>

hi, thanks for your reply

i tried adding a delay but still nothing.

additionally, from what i see from the data sheet, the data out line should be in tristate while not transmitting, for me, it always stays high

in the attachment there is a screenshot of what i get from a logic analyzer

---

<div class="post-metadata">

**Author:** ![Mee\_n\_Mac](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mee\_n\_Mac](https://community.sparkfun.com/u/Mee_n_Mac)\
**Post date:** [November 18, 2014, 4:35pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817/4 "2014-11-18T16:35:32Z")

</div>

The timing appears good so if the connections and power are good … I’d say it’s dead Jim.

---

<div class="post-metadata">

**Author:** ![andrei](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@andrei](https://community.sparkfun.com/u/andrei)\
**Post date:** [November 25, 2014, 1:27pm UTC](https://community.sparkfun.com/t/arduino-uno-aeat-6012-rotary-encoder/29817/5 "2014-11-25T13:27:38Z")

</div>

i finally managed to find the right connector for the encoder and i tried a third sample but still nothing.

that was my last idea as i thought maybe, somehow, when soldering the wires to the connector pins i damaged the encoder. But now i just plugged it and nothing.

i’ll find some other solution to get the position…
