I have a rotary encoder with push button (just the component, not on a breakout board) hooked up to a raspberry pico, with the rotary encoder pins A and B on pico GPIO 2 and 1 (pins 4 and 2), pin C to ground, and the switch pins connected to ground and pico GPIO 5 (pin 7), basically following every single rotary encoder tutorial on the planet, and I'm trying to read the with the following code:
#define ROTA 2 // GPIO2, pin 4
#define ROTB 1 // GPIO1, pin 2
#define SWITCH 5 // GPIO7, pin 7
int call_times = 0;
boolean boop = false;
void setup() {
pinMode(ROTA, INPUT_PULLUP);
pinMode(ROTB, INPUT_PULLUP);
pinMode(SWITCH, INPUT_PULLUP);
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(ROTA), handleRotary, RISING);
attachInterrupt(digitalPinToInterrupt(ROTB), handleRotary, RISING);
interrupts();
}
void loop() {
int val = digitalRead(SWITCH);
if (val == 0) {
if (boop == false) {
boop = true;
Serial.println("boop");
}
} else {
boop = false;
}
Serial.print(call_times);
delay(100);
}
void handleRotary() {
call_times++;
}
And this does nothing in terms of the call_times
value. The switch works fine, plenty of boops to be had when pressing it, but the interrupt handler never gets called when using the rotary dial, the value of call_times
stays zero. I removed the delay call just to make sure that wasn't interfering, but that makes no difference.
I figured I'd test the voltages to see what's going on, which is where things get head-scratchy: if I just set up ROTA and ROTB with pullup inputs with the attachInterrupt
lines and interrupts()
commented off, the voltages on both pins are 3.2V, as expected from a pulled up input. However, with the interrupt setup code in place and uncommented, the voltage on both pins is only 0.2V (i.e. so low that it'll always read a digital zero).
What am I forgetting to do? Or doing flat out wrong?