Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: Reading an Absolute Encoder (Bourns EMS22A) on: June 18, 2012, 10:09:28 am
Seems I just confused with the wiring, since it works now smiley-razz
Thanks for the help anyway.

btw: The ChipSelect pin is realy necessary. Here is my example code in case somebody else wants to tinker with this type of encoders:

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

void setup() {
  Serial.begin(9600);
  pinMode(PIN_CS, OUTPUT);
  pinMode(PIN_CLOCK, OUTPUT);
  pinMode(PIN_DATA, INPUT);

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


//byte stream[16];
void loop() {

  digitalWrite(PIN_CS, HIGH);
  digitalWrite(PIN_CS, LOW);
  int pos = 0;
  for (int i=0; i<10; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
   
    byte b = digitalRead(PIN_DATA) == HIGH ? 1 : 0;
    pos += b * pow(2, 10-(i+1));
  }
  for (int i=0; i<6; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
  }
  digitalWrite(PIN_CLOCK, LOW);
  digitalWrite(PIN_CLOCK, HIGH);
  Serial.println(pos);
}
2  Using Arduino / Sensors / Re: Reading an Absolute Encoder (Bourns EMS22A) on: June 16, 2012, 02:38:11 am
I figured, that the cs pin would only  if you daisy chain several encoders together. I tried it anywhy but it didn't changened anything:
Code:
const int PIN_CS = 5;
const int PIN_CLOCK = 6;
const int PIN_OUTPUT = 7;

void setup() {
  Serial.begin(9600);
  pinMode(PIN_CS, OUTPUT);
  pinMode(PIN_CLOCK, OUTPUT);
  pinMode(PIN_OUTPUT, INPUT);
  
  digitalWrite(PIN_CLOCK, HIGH);
  digitalWrite(PIN_CS, LOW);
}

void loop() {
  delay(1000);
  digitalWrite(PIN_CS, HIGH);
  delayMicroseconds(1);
  digitalWrite(PIN_CS, LOW);
  delayMicroseconds(1);
  
  for (int i=0; i<16; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
    Serial.print(digitalRead(PIN_OUTPUT));
  }
  digitalWrite(PIN_CLOCK, LOW);
  digitalWrite(PIN_CLOCK, HIGH);
  Serial.println("");
}
BTW: I updated the links in my post above.
3  Using Arduino / Sensors / [Solved] Reading an Absolute Encoder (Bourns EMS22A) on: June 15, 2012, 05:43:35 pm
Hey,
I'm having problems reading an Bourns EMS22A Absolute Encoder. It outputs a stream of bitwise data which is controlled by a clock line. you can find the Data Sheet here.
I connected the Pin 6 & 1(chip select & digital input) to ground since I only have 1 encoder and don't need to daisy chain anything.
Here my test code to test the encoder, but somehow it only outputs zeros and I'm not sure why:
Code:
const int PIN_CLOCK = 6;
const int PIN_OUTPUT = 7;

void setup() {
  Serial.begin(9600);
  pinMode(PIN_CLOCK, OUTPUT);
  pinMode(PIN_OUTPUT, INPUT);
  digitalWrite(PIN_CLOCK, HIGH);
}

int last_output = -1;

void loop() {
  delay(1000);
  for (int i=0; i<16; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
    Serial.print(digitalRead(PIN_OUTPUT));
  }
  digitalWrite(PIN_CLOCK, LOW);
  digitalWrite(PIN_CLOCK, HIGH);
  Serial.println("");
}
Maybe some one can figure out what I'm doing wrong.
Pages: [1]