I have a robot base that includes these encoders added to the output shaft of my drive.
I have not worked with encoders but slapping 6 LED's on the 6 signal pins and moving the wheel by hand I easily deciphered a pattern
654321 - pins
000101
001001
001010
000110
Where pin 5 pulses once per revolution, and pin 6.. well.. stays low.. Not sure what it's for.
The specs I found here:
When I barely touch the tires and push them back and forth, I can slowly step through the pattern above, no problem. It never misses. But I am literally just moving the tire a few degrees at most. So it's super sensitive. When I engage the motors, and watch the serial console, I see missing values in the sequence.
I am using the remedial attempt to watch for a change in values, to dump to the serial port. My question is, if I wanted to detect direction and speed/distance, would an Uno be able to keep up, or is there an interface chip I should be looking at?
`#include <Arduino.h>
// monitor the encoder using these 6 pins.
const int encPin1 = 8;
const int encPin2 = 9;
const int encPin3 = 10;
const int encPin4 = 11;
const int encPin5 = 12;
const int encPin6 = 13;
int encVal1;
int encVal2;
int encVal3;
int encVal4;
int encVal5;
int encVal6;
int lastVal = 0;
void setup() {
// put your setup code here, to run once:
delay(3000);
pinMode( encPin1, INPUT_PULLUP ); // The encoder is open collector, so use the pull up's in the arduino.
pinMode( encPin2, INPUT_PULLUP );
pinMode( encPin3, INPUT_PULLUP );
pinMode( encPin4, INPUT_PULLUP );
pinMode( encPin5, INPUT_PULLUP );
pinMode( encPin6, INPUT_PULLUP );
Serial.begin( 9600 );
}
int readEnc() { // This routine reads all 6 pins, and makes an 8 bit integer using the bit positions)
encVal1 = digitalRead( encPin1 );
encVal2 = digitalRead( encPin2 );
encVal3 = digitalRead( encPin3 );
encVal4 = digitalRead( encPin4 );
encVal5 = digitalRead( encPin5 );
encVal6 = digitalRead( encPin6 );
int encVal = (1 * encVal1) + (2 * encVal2) + (4 * encVal3) + (8 * encVal4 ) + ( 16 + encVal5 ) + (32 * encVal6 );
return encVal;
}
void loop() {
// This loop may not be fast enough to catch the incremental transitions when teh motors are engaged, that is my worry.. how might I do this better?
while ( readEnc() != lastVal ) { // This code watches for a change in value, records the new value, then prints the binary output to the serial port
lastVal = readEnc();
Serial.println( lastVal, BIN);
}
}`