chipKIT® Development Platform

Inspired by Arduino™

PMod ENC or other encoder library for Max32?

Created Tue, 31 Jul 2012 22:29:51 +0000 by cgclepper


Tue, 31 Jul 2012 22:29:51 +0000


I am moving a project from Arduino to Max32 and have gotten pretty much everything working but the UI rotary encoders.

I first tried using the excellent Rotary library [1] but it doesn't work nearly as well (or at all) with the Max32 board. I think the library is built for Arduino 1.0 so that may be an issue.

Next, I found the PMod ENC library on the Digilent site which looked promising considering the source. I had to fix an error or two in the files (like <sys\attribs.h> to the proper Unix /), but it appears that the interrupt setup in Enc.begin() hangs the board. Even a simple Serial.print() doesn't seem to execute. Any ideas about getting this to work with the Max32?

I did not use interrupts in my Arduino code because I have some other time sensitive code and the UI encoder polling is deferred. It still runs every 500 usec so events are not missed.

Rolling my own library is certainly not out of the question, but I would prefer not to have to reinvent a basic wheel.

Thanks Chris

[1] [url][/url]

Jacob Christ

Sat, 15 Sep 2012 19:25:43 +0000

The PONTECH UAV100 ( project has some code in it to read a quadrature encoder. I think it may not be building correctly with the latest release of MPIDE right now though. The code is really not in a library form, its just in the pde file.

The project uses two sub modules that are located here:


Adam Donovan

Sat, 22 Sep 2012 07:39:01 +0000

Hmm seems to me that there is some serious issues with reading encoders. I was thinking about getting 2 1024 ppr encoders to control the ABS position of a stepper motor that controls my Gimbal. I wanted to make of these encoders into a high resolution haptic/joystick for the Gimbal but no idea now what code would even work with the chipkit. I did have the following code running on the arduino but cant test it as Im away and my coding skills are not that great. Any ideas if this LIB is going to work? Or anything else that might be faster?

/* Encoder Library - Basic Example

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder. // Best Performance: both pins have interrupt capability // Good Performance: only the first pin has interrupt capability // Low Performance: neither pin has interrupt capability Encoder myEnc(2, 3); // avoid using pins with LEDs attached

void setup() { Serial.begin(9600); Serial.println("Basic Encoder Test:"); }

long oldPosition = -999;

void loop() { long newPosition =; newPosition = newPosition % 2000; long degree = (newPosition * 360) / 2000;

Serial.println(degree); }


Mon, 24 Dec 2012 18:23:06 +0000

any new information on using encoders on the chipkit? i want to use one on an uno and was wondering if there are problems. difficult to tell from this thread if it is just a max problem or ???

i need to get this working pretty soon and can always add a teensy 2 to read the encoder but it would be much better if i could use the chipkit that is doing the rest of the job.

is there any point in trying the pmodenc library to read a high speed optical shaft encoder?

Jacob Christ

Mon, 24 Dec 2012 20:29:18 +0000

They will work, but it may be a matter of refining some software.