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

Thread: Unable to get Rotary Encoder to work with my Teensy 3.5

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    4

    Unable to get Rotary Encoder to work with my Teensy 3.5

    I am trying to get my rotary encoder to work with my teensy 3.5 however I am pretty confused, it's been a few years since I have used a rotary encoder, but I don't remember having any issues like this in the past.

    So I have a teensy 3.5, and this 7 way switch rotary encoder ... https://opensimracing.com/products/funky-switch-7-in-1

    I first wired it up like this...
    Click image for larger version. 

Name:	rot_encoder.jpg 
Views:	12 
Size:	67.7 KB 
ID:	18366

    But then upon further reading I think this is more correct, not entirely sure...
    Click image for larger version. 

Name:	rot_encoder_2.jpg 
Views:	20 
Size:	71.8 KB 
ID:	18367

    Not sure if either of those are right, because I still cant get anything to work...

    Here is the code I am currently working with, however I have tried several different iterations of this...

    Code:
    #include <Encoder.h>
    
    Encoder enc(8,9);
    
    long current_value;
    long previous_value = 999;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      current_value = enc.read();
    
      if (current_value != previous_value) {
        Serial.println(current_value);
        previous_value = current_value;
      }
    }

    It pretty much always assumes to position is 0, so any help is appreciated

  2. #2
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    122
    Hi Semaj4712,

    When I looked at the product webpage you linked to, I saw that the pinout in silkscreen on the shown switch differs from the switch pinout that you showed in the diagram.
    Look at the position of the GND pin:

    Click image for larger version. 

Name:	switch pinout.png 
Views:	11 
Size:	116.7 KB 
ID:	18368

    Could that be the problem? Do you happen to have a datasheet of the switch?

    Regards,
    Paul

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    4
    Quote Originally Posted by PaulS View Post
    Hi Semaj4712,

    When I looked at the product webpage you linked to, I saw that the pinout in silkscreen on the shown switch differs from the switch pinout that you showed in the diagram.
    Look at the position of the GND pin:

    Click image for larger version. 

Name:	switch pinout.png 
Views:	11 
Size:	116.7 KB 
ID:	18368

    Could that be the problem? Do you happen to have a datasheet of the switch?

    Regards,
    Paul
    Hey Paul, your absolutely correct, I used the larger picture as a reference for the schematic, but on my breakout board, the GND is actually more in the middle like in the picture you posted. I think that is correct since I have no issues with the pushbutton functions

  4. #4
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    122
    Hi Semaj4712,

    Did you perhaps measure the encoder pins to see what is happening? A scope is very useful to see the voltages and timing relation between those pins.
    With respect to the external pullups; the encoder library also enables the internal pullups on the chip so external pullups shouldn't be necessary [but it wouldn't hurt either to add 3K3's like you showed].

    Regards,
    Paul

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    4
    Quote Originally Posted by PaulS View Post
    Hi Semaj4712,

    Did you perhaps measure the encoder pins to see what is happening? A scope is very useful to see the voltages and timing relation between those pins.
    With respect to the external pullups; the encoder library also enables the internal pullups on the chip so external pullups shouldn't be necessary [but it wouldn't hurt either to add 3K3's like you showed].

    Regards,
    Paul
    I actually was able to get this to work, I realized that if I swap the GND and PUSH pins on my board, that it actually worked, and then when I reached out to the company, they admitted that they sent me V1 of the boards by accident and the pin labels are backwards.

    Everything seems to be working now, although i have not finished my code to make sure.

    If I have futher issues I will let you know

  6. #6
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    122
    Thinking this switch may be useful for one of my future projects, I searched further on the internet.
    Is this the switch? ALPS RKJXT1F42001.
    The circuit diagrams on that page may help you in debugging the circuit.

    Regards,
    Paul

  7. #7
    Junior Member
    Join Date
    Dec 2019
    Posts
    4
    Quote Originally Posted by PaulS View Post
    Thinking this switch may be useful for one of my future projects, I searched further on the internet.
    Is this the switch? ALPS RKJXT1F42001.
    The circuit diagrams on that page may help you in debugging the circuit.

    Regards,
    Paul
    That is the data sheet I had found as well, which fixed a lot of my issues I initially had with the switch.

Posting Permissions

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