I'm working on a project with the Adafruit ANO Rotary Navigation Encoder to I2C Stemma QT Adapter and the Adafruit Feather RP2040.
Below is a modification of the rotary encoder example code.
A seesaw GPIO interrupt is attached to SS_SWITCH_UP. I have wired the rotary encoder interrupt pin to pin 6 on the feather. Additionally, I have attached an interrupt to feather pin 6.
Neither pins' interrupts work unless SS_SWITCH_UP is being polled with ss.digitalRead(). Not even the pullups work without polling.
I am using interrupts specifically because I do not want to be polling the seesaw buttons while other functions are running. How can I get these interrupts to work as intended? Am I using them incorrectly?
/*
* This example shows how to read from a seesaw encoder module.
* The available encoder API is:
* int32_t getEncoderPosition();
int32_t getEncoderDelta();
void enableEncoderInterrupt();
void disableEncoderInterrupt();
*/
#include "Adafruit_seesaw.h"
#define SS_SWITCH_SELECT 1
#define SS_SWITCH_UP 2
#define SS_SWITCH_LEFT 3
#define SS_SWITCH_DOWN 4
#define SS_SWITCH_RIGHT 5
#define INTERRUPT_PIN 6
#define SEESAW_ADDR 0x49
Adafruit_seesaw ss;
int32_t encoder_position;
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Looking for seesaw!");
if (! ss.begin(SEESAW_ADDR)) {
Serial.println("Couldn't find seesaw on default address");
while(1) delay(10);
}
Serial.println("seesaw started");
uint32_t version = ((ss.getVersion() >> 16) & 0xFFFF);
if (version != 5740){
Serial.print("Wrong firmware loaded? ");
Serial.println(version);
while(1) delay(10);
}
Serial.println("Found Product 5740");
ss.pinMode(SS_SWITCH_UP, INPUT_PULLUP);
ss.pinMode(SS_SWITCH_DOWN, INPUT_PULLUP);
ss.pinMode(SS_SWITCH_LEFT, INPUT_PULLUP);
ss.pinMode(SS_SWITCH_RIGHT, INPUT_PULLUP);
ss.pinMode(SS_SWITCH_SELECT, INPUT_PULLUP);
// get starting position
encoder_position = ss.getEncoderPosition();
Serial.println("Turning on interrupts");
// ss.enableEncoderInterrupt();
ss.setGPIOInterrupts((uint32_t)1 << SS_SWITCH_UP, 1);
// feather INTERRUPT_PIN is connected to seessaw INT pin
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), detectInterrupt, FALLING);
}
void loop() {
// PROBLEM: interrupts do not work without this polling
if (! ss.digitalRead(SS_SWITCH_UP)) {
Serial.println("UP pressed!");
}
int32_t new_position = ss.getEncoderPosition();
// did we move around?
if (encoder_position != new_position) {
Serial.println(new_position); // display new position
encoder_position = new_position; // and save for next round
}
// don't overwhelm serial port
delay(10);
}
void detectInterrupt() {
Serial.println("---interrupt---");
}