Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: Read Endless Potentiometer

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    9

    Read Endless Potentiometer

    Hello, I've been working on a Midi Controller project and after a lot of reserach I found that:

    - I don't want regular analog potentiometers because I don't want a fixed value so I can change parameter and not mess up the current value.
    - I don't want digital encoders because of their low resolution on affordable models.


    So I came up with this

    https://www.mouser.es/ProductDetail/...gYyB27TqoGq8Q=

    This are the same or very similar as the ones that Maschine MK3 uses and I really like the feel. I found them contacting with this great guy.

    https://www.youtube.com/watch?v=q2ax...A&index=6&t=0s



    So my question is, How do I read properly this with the Teensy LC that I have. I want to have increments or decrements.
    I connected the potentiometer correctly and I get the two values, one delayed from the other.

    This is the behaviour of the potentiometer:

    Click image for larger version. 

Name:	Capture2.PNG 
Views:	42 
Size:	56.9 KB 
ID:	19206


    This is what I got on the serial:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	38 
Size:	14.4 KB 
ID:	19207


    This is the code so far:


    int val6, val5;

    void setup()
    {
    Serial.begin(38400);

    val6 = analogRead(6);
    val5 = analogRead(5);
    }


    void loop()
    {
    delay(250);
    if (abs(val6 - analogRead(6)) > 10) {

    val6 = analogRead(6);
    val5 = analogRead(5);


    Serial.print("values: ");
    Serial.print(val6);
    Serial.print(" / ");
    Serial.println(val5);
    Serial.println("");

    }

    }


    Sorry for the mess, and thanks.

  2. #2
    Senior Member
    Join Date
    Apr 2019
    Posts
    110
    Hello, you piqued my interest with this post. There's obviously a correct way of coding this, that's neat and no doubt, mathematical. I don't have the exact answer, but this is a form of absolute rotary encoder called a resolver, I think. And it's designed so that angle can be read. They are based on two coils 90deg apart to produce two analogue signals - a sine wave and a cos wave, and the idea is to take the arctan(sin output/cos output) to get the angle.

    The potentiometer has two linear tracks that approximate this. So it can probably be treated the same way. Then once you have the 'angle', compare it to a previous value - in theory. There are ICs for this purpose it seems, but to read one turned by hand with a Teensy should be possible.
    Last edited by UHF; 02-29-2020 at 12:25 AM.

  3. #3
    a good place to start would be with something like
    Code:
    float angle = atan2f(val5, val6);

  4. #4
    Senior Member
    Join Date
    Apr 2019
    Posts
    110
    Having watched the video at 12:00, the Maschine MK3 seems to just have a normal (detent-less? - non-clicking) encoder. Arturia use these on their products like the Minilab. They rotate freely with some grease inside to give a bit of resistance. I would just use one of these.

  5. #5
    edit. never hear about these endless pots, very intriguing, knobs on my NI keyboards feel great. i spend a good while finding the best rotary encoders for my synth build.. fwiw if you wanna order samples, the ALPS are worth the extra $ over the bourns imho, feel much sturdier and more like a pot. i am happy with those.
    the resolution on encoders can be misleading because in most cases you will have to implement some kind acceleration on the software side anyways.

    UHF - yeah these look like encoder but its atually the part nazori posted
    Last edited by weasel; 03-02-2020 at 01:49 AM.

  6. #6
    Junior Member
    Join Date
    Feb 2020
    Posts
    9

    Working on it

    Thanks very much, UHF and MarkzP. I will try to do the conversion to angle and work from there. I will keep you updated.

  7. #7
    Junior Member
    Join Date
    Feb 2020
    Posts
    9
    Yeah I was having the same problem until I found about this. I really didn't like the enoders from arturia at least the MiniLab ones, the resolution was very low and you had to do several whole laps to get the parameter cover.

    Sorry for my bad english, I will keep you update, this week I hope to advance a lot.

  8. #8
    Junior Member
    Join Date
    Feb 2020
    Posts
    9

    Angle reading DONE

    I took your suggestions and i did this:

    Code:
    void loop()
    {
      delay(250);
      if (abs((val6 + 500) - analogRead(6)) > 50) {
    
        //I substract 500 because the reading values where 1000 - 0
        val6 = analogRead(6) - 500;
        val5 = analogRead(5) - 500;
    
        //Get the Angle and I transform it to deegres because i'm not that good at radians
        angle = atan2f(val6, val5);
        deg = angle * 57296 / 1000;
    
        //Add 360 because every angle from 180 to 360 are calculated as the negative one
        if(deg < 0){
          deg = deg + 360;
          }
          
        Serial.print("sin:  ");
        Serial.print(val6);
        Serial.print(" / ");
        Serial.print("cos:  ");
        Serial.print(val5);
        Serial.print(" / ");
        Serial.print("Angle = ");
        Serial.println(deg);
        Serial.println("");
        
      }

    And I got the angle correctly:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	26 
Size:	13.5 KB 
ID:	19253


    Now I'm going to see how I translate that into MIDI 0 - 127 and see how ableton behavies to that.

    THANKS

  9. #9
    Junior Member
    Join Date
    Feb 2020
    Posts
    17
    Fascinating knob! Very clever.

    Using arctan will not give the right angles in this case, it works for that resolver since it has sinus waves.

    The solution for this knob is actually very simple:
    Code:
    if(v0 < 50%) 
      angle  = 360 - v1 *180
    else
      angle  = v1 * 180
    v0 and v1 are assumed to be between 0 and 1.0. v0 is the curve that starts in the middle in the datasheet.

    If the unsharp turns at the top and bottom are annoying or the knobs are made with poor precision you would have to use a more intricate method. Perhaps trying to only use the value from v0 or v1 when the are away from the top or bottom. I would guess that to get best precision you would have to calibrate each knob to find the exact points where both pots are equal. That might be overkill in your case.

  10. #10
    Senior Member
    Join Date
    Apr 2019
    Posts
    110
    Yes that looks good:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	17 
Size:	41.2 KB 
ID:	19264

    It goes back in the centre, rather than the end.

  11. #11
    Junior Member
    Join Date
    Mar 2017
    Location
    Australia
    Posts
    13
    Looks interesting. Just an observation but do you really wish to use:
    Code:
    ]analogRead(6);
    Analog pins are more traditional referenced with as "Ax", as in
    Code:
    ]analogRead(A6);
    You may actually be targeting the wrong hardware pin.

  12. #12
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,356
    Quote Originally Posted by LachAus View Post
    Looks interesting. Just an observation but do you really wish to use:
    Code:
    ]analogRead(6);
    Analog pins are more traditional referenced with as "Ax", as in
    Code:
    ]analogRead(A6);
    You may actually be targeting the wrong hardware pin.
    By convention in Arduino (and Teensyduino) A6 is understood when '6' is called for analogRead... handy in control loops where a incremented variable can be used directly in the read.

  13. #13
    Junior Member
    Join Date
    Mar 2017
    Location
    Australia
    Posts
    13
    Quote Originally Posted by oddson View Post
    By convention in Arduino (and Teensyduino) A6 is understood when '6' is called for analogRead... handy in control loops where a incremented variable can be used directly in the read.
    Well there you go; I did not realize that. Thanks for the lesson! Sorry for the derail.

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,345
    Looking at the Teensy card where it shows 'A6' - it is on pin 20, so that can work as well

    Code:
    // A0-A9 are always digital 14-23, for Arduino compatibility
    // ...
    #define PIN_A6  (20)

  15. #15
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,584
    Quote Originally Posted by UHF View Post
    Yes that looks good:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	17 
Size:	41.2 KB 
ID:	19264

    It goes back in the centre, rather than the end.
    The atan2f() function returns values from -pi to pi. So, if you want to convert this range into the 0 to 127 midi interval, you'll have to add pi first to make it cover the interval [0;2pi] and then scale the result to your desired interval.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •