Wiring
| Sensor | | Goes to | Note |
| 1 — Vcc | → | +5 V rail | Its own supply. The MDrive's I/O power pin is an input, not a source — it cannot feed these. |
| 2 — L | → | Vcc, or open | Tied to Vcc = Light-ON. Open = Dark-ON. |
| 3 — OUT | → | 3 / 4 | P1 pin 3 (I/O 1) for one end, pin 4 (I/O 2) for the other. |
| 4 — GND | → | 2 | P1 pin 2, I/O ground. The 5 V supply's return lands here too. |
Bench check before you commit. Do not trust the terminal numbering from a
photograph. With the sensor off the rail, feed it 5 V from a supply current-limited to about
20 mA on terminals 1 and 4, leave L open, and watch the red indicator: it should light when you put
something opaque in the slot. If it does not light either way, kill the supply and re-check the
orientation rather than turning the voltage up.
Making them limits
Three MCode lines over the serial link, then a save. S<n> takes type, active state and
sink/source: type 2 is Limit +, type 3 is Limit −, and the third parameter 0 means sinking,
which is what an NPN output wants.
S1=2,1,0 ' I/O 1 = Limit +, active HIGH, sinking
S2=3,1,0 ' I/O 2 = Limit -, active HIGH, sinking
LM=2 ' any limit decelerates all motion to a stop
S ' save to NVM
Active HIGH with Light-ON is the fail-safe combination, and it is worth the
extra thought. Tie L to Vcc so the output conducts while the slot is clear, holding the drive's
input low, meaning “not at the limit”. Now a flag entering the slot releases the input and it
floats high, which the drive reads as the limit being hit — and so does a broken wire, a pulled
connector or a dead sensor. The lazy wiring (Dark-ON, S1=2,0,0) works exactly as well until
something comes loose, at which point the machine cheerfully drives into the end of the rail.
LM picks what happens next: 1 stops only travel in the offending direction, 2 stops all
motion including homing, 3 also halts the running program. Modes 4 to 6 are the same three without a
deceleration ramp. Note that with a ramp the axis keeps moving past the trip point for the length of the
decel, so the flags want to be far enough in from the hard stops to absorb that.
Two things that will catch you
Limits do not exist in clock mode. Setting CM=1 to accept step/direction on P1 pins
13 and 14 disables the limit functions outright. If you go that route the end stops become the ESP32's
problem, which is a solid argument for staying on the serial interface.
You now have two ground paths to the drive. I/O ground is non-isolated and common with power
ground, so tying your 5 V supply's return to P1 pin 2 bonds the ESP32's ground to the motor supply
ground. Comm ground on P2 pin 10 reaches the same place through that internal 100 Ω resistor
whose whole job is to stop the loop. Wire both and you short it out. Pick one: with the end stops sharing
I/O ground, leave P2 pin 10 unconnected — the grounds are already common, so the RS-422 receiver has
its reference. The cleaner alternative is an isolated link (which is what the MD-CC400-001 buys you) and
then Comm ground is the only tie.
If you also want the ESP32 to see the end stops, the open-collector output will happily drive a second
load: run it to a GPIO with a pull-up to 3.3 V. Pull up to 3.3 V and nothing higher — the
sensor can switch 24 V, and the ESP32 cannot survive it.