<AdaEnconder.h> - Problems with Arduino Micro

Hello!

I have a strange problem with the AdaEnconder library. When using this library on an Arduino UNO everything works like a charm. But after uploading the code to my MICRO, it seems like it just does nothing.

Here is the code I am using:

#include <ByteBuffer.h>
#include <ooPinChangeInt.h>
#include <AdaEncoder.h>

#define ENCA_a 2
#define ENCA_b 3

AdaEncoder encoderA = AdaEncoder('a', ENCA_a, ENCA_b);

int8_t clicks=0;
char id=0;

void setup()
{
  Serial.begin(115200);
}

void loop() 
{
  AdaEncoder *thisEncoder=NULL;
  thisEncoder=AdaEncoder::genie();
  if (thisEncoder != NULL)
  {
    clicks=thisEncoder->query();
    if (clicks > 0)
    {
      Serial.println(" CW");
    }
    if (clicks < 0)
    {
       Serial.println(" CCW");
    }
  }
}

(Please note that this is a modified version of the included example.)

As I said, the code works as supposed on my UNO. So does the original example and even a rewritten code that functions as an interrupt service routine.

So, as my MICRO does not output anything (not even with the original example code), I decided to add a few serial prints to find out what is going on. It seems like as if “thisEncoder” stays always NULL, so I guess the problem must have something to do with the “genie()” function.

Here is what the function looks like:

AdaEncoder *AdaEncoder::genie()
{
  // if (currentEncoder == NULL)
  currentEncoder=firstEncoder;
  while (currentEncoder != NULL)
  {
    if (currentEncoder->clicks)
    {
      return currentEncoder;
    }
    currentEncoder=currentEncoder->next;
  }
  return NULL;
}

Well… I am not too deep into C++ yet, so maybe someone might give me a hint why this is not working on my MICRO. Thanks a bunch!

On the Micro, although pins 2 and 3 are used for interrupts, they are interrupts 1 and 0 respectively whereas on the Uno they are interrupts 0 and 1. Could that explain the problem ?

No, that does not really make a difference. I just would turn the reading around, meaning that you would get a CCW reading although it is spinning CW and vice versa.

That library uses PCINTs, not INT1/INT0, as far as I can tell?

The Micro doesn't have PCINTs on those two pins. I think you need it on Port B.

Ahhh... Thank you, that was something I did not think of. THANKS!