Absolute Rotary Encoder

Hello All, I try to read digital Absolute Rotary Encoder with Arduino in SerialMonitor, with this code:

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*, INPUT);*
}
}
void loop() {
Read_input(); // Read Encoder Signal
delay(100);

}
void Read_input(){

  • for(byte i = 0; i <10; i = i + 1 ){*
    pin_state = !digitalRead(input_pin*); // 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 ^ (dec_position&0x1));
}*_

* // Print 0-1023 position with line feed*
* Serial.println(dec_position, DEC);
_}
OUTPUT SERIAL
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
599
597
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
170
170
170
170
170
170
138
253
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
607
599
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682

I want Questions about this output and code Absolute Rotary ENcoder, Thanks for you attention._

$_1.JPG*

Hi
The picture is fine, but it doesn’t give us the specifications, part numbers etc.
Please post the specs or a link to the specs of the encoder please.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile:

Zastra:
Hello All, I try to read digital Absolute Rotary Encoder with Arduino in SerialMonitor, with this code:

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*, INPUT);*
}
}
void loop() {
Read_input(); // Read Encoder Signal
delay(100);

}
void Read_input(){

  • for(byte i = 0; i <10; i = i + 1 ){*
    pin_state = !digitalRead(input_pin*); // 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 ^ (dec_position&0x1));
}*_

* // Print 0-1023 position with line feed*
* Serial.println(dec_position, DEC);
_}
OUTPUT SERIAL
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
599
597
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
170
170
170
170
170
170
138
253
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
607
599
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682

I want Questions about this output and code Absolute Rotary ENcoder, Thanks for you attention.
[/quote]*

The code you posted did not generate the alleged output.
It is riddled with compiler errors, too many to list.
For example for loop not using indexes etc.
Please post the real code you have used.
As pointed out , a spec for the encoder would help.
BTW Absolute encoder probably does not have Gray code output, but the spec would tell us._

It looks to me like you are taking a binary output and treating it as Greycode.