Need help to connect 8 rotary encoders and 8 switches to arduino as midi control

Hi

Can anyone help or guide me as i want to make a midi controller to control Lightroom and ease out my workflow.

My aim is to connect 8 rotary encoders and 8 switches (apart from the inbuilt switches in rotarty encoders) to an arduino Uno or an arduino pro micro so tht i can use it as a USB midi controller and then map the controller to a midi mapping software.

I know a bit about electronics, soldering and uploading code.
But i have no idea of coding or anything of that sort.

I would really like someone to help me with the connections and also the code.

It would be of great help.

Thanks!

Hi

Can anyone help me in making a midi controller using 8 rotary encoders and an i2c multiplexer?

Thanks

nikonian:
Can anyone help me in making a midi controller using 8 rotary encoders and an i2c multiplexer?

No.
I can’t see how you can use an I2C multiplexer in any way to do that.

Cross posting is a way to annoy people on this forum. Thread reported to moderator.

Threads merged.

What is Lightroom?

Why rotary encoders? They don’t keep their position through power cycles and if it is a MIDI control you will have to restrict the numbers in software to make it look like you have a pot anyway. This is a lot simpler to do with pots.

With a rotary encoder you need at least one but preferably two interrupt capable pins to read them, which would involve using the pin change interrupt feature of the processor.

8 encoders is 16 digital pins at a minimum. All three ports banging with pin change interrupts. It won’t leave you much room to hook anything else to an UNO.

Here’s some code that reads two adjacent sets of two adjacent pin change interrupt pins to read two encoders on a pair of motors on a tank.

#define LEFT_INT_MASK 0x80
#define LEFT_B_MASK 0x40
#define RIGHT_INT_MASK 0x20
#define RIGHT_B_MASK 0x10


volatile uint8_t lastPortRead = 0;

volatile int32_t leftCounter = 0;
volatile int32_t rightCounter = 0;


ISR(PCINT2_vect){

	uint8_t portRead = PINC;

	uint8_t whoFired = portRead ^ lastPortRead;
	uint8_t pinsDiff = portRead ^ (portRead << 1); // Will have bits 5 or 7 set if pins on right motor or left motor are diff.  Cleared if same.

	if (whoFired & LEFT_INT_MASK) {
		boolean forw = false;
		if (pinsDiff & LEFT_INT_MASK) {
			leftCounter++;
			forw = true;
		} else {
			leftCounter--;
		}
	}
	if (whoFired & RIGHT_INT_MASK) {
		boolean forw = false;
		if (pinsDiff & RIGHT_INT_MASK) {
			rightCounter++;
			forw = true;
		} else {
			rightCounter--;
		}
	}

	lastPortRead = portRead;
}


void setupPCint(){

	PCICR = PCICR | (1 << PCIE2);   //  Turn on pin change interrupt 2
	PCIFR = (1 << PCIF2);   // Clear any pending interrupt flag for pin change interrupt 2
	PCMSK2 = (1 << PCINT23) | (1 << PCINT21);  // Set interrupts for pins 21 and 23 at bits 5 and 7.  Bits 4 and 6 will be the other pins.

}


int32_t getLeftMotorCount(){
	int32_t retval = 0;
	// Disable interrupt
	cli();
	retval = leftCounter;
	sei();
	return retval;
}

int32_t getRightMotorCount(){
	int32_t retval = 0;
	// Disable interrupt
	cli();
	retval = rightCounter;
	sei();
	return retval;
}

In this code I’m only interrupting on one of the two pins from each encoder (the pin masked by INT_MASK) and the other pin is just read to see which way the encoder is going (the B_MASK)

This would be easy to extend to 8 if you had a Mega instead of an UNO so you could get a full 8 pin wide port. You could do 4 encoders each on two ports. Or even all the A pins to one port and all the B pins to another so you could just XOR them and mask with who_fired.