I use arduino uno and absolute encoder 1024 divisions. I find a website where I see how to connect my encoder with arduino.
www.thaiconverter.com/article/14/%E0%B8%AD%E0%B9%88%E0%B8%B2%E0%B8%99%E0%B8%84%E0%B9%88%E0%B8%B2-absolute-encoder-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-arduino
from this website I used sketch.
boolean pin_state[10];
byte input_pin[] = {2,3,4,5,6,7,8,9,10,11}; // Config Pins Input Here bit-1 to 10
int dec_position = 0;
boolean a = 0;
void setup() {
Serial.begin(9600);
for(byte i = 0; i <10; i = i +1 ){ // declare pin mode
pinMode(input_pin[i], INPUT);
}
}
void loop() {
Read_input(); // Read Encoder Signal
delay(100);
}
void Read_input(){
for(byte i = 0; i <10; i = i + 1 ){
pin_state[i] = !digitalRead(input_pin[i]); // Bitwise for active LOW
}
// Gray Code Decoder
dec_position = pin_state[9];
for( int i = 8; i >= 0; i = i -1){
dec_position = (dec_position << 1) | (pin_state[i] ^ (dec_position&0x1));
}
// Print 0-1023 position with line feed
Serial.println(dec_position, DEC);
}
and I use com-port and see how signals from encoder change.
but signals are random(example after 30 may be go 431 and etc).
can you help me?