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

Status
Not open for further replies.

FrancisYountr

New member
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!!
 
When asking questions, it helps to provide links to the device you want to use. Is it this one?

https://www.usdigital.com/products/encoders/incremental/rotary/kit/E2

And is there any reason why the default encoder library will not do what you want?
https://www.pjrc.com/teensy/td_libs_Encoder.html
see also
https://playground.arduino.cc/Main/RotaryEncoders

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
 
I will be using this encoder: https://www.usdigital.com/products/encoders/incremental/rotary/kit/E5
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.
Thanks!
 
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.
 
Status
Not open for further replies.
Back
Top