Encoder Libary not working with Arduino Due

Status
Not open for further replies.

dave_

New member
Hy!

I've done some tests with the encoder libary on an Arduino Micro and everything worked perfectly.
However, I have now upgraded to an Arduino Due and I'm not able to get it working there.

It seems that somehow the pullup-resistors don't work. Because when the encoder is in in a state where both pins are floating, interrupts happen constantly and the value increases rapidly.
When the encoder is in a state where both pins are tied to ground, everything is fine (no unwanted interrupts).

I've also tried the following code and it works as expected:
Code:
void setup() {
	pinMode(12, INPUT_PULLUP);
	attachInterrupt(12, testfunc, CHANGE);
}
The function "testfunc" is called when the pin is connected to ground and when floating there is a constant 3.3 volts.

After initializing an encoder at two pins, their voltage is somewhere between 0 and 3.3 Volts when floating.

Does somebody have an idea what's causing that and how it can be fixed?
 
It did work with earlier versions of Arduino 1.5.x. Maybe trying it with the older versions to figure out which change broke it, and then looking at the specific stuff that changed in that version might shine some light on this problem?

I can't get involved in troubleshooting this problem, but I'd be happy to accept a patch if anyone does figure it out.
 
I got it working! :)
But I'm afraid, I still don't know exactly what the problem was.

My solution was to move all the pin and interrupt initialization stuff from the constructor to an "init()" method. I basically renamed the constructor from

Code:
	Encoder(uint8_t pin1, uint8_t pin2) {
		pinMode(pin1, INPUT_PULLUP);
		pinMode(pin2, INPUT_PULLUP);
		encoder.pin1_register = PIN_TO_BASEREG(pin1);
...
to
Code:
	void init(uint8_t pin1, uint8_t pin2) {
		pinMode(pin1, INPUT_PULLUP);
		pinMode(pin2, INPUT_PULLUP);
		encoder.pin1_register = PIN_TO_BASEREG(pin1);
...

and called the init method in the setup() section:

Code:
#include <Encoder.h>

Encoder knob;

void setup() {
  knob.init(24, 26);
}
...

That's definitely not the most elegant solution but at least it works...
 
Status
Not open for further replies.
Back
Top