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

Thread: Teensy2.0 pinouts and Rotary Encoders

  1. #1

    Teensy2.0 pinouts and Rotary Encoders

    I have a Teensy2.0 powering a custom button box - it has 4 rotary encoders and 23 momentary buttons. I want to reconfigure it with less buttons but add another rotary encoder, also use the push-switch capability of the encoders (instead of some of the switches).

    I was told there's only 4 pinouts you must use for the encoders, that's pins 5 to 8, the ones ref. INT0, INT1, INT2, INT3, is this correct? and will limit the number of rotary encoders to 4 max? Currently the 3 encoders are wired to pins 4 & 5, 6 & 21, 7 & 9, 8 & 10.

    Will the Teensy2 let me wire in a 5th rotary encoder and if so which pins will I need to use?

  2. #2
    I recall this:
    // Change these pin numbers to the pins connected to your encoder.
    // Best Performance: both pins have interrupt capability
    // Good Performance: only the first pin has interrupt capability
    // Low Performance: neither pin has interrupt capability

    Not tried the low performance option but the project does not really need high precision.

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,973
    Don't really play with a Teensy 2.0 so not 100% sure. But according this: https://www.pjrc.com/teensy/td_libs_...r.html#polling. The 2.0 only has 4 interrupt pins you can use: 5, 6, 7, 8. So if you want:
    Option 1: Best Performance: Both signals connect to interrupt pins. You are going to be limited to only 2 encoders on interrupt pins pairs 5,6 and 7,8
    Option 2: Good Performance: First signal connects to an interrupt pin, second to a non-interrupt pin. This option should allow you to use 4 encoders since there will only be 1 interrupt pin per encoder.
    Option 3: Low Performance: Both signals connect to non-interrupt pins, See details on the web page referenced up.

    So since you want to use 4 encoders you can try option 2. Where one of the pins on each each encoder is attached to one of the T2.0 interrupt pins, the second encoder pin can then be attached to unused pin. Don't think you are going to be able to add a 5th encoder and still use the encoder library with interrupts. You may want to consider upgrading to Teensy LC or T3.2 or better.

  4. #4
    Thanks for your response - as per my first post - I am currently using 4 encoders - (option 2, 1 INT per encoder, which works fine ), I'm not sure if a Teensy2 can handle a 5th encoder not having access to any interrupts. I wondered if any one had tried it and succeeded before I go for an upgrade with more INT pins available.

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,973
    Did you see the last sentence in my post:
    Quote Originally Posted by mjs513
    Don't think you are going to be able to add a 5th encoder and still use the encoder library with interrupts. You may want to consider upgrading to Teensy LC or T3.2 or better.
    To be honest your wiring didn't register with my mind when I read your post, sorry for the miscommunication.

  6. #6
    Thanks, I'll look into this, but I may take apart my current button box if im feeling brave, and just try a 5th rotary on non-INT pins.
    My other option is to try and port it all over to a Pi Pico I bought last week but at the moment I'm really struggling to get my head round micropython and see if I can get the pico to work as USB gaming controller with a 5 x 6 button matrix.

  7. #7
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    79
    @Sprool You may want to move up to a Teensy 4.1. I am running 9 mechanical and two optical encoders as well as 19 buttons (using two MUX boards from SparkFun). All encoders use interrupt pins and they are all very reliable. @Luni has written an encoder library (EncoderTool) that allows the use of multiplexers with encoders, allowing even more encoders on fewer pins.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,110
    If your buttons aren't already wired in a matrix, just using a Teensy 3.5, 3.6 or 4.1 with a lot more pins might be the best path. Pushbuttons vary in quality, but many of them aren't very good at being resoldered & reworked.

    The non-interrupt encoder support usually works well with ordinary low resolution mechanical encoders, but only if the rest of your program avoids any delays. If you're scanning a key matrix, you probably have some delays inside that code. Depending on how that code is designed, it might be doing things in a complex but good way where it checks for elapsed time and avoids delaying the rest of your code. Or it could be imposing delays on everything else. How well the non-interrupt encoder reading works in practice depends on all the rest of your code.

    If you need more interrupts but not a lot more pins (buttons using a matrix or I/O expander) then Teensy LC might be a good approach.

  9. #9
    Good info - thanks for the input. I'm sticking with the windows max 32 buttons for game controller, so 6 x 6 matrix will cover this, looks like a teensy LC might be the best option, unless I can find a similar code to get the Pi Pico to do the same thing.

  10. #10
    Am I ok with the Teensy LC pins - Im going to be needing total 10 INT pins for the rotary encoders and 10 gen purpose pins for the other switches & buttons (matrix array)?

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,110
    Teensy LC has 24 pins on the outside edges, plus a few more on other pins.

    18 of those 24 support interrupts. So sure looks like Teensy LC can meet this 20 pin need, with 7 pins left over.

  12. #12
    Great, thanks again Paul for your speedy input!

Posting Permissions

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