Encoder not working on Leonardo

Hello

I am trying to use a Grove Encoder with a Leonardo board but it will not compile. I am using the basic 'Encoder Test' example. This works when I upload to an Arduino UNO (but only when I use IDE 1.8x and not 2.3.2 for some reason??) but I keep getting this error message for the Leonardo board.

Here is the basic sketch:

#include <Encoder.h>
#include <TimerOne.h>
//Encoder encoder;
void setup()
{
encoder.Timer_init();
Serial.begin(9600);
}
void loop()
{
if (encoder.rotate_flag ==1)
{
if (encoder.direct==0)
{ Serial.println("backward rotated!");}
else
{Serial.println("forward rotated!");}
encoder.rotate_flag =0;
}
}

and here is the error message.

In file included from /var/folders/21/j6kzkyl57kbcqr172y2v7pxc0000gn/T/arduino_modified_sketch_512323/Encodertest.ino:1:0:
.../Documents/Arduino/libraries/Encoder/Encoder.h:37:7: warning: extra tokens at end of #endif directive [-Wendif-labels]
#endif;
^
In file included from .../Documents/Arduino/libraries/Encoder/Encoder.cpp:21:0:
.../Documents/Arduino/libraries/Encoder/Encoder.h:37:7: warning: extra tokens at end of #endif directive [-Wendif-labels]
#endif;
^
.../Documents/Arduino/libraries/Encoder/Encoder.cpp: In constructor 'Encoder::Encoder()':
.../Documents/Arduino/libraries/Encoder/Encoder.cpp:34:3: error: 'PCMSK2' was not declared in this scope
PCMSK2=0x0C;
^~~~~~
.../Documents/Arduino/libraries/Encoder/Encoder.cpp:34:3: note: suggested alternative: 'PCMSK0'
PCMSK2=0x0C;
^~~~~~
PCMSK0
In file included from .../Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h:30:0,
from .../Documents/Arduino/libraries/Encoder/Encoder.cpp:22:
.../Documents/Arduino/libraries/Encoder/Encoder.cpp: In function 'void PCINT2_vect()':
.../Documents/Arduino/libraries/Encoder/Encoder.cpp:43:5: warning: 'PCINT2_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
ISR(PCINT2_vect)
^
exit status 1
Error compiling for board Arduino Leonardo.


Any ideas on what I am doing wrong?

thanks

Steve

Either you have chosen the wrong board type in the Arduino IDE, or the encoder library is not compatible with the Leonardo, which uses a different processor than the Uno.

Which encoder library are you using??

Hi @soundsteve

welcome to the arduino-forum.
I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster. This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

best regards Stefan

Some encoder libraries are not written correctly, I find that this one is good Encoder Library, for Measuring Quadarature Encoded Position or Rotation Signals

Note that the structures of the timers are different on the Leonardo from the ones in the Uno. Which probably explains your problems.