This looks pretty nifty. "Using the three onboard address jumpers, you can connect up to 8 of these encoders on a single I2C port." Which means only two I/O pins needed.
Thanks for the answer! Yeah that module is interesting and would make it easier. Though I doubt it will be available on my country (and ordering it is a no-no due import prices).
The problem with multiple rotary encoders is that you need an interrupt for each encoder you have.
Not only that but you need extra pins that can generate interrupts as well and an Arduino Uno only has two of them.
You could use the pin change interrupt on an Arduino Uno to create many more interrupts if you use this feature. The coding would be a bit more complex but you could do this without needing any extra pins except one for each encoder you want to use.
Also the code needs to implement a state machine to do the automatic de-bouncing you can get with doing it this way.
Or you could use a different processor that has more interrupt pins. I have seen the RP2040 used for this where every pin is capable of generating an interrupt. Then you would not have to use the pin change but you still need a state machine for each rotary encoder. Using arrays would help cut down the code for this.
It is not a simple project. How experienced are you with hardware and software?
No that would not work. But the MCP23S17 would probably work.
If you want to use expander use two, put the Clock on one and use that interrupt, put the DT on the other. When you rotate the encoder you will get an interrupt, that you have to mask out of 8 then read the other PCF8574 and the DT will tell you the direction it is rotating. DT and CLK are interchangeable so depends on what edge etc you are working with on the interrupt.
Pick one edge rising or falling on one and read the level of the other.
The PB switch can be read from another PCF8574. The rotary encoders I use have built in resistors, using input pullup will make then real flakey but will not hurt them. They also have debounce capacitors saving a lot of software. The KY-040 do not have resistors. The ones I use look like this:
HINT: Do NOT use delays in your code.
Hopefully this helps.
I built something quite a bit smaller, with just 2 encoders and 2 faders, and a simple 1602 LCD.
I do think you will be short of pins (just as i almost was)
8 encoders will require 2 pins each (without the buttons) You can use PinChangeInterrupts It isn't basic programming but i can help get that to work. I added 10K pullups & Debouncing capacitors since the cheap encoders i have just don't have any.
Anyway that will take up 16 pins.
The I2C Oled will take 2 pins, and i am expecting the MIDI port to use the UART,
So with 3 encoders using up the remaining pins of PortD and another 3 encoders using up all available pins of PortB, with the Oled taking 2 Pins of PortC that leaves just 4 pins for the 2 remaining encoders, but now there is nothing left for the buttons.
So without expanders i don't think it can be done on an UNO, but on a Nano or Pro-mini there are 2 more input pins available (A6 & A7) which could accommodate the buttons with just the help of a few resistors. (i used a pro-mini btw)
Personally i am not into using expanders, and would rather just use a bigger board in such a situation.
I am also wondering why you would want 8 encoders. I actually use 1 of the encoders to select what the other one is doing and what the faders are doing, but if you want 8, who am i to disagree.
It might be worth to as @PieterP for an opinion. He's the author of Control surface and may have some ideas on how to solve your issue.
This project uses a board with lots of GPIO pins to connect 8 rotary encoders. The board is a Pi Pico. The code is CircuitPython but the board can be programmed using the Arduino IDE with the arduino-pico board package. The Pi Pico suports MIDI over USB in Arduino and CP. One of the CP examples in the firmware directory shows how to send MIDI CC over USB.
In terms of experience level, I think I can handle it. I've worked on projects with debouncing state machines before. Though I thought this project would be simpler to do haha. I will investigate to use RP2040
8 encoders so when changing from virtual instrument to virtual instrument the values don't jump!!
Also the code I used for my last project used Control surface.