I've posted to the DFRobot forum, who makes the FIT0186 motors, but no one seems to be replying there. So, excuse the copy pasting. It's probably an issue with the motor/encoder, but perhaps it has to do with the arduino. I'm using a Nano, and a TB6612 based motor driver from DFRobot.
I'm trying to get the built-in encoder working for the FIT0186.
The example wiki code doesn't work, and I've modified it as far as I can using sensible changes. I'm plugging both Hall Sensor A and B outputs to the interrupts.
Currently, when I plug in the 12V, it triggers an interrupt, but then other than that initial pulse, no interrupts are triggerred.
The motor is moving as expected. Attaching my code. Has anyone got the encoder working?
const byte encoder0pinA = 2;
const byte encoder0pinB = 3;
volatile int posA;
volatile int posB;
int DIR1 = 8;
int PWM1 = 9;
void setup()
{
Serial.begin(115200);
pinMode(DIR1, OUTPUT);
pinMode(PWM1, OUTPUT);
pinMode(encoder0pinA,INPUT);
pinMode(encoder0pinB,INPUT);
attachInterrupt(digitalPinToInterrupt(encoder0pinA), encoderA, RISING);
attachInterrupt(digitalPinToInterrupt(encoder0pinB), encoderB, RISING);
}
void loop()
{
Serial.print("Pulse:");
Serial.println(posA);
Serial.println(posB);
noInterrupts();
posA = 0;
posB = 0;
interrupts();
delay(100);
int value;
digitalWrite(DIR1, HIGH);
for(value = 0 ; value <= 255; value += 5)
{
analogWrite(PWM1, value); //PWM Speed Control
delay(20);
}
Serial.print("Pulse:");
Serial.println(posA);
Serial.println(posB);
delay(100);
for(value = 255 ; value >= 0; value -= 5)
{
analogWrite(PWM1, value); //PWM Speed Control
delay(20);
}
Serial.print("Pulse:");
Serial.println(posA);
Serial.println(posB);
delay(100);
digitalWrite(DIR1, LOW);
for(value = 0 ; value <= 255; value += 5)
{
analogWrite(PWM1, value); //PWM Speed Control
delay(20);
}
Serial.print("Pulse:");
Serial.println(posA);
Serial.println(posB);
delay(100);
for(value = 255 ; value >= 0; value -= 5)
{
analogWrite(PWM1, value); //PWM Speed Control
delay(20);
}
}
void encoderA()
{
posA++;
}
void encoderB()
{
posB++;
}