I'm new to the forum and i hope i post my question at the right place.
I took apart my Akai MPK25, to use it's part to build my own midi controller. It has some rotary knobs, which i thought were rotary encoders. After some internet-research, i found out, that they're actually dual 2.5KB rotary potentiometers, just like this one:
I couldn't find a datasheet or any useful information in the internet and have no idea how to hook them up and how to write a code, so i can use them just like a rotary encoder.
A pot is a resistance and is measured as a Voltage at he Arduino. A rotary encoder is a seriaes of on/off signals and is measured using 2 digital inputs at the Arduino. They are fundamentally different.
A dual pot means that there are actually 2 pots attached to the same shaft, so if you know how to use one pot with the Arduino then you should be able to use this device.
If you want to use a rotary encoder then you should just buy one. They are available for about $1 on eBay.
Well, since i already took apart my Akai and got them lying in front of me, I still try to use them instead of ordering some encoders. Maybe my question was a bit confusing. I know the difference between a rotary encoder and a potentiometer. What I meant by "using them like a rotary encoder", is that i want to increase or decrease the midi control value when i start turning the knob, regardless of its current position. That's the way they worked on the Akai controller.
So if I understand correctly, as i turn this dual pot one resistance increases while the other decreases?
So if I understand correctly, as i turn this dual pot one resistance increases while the other decreases?
You basically have 2 pots working off the same shaft. Usually used in stereo systems for input to both channels at the same time.
How they work depends on how you wire up the ends of the pot and the wiper. You really just need to connect a multimeter to the pins and work out which 3 pins are related on the pot.
I'm new to the forum and i hope i post my question at the right place.
I took apart my Akai MPK25, to use it's part to build my own midi controller. It has some rotary knobs, which i thought were rotary encoders. After some internet-research, i found out, that they're actually dual 2.5KB rotary potentiometers, just like this one:
I couldn't find a datasheet or any useful information in the internet and have no idea how to hook them up and how to write a code, so i can use them just like a rotary encoder.
I'm really glad if someone can help me.
Your link show a single pot, not a dual. As a bit of information for future use, dual pots may be either both operated by the same shaft, or concentric, with one shaft inside the other. The outer shaft operated the front pot and the smaller inner shaft controls the back pot.
Paul_KD7HB:
Your link show a single pot, not a dual.
The product description says it's a dual pot but a dual pot (potentiometer) would usually have six pins like this (excluding the earth screen). I think the photo is of a rotary encoder.
I have also used these potentiometers from a salvaged Akai mpd.
These potentiometers have two wipers that are 90 degrees out of phase with each other, so the combination of the two enables you to determine the position of the pot.
From the front view, pin 1 and pin 3 are the wiper terminals. Pin 2 is VCC, pin 4 is ground.
I have made a library class for up to 4 encoders, connected to an 4051 analog multiplexer.
#include <Wire.h>
#include "Arduino.h"
#include <analogmuxdemux.h>
#define ENCNUMBER 3 // number of encoders connected
#define SENSITIVITY 8
class mpdencoder
{
private:
int potTable[ENCNUMBER][2] = {{0, 3}, {2, 1}, {6, 4}}; //location of potentiometers on 4051 chip // {5,7} disabled
int pinS0;
int pinS1;
int pinS2;
int pinX;
int rotationA[ENCNUMBER];
int rotationB[ENCNUMBER];
int rotationMeanOld[ENCNUMBER];
int rotationMeanNew[ENCNUMBER];
long teller[ENCNUMBER];
int sensorValueA[ENCNUMBER];
int sensorValueB[ENCNUMBER];
int difference[ENCNUMBER];
AnalogMux encoder;
public:
mpdencoder(int pinS0, int pinS1, int pinS2, int pinX);
void init(int pinS0, int pinS1, int pinS2, int pinX);
long lees(int i);
};
mpdencoder::mpdencoder(int pinS0, int pinS1, int pinS2, int pinX) : encoder(pinS0, pinS1, pinS2, pinX) {
};
long mpdencoder::lees(int i) {
sensorValueA[i] = encoder.AnalogRead(potTable[i][0]);
sensorValueB[i] = encoder.AnalogRead(potTable[i][1]);
/////////////////
if (sensorValueA[i] < 512) { // 90 - 270 graden
if (sensorValueB[i] < 512) { // 180 -270 graden
rotationA[i] = 180 + (sensorValueA[i] * 0.1759);
rotationB[i] = 270 - (sensorValueB[i] * 0.1759);
}
if (sensorValueB[i] > 512) { // 90-180 graden
rotationA[i] = 180 - (sensorValueA[i] * 0.1759);
rotationB[i] = 270 - (sensorValueB[i] * 0.1759);
}
}
if (sensorValueA[i] > 512) { // 0-90 of 270-360
if (sensorValueB[i] < 512) { // 270 -360 graden
rotationA[i] = 180 + (sensorValueA[i] * 0.1759);
rotationB[i] = 270 + (sensorValueB[i] * 0.1759);
}
if (sensorValueB[i] > 512) { // 0-90 graden
rotationA[i] = 180 - (sensorValueA[i] * 0.1759);
rotationB[i] = (sensorValueB[i] * 0.1759) - 90;
}
}
/////////////////////////////
/////////////////
rotationMeanNew[i] = rotationA[i];
// rotationMeanNew[i] = (rotationA[i] + rotationB[i]);
// rotationMeanNew[i] = rotationB[i];
int difference = rotationMeanNew[i] - rotationMeanOld[i];
if ((difference != 0) && (difference > - SENSITIVITY || difference < SENSITIVITY)) {
if (difference > 0) {
teller[i]++;
} else if (difference < 0) {
teller[i]--;
}
rotationMeanOld[i] = rotationMeanNew[i];
}
return teller[i];
};
There is some dutch in it, but i think the general idea should be clear.
To me, these pots feel way better compared to conventional cheap rotary encoders.
It uses x y coordinates plane, so simply you must set up zero point (511) and calculate the angle between point(x,y) and that zero point.
So the formula for an angle in Radians: atan2(PositionX-511, PositionY-511) then it is divided by pi to express it in percents then multiplied by value of your choice (i used 5000 for precission) (360 will stand for degrees) . Since the value is negative and positive, for fast mapping the I added maximum value (5000) so in the final output i will have 10000 units expressing amount of rotation.