Rotary encoders on i/o expander 16x

Status
Not open for further replies.

Fuzzy

Active member
Paul's encoder library on Teensy works extremely well, yes!

I am working on a project and need additional i/o for encoders.

I am curious if there is an i/o expander for encoders that can work just as well? I would like to add 16 additional encoders.

I have used i/o expanders for pushbuttons with no issues. But I know encoders are a different beast, especially with strong performance and interrupts.

Thanks x100
 
Speaking of encoders I just finished wiring up 24 of them with 6 of the cd4051be multiplexers and have had absolutely no issues with steps being missed. It takes 10 pins to wire it up with the inhibit being used, but works great for the number I have. I know the 74hct4051 is more preferred but it works flawlessly with what I got.
60299BD5-5239-481A-8E5F-60E595453BDD.jpg
 
@vjmuzik rad.
If you could share your code, that would be massively helpful :)

Basically I have the encoders A pin on one multiplexer and the B pin on another so for 8 encoders it takes two multiplexers.

Here’s basic code for 8 encoders.

Code:
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>

#define inhibit 29
#define A 30
#define B 31
#define C 32
#define encodersA 8
#define encodersB 9




Encoder myEnc[8] = {
  Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), 
  Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB)
};
long position[8]  = {
  -999, -999, -999, -999, -999, -999, -999, -999
};
uint8_t encIncNum[8] = {
  0, 1, 2, 3, 4, 5, 6, 7
};


void setup() {
  // put your setup code here, to run once:
  pinMode(inhibit, OUTPUT);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
}


uint8_t i = 0;
void loop() {

  
  readInputs(i);
  
  i++;
  if(i >= 8) {
    i = 0;
  }
}

void selectAddress(uint8_t a) {
  digitalWrite(inhibit, HIGH);
  digitalWrite(A, a & 0x1);
  digitalWrite(B, (a >> 1) & 0x1);
  digitalWrite(C, (a >> 2) & 0x1);
  digitalWrite(inhibit, LOW);
}

void readEnc(uint8_t enc) {
  long newPos = myEnc[enc].read();
  if (newPos != position[enc]) {
    position[enc] = newPos;
    if(position[enc] < 0) {
      usbMIDI.sendControlChange(97, encIncNum[enc], 1);
    }
    if(position[enc] > 0) {
      usbMIDI.sendControlChange(96, encIncNum[enc], 1);
    }
    myEnc[enc].write(0);
  }
}

void readInputs(uint8_t i) {
  selectAddress(i);
  delayMicroseconds(50);
  readEnc(i);
}
 
Status
Not open for further replies.
Back
Top