Angle and rotary encoder

Hi alla guys, I hope for an illumination for a little project on my thesis.

I need to mesaure the length of an irregular object by sliding on it.

I think i need ti use a Shaft (or rotary) encoder but i don't know what model to use and if there is a library for Arduino. I need to do a low speed measurement and i need the highest precision possibile spending less than 100-150 dolars :(

Can you help me? :)

Thaaaaaaaaanks :D

You will have to provide a little more information on what you are trying to do. How irregular obejects? What dimension? What surface? An encoder with a friction wheel might be feasable. An other solution might be hacking an optical mouse

CROSS-POSTING not allowed !!! http://forum.arduino.cc/index.php?topic=284560.msg1994585#msg1994585

Or you write in italian section or in international section

@nid69ita: Sorry for cross posting.

@nilton: I need to track the perimeter of an object by sliding a shaft encoder on it (an object like a car dimension) and i need to sync the encoder data (connected on a wheel) with an IMU sensor like 9DOF Razor IMU or x-bIMU :)

That sounds pretty complicated but still doable if you got your math right.
I have been using these 1024p/r encoder a lot If you act on every edge you can get 4096 counts/rev. With a 50mm dia masuring wheel that will give you a linear resolution of 0.03835mm

Here is some example code:

const char encTable[16] ={0, 1, -1, -0, -1, 0, -0, 1, 1, -0, 0, -1, -0, -1, 1, 0};//gives -1, 0 or 1 depending on encoder movement
volatile long actPos;
volatile byte encState;

void setup(){
    Serial.begin(115200);
    attachInterrupt(0, readEnc, CHANGE);
    attachInterrupt(1, readEnc, CHANGE);
}//setup()

void loop(){
  Serial.println(actPos);
  delay(500);
}//loop()

void readEnc(){
  encState = ((encState<<2)|((PIND>>2)&3))&15;//use encoder bits and last state to form index
  actPos += encTable[encState];//update actual position on encoder movement
}//readEnc()

nilton61:
That sounds pretty complicated but still doable if you got your math right.
I have been using these 1024p/r encoder a lot If you act on every edge you can get 4096 counts/rev. With a 50mm dia masuring wheel that will give you a linear resolution of 0.03835mm

Here is some example code:

const char encTable[16] ={0, 1, -1, -0, -1, 0, -0, 1, 1, -0, 0, -1, -0, -1, 1, 0};//gives -1, 0 or 1 depending on encoder movement

volatile long actPos;
volatile byte encState;

void setup(){
   Serial.begin(115200);
   attachInterrupt(0, readEnc, CHANGE);
   attachInterrupt(1, readEnc, CHANGE);
}//setup()

void loop(){
 Serial.println(actPos);
 delay(500);
}//loop()

void readEnc(){
 encState = ((encState<<2)|((PIND>>2)&3))&15;//use encoder bits and last state to form index
 actPos += encTable[encState];//update actual position on encoder movement
}//readEnc()

Thank you very much :smiley: this us exactly what i need but… I See too much wires :o is there a Hardware usage example (or a sketch up diagram ;'D )

And another question, sequentially i get YPR data from IMU (i said sequentially because is impossibile to use multithreading in Arduino) and Shaft, will i have problems with clock ( latency or delay on the read of one of two sensors)?

Thaaaaaaanks, have a nice day :smiley: