I have some encoders that I need to use on the analog pins of the due. Encoder1 is attached to A1, A3 (pins 55 and 57) and encoder2 is attached to A6 and A8 (pins 60 and 62). I am using an arduino due
While encoder2 works fine, encoder1 does not. I checked the pins with an oscilloscope and it gets the pulses just fine, I believe the only remaining thing that would cause it not to work is if A1 and A3 were not capable of interrupts. According to that attachInterrupts page, it doesn't say if any of the analog pins can use interrupts (even if being used as digital pins), but I'm not sure why this would work for encoder2 only. I have also tried the format:
attachInterrupt( digitalPinToInterrupt(pin) );
I have the same results with other encoder libraries.
I am using the quadrature.h library. Here is a snippit of the code it sets up the interrupts
template<int A, int B>
inline
void Quadrature_encoder<A, B>::begin()
{
//store the starting state for the two interrupt pins
if(b == Board::uno) {
if (A_pin == 0) {
pin_A_digital = 2;
pin_B_digital = 3;
} else {
pin_A_digital = 3;
pin_B_digital = 2;
}
}
if(b == Board::due) {
pin_A_digital = A_pin;
pin_B_digital = B_pin;
}
/*
TODO: Add mega support
*/
pinMode(pin_A_digital, INPUT);
pinMode(pin_B_digital, INPUT);
Enc_A = digitalRead(pin_A_digital);
Enc_B = digitalRead(pin_B_digital);
//configure the interrupts
attachInterrupt(A_pin, &Quadrature_encoder<A,B>::delta_A, CHANGE);
attachInterrupt(B_pin, &Quadrature_encoder<A,B>::delta_B, CHANGE);
}