Rotary Encoder - Illuminated (Red/Green)

Hi Folks!

thanks in advance for taking the time hopefully to lend a hand! (firstly I couldn’t work out what area this would be best posted into so excuse me if it’s in the wrong place!)

I’ve got a small timeline electronics/art project and I wanted to get into the world of using Rotary encoders, the electronics side I understand and I’m fully conversant in but the code side is still an absolute mystery to me for the most part

I can normally get along by crudely smashing bits of code samples together to get a working result, in this instance I’m entirely stumped

I recently purchased the R/G Rotary encoder and breakout to go with my Arduino Leonardo to get coding however the example seems to be completely outdated and will not compile, it seems to have something to do with the fact the PinChangeInt.h Library is no longer supported and discontinued and has been superseded by the original programmer to “EnableInterupt.h”

I looked at the keywords for both libraries hoping I could just migrate one set of commands for another and get up and running but it seems after a little more digging the EnableInterupt.h library is an entirely different and apparently “Simpler” kettle of fish, I say Simpler in brackets because I don’t understand any of it haha.

Can someone point me in the right direction is there any updated sample code for the Sparkfun encoder? I purchased it because I’ve had a great experience in the past with the example code being more than sufficient enough for me to bash my own stuff together from it and learn along with the way without having to understand every small facet of the code under it

This is the error I get when I come to compile:

Arduino: 1.8.10 (Windows 10), Board: "Arduino Leonardo"

In file included from PATHHIDDEN\Potentiometer_Dev\Potentiometer_Dev.ino:88:0:

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:328:32: error: 'PCMSK1' was not declared in this scope

 PCintPort portC=PCintPort(3, 1,PCMSK1); // port PC==3  (also in pins_arduino.c, Arduino version 022)

                                ^~~~~~

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:328:32: note: suggested alternative: 'PCMSK0'

 PCintPort portC=PCintPort(3, 1,PCMSK1); // port PC==3  (also in pins_arduino.c, Arduino version 022)

                                ^~~~~~

                                PCMSK0

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:331:32: error: 'PCMSK2' was not declared in this scope

 PCintPort portD=PCintPort(4, 2,PCMSK2); // port PD==4

                                ^~~~~~

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:331:32: note: suggested alternative: 'PCMSK0'

 PCintPort portD=PCintPort(4, 2,PCMSK2); // port PD==4

                                ^~~~~~

                                PCMSK0

In file included from C:\Users\luke_\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino/Arduino.h:30:0,

                 from sketch\Potentiometer_Dev.ino.cpp:1:

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h: In function 'void PCINT1_vect()':

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:589:19: warning: 'PCINT1_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]

 #define PORTCVECT PCINT1_vect

                   ^

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:604:5: note: in expansion of macro 'PORTCVECT'

 ISR(PORTCVECT) {

     ^~~~~~~~~

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h: In function 'void PCINT2_vect()':

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:590:19: warning: 'PCINT2_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]

 #define PORTDVECT PCINT2_vect

                   ^

C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt/PinChangeInt.h:614:5: note: in expansion of macro 'PORTDVECT'

 ISR(PORTDVECT){

     ^~~~~~~~~

Multiple libraries were found for "PinChangeInt.h"
 Used: C:\Users\luke_\Documents\Arduino\libraries\PinChangeInt
exit status 1
Error compiling for board Arduino Leonardo.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

hopefully, some kind soul with a much better knowledge of code can support/link me to an updated code sample that works out the box, my project lead time isn’t all that massive and I’d hoped to be up and running by now but when is that ever the way haha!

is there a formal way to inform Sparkfun also? I figure they would want to be listing working examples on product pages like the other parts I’ve purchased in the past?

Hi Sni9er.

I’ll see if we can get some updated code that works with more current libraries, even old libraries should still work as long as you have them installed.

That being said, it doesn’t look like the PinChangeInterrupt library is compatible with a Leonardo, but it still works with an Uno.

Technically you don’t really need a library to use an encoder at all and it might be better to use some example code that doesn’t use one. I haven’t tested it, but the code on [this page should work with a Leonardo.](Arduino Playground - RotaryEncoders)