Is there a way to use a potentiometer instead of an encoder? MIDI and MCU

yes I do


0
0
8
13
20
23
27
36
48
89
112
131
195
230
366
751
941
1023
1023
1023
699
570
305
205
150
130
90
46
35
12
0
0
0

I am trying to replicate what a digital Avid C24 mixer can do. It has some analog parts and some digital. the Gain control was digital with a potentiometer rather than an encoder.
The signal panning was used with an encoder but as you can map a potentiometer for the pan I should be able to replicate that if it wasn't that I can only go either right or left.

I use RK09L1140A5E potentiometers which AFAIK are linear

isn't the pot read within the library I am using?

so if you run this, do you see anything?

#include <Control_Surface.h>

USBMIDI_Interface midi;
CCPotentiometer potentiometer{ A0, MIDI_CC::General_Purpose_Controller_1 };

analog_t echo(analog_t raw) {
  Serial.println(raw);
  return raw;
}

void setup() {
  potentiometer.map(echo);
  Control_Surface.begin();
  Serial.begin(115200);
}

void loop() {
  Control_Surface.loop();
}

Should I see anything different? on the serial you can see it converts the signal the max value of 16383.

If you run a software like MIDI monitor, you'll see the potentiometer doesn't react as it should. if you rotate it to the right or the left it will go to max value. Specially when using V_POT_1 I'm guessing it expects to see a + or - from an encoder.

I'm sorry, I am trying to understand if I should see something different.

What do you see? The numbers between 0 and 1023?

I see values between 0 and 16383

Same discussion on GitHub:

1 Like

Ok So the pot and the library work fine and deliver the expected 14 bit sampled value.

I’m confused on your goal:
Do I get right you want this to send a +1 or -1 signal (what happens when you are at the end points) or do you want to send a fixed value within a range?

Yes, so pretty much that's the correct approach. +1 or -1 and want to send fixed values within a range so I am trying now to map the end since the portion I need to send is much smaller seems to be smaller although although for now I haven't been able to map it yet

+/- 1, suggests the result should simply indicate whether the pot changed, was rotated clockwise or counter-CW

fixed suggests just returning the pot position possibly scale from 0-100 using map()

sounds like you want both. ???

Maybe I didn’t explain myself correctly. The library works perfectly.

The approach needs an analogue pot using -1 and +1 like an encoder as it iss controlled usually by an encoder and it now works.

The element I’m trying to control it seems to be using less that 0 to 100% of the potentiometer so now I am trying to expand that. So if, let’s say, it’s 0 to 70% now I need to make it (map it?) 0 to 100%

this is so confusing.

why do you need it mapped to 1-100 if you want +/-1 and 0?

if you want a +/-1. measure the pot value, whatever it is (0-10000), compare it to the previous value and return zero if it is the same, +1 if > and -1 if <.

what am i misunderstanding?

The element I want to control is controlled with +/-1 and it had a beginning and an end.
Even if it was an encoder and I keep turning right it would it won’t go any further after the maximum it has. That maximum when translated to the pot goes up to about a 70% of the Pot rather than going up to the 100% use of it

both ?? :confused:

OK, so the element will just ignore a +1 if it's at the top range or a -1 if it's at the bottom range.

assume the pot reading on A2 is 450 (using the standard [0, 1023])
you turn the pot and it reads 490, do you want to send +1 or +40 ?

Say now you reboot at the pot is at 490 and you want to increase again , you move it to 900.
Say now you reboot at the pot is at 900 and you want to increase again , you move it to 1023.

now at the next reboot you are stuck and can't go up

sounds like (again not clear), that you want to use the pot like an encoder that inc/decrements some value between some min/max.

of course, such an approach doesn't matter what the initial value and can be inc/decremented between the 2 extremes because there is no limit to the encoder. if the value starts at the max, it can be decremented to the min and conversely

this is, of course a limitation with the pot, in 2 ways: the first is that is may be near its max position when the value is at the min can it is difficult to adjust it some minimal amount resulting in enough +1s to increment the value much beyond min

the second is that it can be quickly turned such a large amount, resulting in a +1 to use up most of its range

is this your understanding of the limitations of using a pot like an encoder?

The second limitation you point our is the solution to the first limitation.

a7

hows so?

presumably your suggesting that if the pot is near max and the value near min, the pot can be quickly turned to min to reset it's position

May be it would be better in the first step to forget about the code ( encoder or pot ).
Tell us what you want to control with your knob if you turn it right or left. Is it a MIDI controller or something the like?
There are usecases where it is easy to change from encoder to pot, and there are usecases where it is nearly impossible.

To be honest, I don't believe that. I think your element is controlled by a fixed value between max and min. And with an encoder this value is changed by +/- 1 with every tic. With a pot you don't need +/-1, you get that value directly by mapping the analog value to the needed range of min and max.

1 Like