How to use linear encoders with Arduino. hardware, code, and demo.
How to salvage linear encoders form a broken (or out of ink) printer and use them with an Arduino to make precise motions measurements. Hardware, theory, software walkthrough, and demo.
I also discuss some of the pitfalls of interrupt code.
The code:
// Interrupt information
// 0 on pin 2
// 1 on pin 3
#define encoderI 2
#define encoderQ 4 // Only use one interrupt in this example
volatile int count;
void setup()
{
Serial.begin(115200);
count=0;
pinMode(encoderI, INPUT);
pinMode(encoderQ, INPUT);
attachInterrupt(0, handleEncoder, CHANGE);
}
void loop()
{
Serial.println(count);
delay(10);
}
void handleEncoder()
{
if(digitalRead(encoderI) == digitalRead(encoderQ))
{
count++;
}
else
{
count--;
}
}
Видео How to use linear encoders with Arduino. hardware, code, and demo. канала Cheap Science
I also discuss some of the pitfalls of interrupt code.
The code:
// Interrupt information
// 0 on pin 2
// 1 on pin 3
#define encoderI 2
#define encoderQ 4 // Only use one interrupt in this example
volatile int count;
void setup()
{
Serial.begin(115200);
count=0;
pinMode(encoderI, INPUT);
pinMode(encoderQ, INPUT);
attachInterrupt(0, handleEncoder, CHANGE);
}
void loop()
{
Serial.println(count);
delay(10);
}
void handleEncoder()
{
if(digitalRead(encoderI) == digitalRead(encoderQ))
{
count++;
}
else
{
count--;
}
}
Видео How to use linear encoders with Arduino. hardware, code, and demo. канала Cheap Science
Комментарии отсутствуют
Информация о видео
23 сентября 2012 г. 2:40:37
00:09:52
Другие видео канала