The build
At the end of my first semester of Mechatronics at the University of Waterloo, we were assigned a LEGO Mindstorms NXT design project. We met the requirements in a day, so a partner and I decided to build a LEGO CNC mill, inspired by one on YouTube.
Three motors drive the X, Y and Z axes, each with a touch-sensor limit switch for homing. A separate high-speed LEGO motor spins a 1/16-inch drill bit through floral foam, which is soft enough to cut like butter.
Control
LEGO motors have built-in encoders, and with our gearing one tick was about a thousandth of an inch. After testing several approaches, a feedforward plus PD controller held the average error under one tick. Cutting forces in foam are tiny, so a simple controller worked well.
G-code, and running out of memory
G-code is well documented and straightforward to interpret, but files for complex parts were far too large for the NXT’s memory, even with custom compression. So we ran a Python server on a laptop that fed the NXT file chunks one at a time, watching for each chunk to be consumed and keeping one buffered.
Control path
- InputG-code file
- StreamingPython serverOn a laptop, streams file chunks as the NXT needs them
- InterpreterNXT interpreterDecodes G-code moves
- ControlFeedforward + PDOne loop per axis
- AxesX · Y · Z motorsPlus a high-speed spindle
Mechanics
We shimmed the linear rails to take up slack, used chain in the gear reductions for lower backlash, and built the frame rigidly to avoid low-frequency vibration. The finished machine carved an Iron Man head in about three and a half hours.




