How to connect 5 volt incremental optical encoder with differential output to ESP32 Devkit V1?

Hello so I'm looking at this Nema17 with an incremental encoder attached for my inverted pendulum project (it's taking forever to finish LOL).

After researching, apparently since its encoder output is 2 channels differential (not really sure what that means) I need an receiver to take translate the differential from each channel and convert to 3.3 volt for esp32 GPIO. I was looking at this MAX3485 as an option. I think I need 2, one for each encoder channel. I just wanted to double check these components are correct since I don't know what differential output means. Thank you for any information or clarification

The encoder description could be better.
But common sense says 2x max3485 would likely work here.

Sorry it just says 2 channel output differential. But I don't really know what that means. Thanks for the confirmation

Hi, @sliferslacker19
Do you have a scope.

I think you will find that just using EA+ and EB+ terminals with respect to gnd will give you the signals you need.
The pulses will be 5V, what controller are you feeding the signals to?
You may need a potential divider on each the two channels if the logic is 3V3.

Differential means that EA+ and EA- are the same signal, but when one is low the other is HIGH and vice versa.
The same for EB+ and EB-.
Did you Google to ask?

Tom.... :smiley: :+1: :coffee: :australia:

The two channels are in quadrature, that is the square wave output of one is shifted by 90° so the direction of rotation can be determined. There are 4000 pulses per revolution.

A differential (RS-422 style) output is not directly compatible with ESP32 GPIOs - it needs a line receiver first. AM26C32 / 26LS32 is the usual part: it converts A+/A- and B+/B- into single-ended 3.3 V logic. The receiver output then goes straight to two ESP32 pins (no divider needed, since it runs from 3.3 V).

Practical points from my own encoder wiring:

  1. Terminate the pair with 120 ohm at the receiver end only. Without it, edges ring and you get double counts at higher RPM.
  2. Use twisted pairs for A+/A- and B+/B- separately; running A and B in the same pair causes crosstalk phase errors.
  3. Add 100 ohm series + 100 pF to ground at the ESP32 pin if the cable is longer than ~2 m.
  4. The receiver has an enable pin - tie it active, and add a 10 k pull-up so it does not float during power-up.
  5. For counting in software, use the ESP32 PCNT peripheral rather than interrupts; at 1000 CPR x 3000 RPM interrupts start dropping counts.

If the encoder is 5 V single-ended rather than differential, then it is just a level question: 5 V into ESP32 needs a divider or a 74LVC245 running at 3.3 V.

Which encoder model are you using, and what cable length? That decides whether termination alone is enough.

When I don't understand a term, I use a search tool called Google. Do you have that?

That is totally wrong
Both the encoder and IC need 5V, so don't try this with a 3.3V microcontroller.

@sliferslacker19

That is totally wrong
Both the encoder and IC need 5V, so don't try this with a 3.3V microcontroller.

@yjeie_suzhou post seems to be AI generated spam.

How far will the encoder be located from the Arduino? If less than 4 or 5 meters, you probably don't need differential outputs. As @TomGeorge said, just leave the A- / B- outputs floating or pull down with 10k resistors.

Yes they will work fine and yes you need two but remember the encoder Vcc must be 5V.

And don't forget the level shift down to 3.3V (if required ?).
I'm not familiar with ESP32 Devkit V1, input pins may be 5V tolerant
. ???.

Not needed with the adapters chosen by @sliferslacker19

esp32, what do you mean by scope?

I'm not sure how long the cable is, doesn't seem to say on the site. So I only need the A+ and B+ signals to read the encoder?

Yea I was planning to power that with my esp32 5 volt pin

Yes, that's correct. According to your initial link, the stepper on line motors with the integrated encoder come with 500 mm cables. Unless you have are planning to extend them you can use only one pair

I don't think your answer is sufficient for OP. He has 5V "differential signal" to be measured by 3.3V Esp32. Either he uses his max3485 with both +/- wires connected or he needs to experiment the signal through level shifters.

From the datasheet of the stepper motor , it can be seen that the 'step angle' is 1.8°. Hence the stepper motor does 200 steps per revolution.

The encoder gives 1000 pulses per revolution. This means that there are five pulses from the encoder per step.

If you just do a single step then there is going to be a burst of five pulses, at a rate determined by how fast the motor does that single step.

What happens when the motor is doing multiple steps?
Do the encoder pulses come in bursts of five pulses with a gap before the next burst of five pulses, or does the inertia of the rotor tend to even out the pulse rate?
I'm wondering whether you need to use micro-stepping so that the pulses are more evenly spaced.

Then no problems.