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

Thread: How to program US Digital optical encoder kit with Teensy 3.5?

  1. #1

    How to program US Digital optical encoder kit with Teensy 3.5?

    Hello Everyone,
    I have been trying to program a code that can read the US Digital Optical Encoder Kit and give me the angle that the encoder has moved.
    Could somebody please give me an example of a code to do this and perhaps explain it to me?
    Thank you!!

  2. #2
    Senior Member
    Join Date
    Apr 2013
    When asking questions, it helps to provide links to the device you want to use. Is it this one?

    And is there any reason why the default encoder library will not do what you want?
    see also

    If not it would be good to explain why

    These are non standard electrically compared to mechanical encoders that may make a difference if you dig into it, and they also appear to have an index pin which may or may not make a difference depending on what you are doing.

    edit: these appear to be a 5V device, should be OK with a T3.5 but plan accordingly if moving to a T3.6

  3. #3
    I will be using this encoder:
    It has 2048 individual demarcations, making one mark moved ~ .176 degrees.

    When looking through the two websites above, as well as various others, I hadn't come across a program which displayed the specific angle the encoder wheel turned in either the positive direction( clockwise) or the negative direction( counter-clockwise).
    I am also confused as to what an index pin is, and what it does to help read the encoder.

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Encoders only report steps from starting position which will be unknown so you cannot output an angle, hence the libraries only report steps. If you know the steps the conversion to angle is trivial - see below

    The Index pin appears to mark a zero point.

    So your code will most likely involve pretty much any of the libraries, possibly modified to turn off pullups
    Starting the encoder processing
    Setting up to monitor the index output on a pin, preferably with an interrupt
    Waiting until the index pin triggers (encoder will need to be moved through full range by whatever it is connected to)
    Zero the encoder count
    From there your angle is (encoder count%2048)*.176 though check that is actually the case once you have the hardware and work out how to handle your rounding errors (otherwise you may have oddities going from 359 to 0)

    Given encoders can miss steps for various reasons if this is mission critical you will also need to keep monitoring index and handling the situation where it triggers when not at zero, simple resetting of the count to zero will work but may have unpredictable results on down stream equipment so think about what happens in this case.

    You also need to work out how the 'rotate full cycle to find index' works in your setup process without having side effects.

  5. #5
    Thank you very much.
    I will attempt to try out the things that you have stated above and I hopefully will get it to work.

Posting Permissions

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