Hello dear friends.
Please bear with me as im not a native english speaker and it gets kind of hard for me to express my thoughts effectively.
Im trying to build myself a custom midi controller for my mixing tasks. Given controller would ideally have 16 pots but im starting with just 2 or 3 as a proof of concept and then will scale accordingly. And decided that i want to have rotary encoders instad of single turn pots.
After looking for suitable rotary encoders, i discovered that most cheap ones output 24 ppm at the most which is definitely not enough resolution for providing an expressive control over my music software.
So i came up with the idea of hacking a stacked potentiometer (normally called pan pot, at least here where i live, basically two wafers connected to a single shaft) into a continuous rotation potentiometer so it can act as a rotary encoder.
What i did is open up the thing and remove the lower wafer and then remove the end stop of the case so that both wipers could do a 360 continuous turn. As you would expect, when the wipers end their normal rotation, the signal is lost as the conection between the outer ring and the middle pin is lost and the analog input starts to float.
So what i did is to realign one of the wipers about 90 degrees out of phase from the other one so that there is always a valid signal on at least one of the two analog inputs.
That seemed to work. and when plotting the analog ins what i got is two sine-ish, saw-ish similar looking waves which ran out of phase from each other and when each one reached the top or bottom there would be a gap for a few ms and then signal would come up from the other end (i hope i am making sense), When one input reached the the top or bottom the other was in the middle area rising or decreasing depending on the direction in which i moved the pot. So i thought i could code something that would help me discriminate one of the two signals when it reached the top or bottom and then dettect the direction of the remaining signal as to determine if a change to a higher value was required.
What i came up with is this scheme:
#include <MIDI.h>
int v1 = 0;
int v2 = 0;
int d1 = 0;
int d2 = 0;
int t = 0;
byte cc = 10;
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
MIDI.begin();
Serial.begin(115200);
}
void loop() {
if((analogRead(A0) > 10) or (analogRead(A0) < 1020)) {
if (analogRead(A0) > (v1 + 3) ) {
if (analogRead(A0) > (v1 + 20) ) {
d1 = -1;
} else {
d1 = 1;
}
v1 = analogRead(A0);
} else if (analogRead(A0) < (v1 - 3)) {
if (analogRead(A0) < (v1 - 20)) {
d1 = 1;
} else {
d1 = -1;
}
v1 = analogRead(A0);
} else {
d1 = 0;
}
} else {
d1 = 0;
}
if((analogRead(A1) > 10) or (analogRead(A1) < 1020)) {
if (analogRead(A1) > (v2 + 3) ) {
if (analogRead(A1) > (v2 + 120) ) {
d2 = -1;
} else {
d2 = 1;
}
v2 = analogRead(A1);
} else if (analogRead(A1) < (v2 - 3)) {
if (analogRead(A1) < (v2 - 120)) {
d2 = 1;
} else {
d2 = -1;
}
v2 = analogRead(A1);
} else {
d2 = 0;
}
} else {
d2 = 0;
}
if ((d1+d2) > 0) {
t++;
MIDI.sendControlChange(cc, 65, 1);
} else if ((d1+d2) < 0) {
t--;
MIDI.sendControlChange(cc, 63, 1);
}
/*
Serial.print(1024);
Serial.print(' ');
Serial.print(0);
Serial.print(' ');
Serial.print(t);
Serial.print(' ');
Serial.print(analogRead(A1));
Serial.print(' ');
Serial.println(analogRead(A0));*/
}
And it seems to work. But the thing that botters me is that even after engaging the internal pull up resistor as to avoid floating inputs i steel get some minor jitter whenever one of the wipers leaves the resistive track. If after moving the pot i accidentaly leave the wiper in the wrong place the signal can move erratically thus sending undesired midi messages.
I would love to know if you my friends could help me solve this problem, as i've spent a lot of time trying to come up with a solution to no avail. Im really no electronics expert and have been experimenting with arduino for about 3 months. This is the first big project im trying to complete and it would mean a lot to me if you could point me in the right direction to eliminate the jitter.
Any help is appreciated.
Kind regards.
O5