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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Accuracy of a print head sensor in a DIY linear driveHow Rotary Encoder Works and How To Use It with ArduinoJCS-900 DRO with Arduino and LCDHow an Encoder WorksSchematics and sketch to use inkjet printer linear encoderTransmissive optical sensors from old printers and scannersHow to connect your “L298N Dual H-Bridge Motor Controller” to “Arduino Uno”How to make GRBL+arduino based CNC plotter PCB ink plotterClosed Loop Stepper Motors for CNC machinesHACKED!: Using an HDD Motor as a Rotary Encoder?!CNC Closed Loop V Open Loop Systems V Rotary Encoder V Linear ScaleWhat is the Difference between Absolute and Incremental Encoders?Rotary encoder - sensor arrangementStepper Motors with Arduino - Controlling Bipolar & Unipolar stepper motorsCNC v3.2.1 - electronics using DC motors and rotary encodersNew spindle motor for the latheAbsolute vs. Quadrature EncodersDocumenting the Servo Motor's Resolver Position Timing.Arduino and Hardware Debouncing tutorialChasing Micrometres with the best Ball Screws