← Course overview
Week 6 of 12 · Mechatronics

Building the Inspector Wheel & Optical Shroud

Design and fabricate the rotating inspection nest, positive D-shaft hub, homing cam, and optical darkroom shroud to present Skittles to the AS7341 spectral sensor.

~6 hrs CAD + Print + Motion Mechatronics

Concept Mechanical Indexing & Optical Isolation

This subassembly combines software, electronics, and mechanical design into a single precision mechanism. The inspector wheel has three critical engineering jobs:

Kit What you need this week

  • Digital calipers & fresh Skittles for measurement
  • Fusion 360 + 3D printer (PLA recommended for optical parts)
  • Week 5 NEMA-17 stepper + VMA327 limit switch rig
  • M3 × 4.5mm heat-set insert + M3 × 6mm grub screw
  • Reference parts: 3D Files/wheel.stl, cam.stl, inspection.stl

Build Step by step

Step 1

Measure your Skittles with calipers

Measure 5 random Skittles across diameter and thickness. You will typically find ∅ 13.0–13.4mm diameter and 6.0–6.8mm thickness. Define your pocket parameters:

pocket_diam = 14.2 mm    # 13.4mm max + 0.8mm clearance
pocket_depth = 7.0 mm   # Full candy thickness
draft_angle = 7.0 deg   # Draft to prevent gravity sticking
Step 2

Model the 4-pocket inspector wheel

In Fusion 360:

  • Sketch a circle ∅ 60mm on the XY plane and extrude 8.0mm.
  • Create a circular pattern of 4 nest pockets at r = 20.0 mm radius. Extrude as Cut with a 7° taper angle.
  • Add a 1.2mm high retaining rim around the outer edge to retain candy under centrifugal motion.
Step 3

Model the D-shaft collar & eccentric homing cam (`cam.stl`)

The inspector wheel must trip the limit switch once per revolution to establish an absolute physical datum ($0.0^\circ$) without using a hard stop that would block continuous 360° forward rotation. On the underside of the wheel (or as the dedicated interlocking part cam.stl):

  • Central Hub Boss: Extrude a central cylinder (∅ 24.0mm base circle, height 12.0mm).
  • D-Shaft Positive Bore: Cut a 5.15 mm D-shaft bore with a 4.5 mm flat edge offset.
  • Transverse M3 Grub Screw Clamp: Add a transverse M3 heat-set insert pilot hole (∅ 3.2mm × 4.5mm depth) perpendicular to the D-flat. Tightening an M3 grub screw against the flat guarantees zero rotational slipping over thousands of cycles.
  • Eccentric Lobe Profile: Model a smooth tangential ramp that rises +3.5mm radially over a 25° angular sweep with $R=4.0\text{mm}$ blend fillets. As the wheel spins, this lobe gently depresses the roller microswitch lever on plate_stepper.stl without mechanical shock or contact bounce.
Step 4

Model the optical darkroom shroud (`inspection.stl`)

The AS7341 sensor board mounts directly above the pocket wheel:

  • Model a rectangular hood that encloses the sensor board with M2.5 mounting standoffs.
  • Position the sensor's optical aperture at a calibrated 8.0 mm focal height above the Skittle's top crown.
  • Add internal light-baffling lips that overlap the wheel without touching (0.8mm air gap), creating a labyrinth seal against ambient photons.
Step 5

Print, assemble & calibrate indexing

Print the parts (black PLA is ideal for the optical shroud to absorb stray light). Install the M3 heat-set insert, slide the hub onto the motor shaft, and tighten the grub screw against the D-flat. Bolt the optical shroud over the assembly.

Step 6

Code the 3-phase homing & 90° indexing routine

Write an automated 3-phase homing routine in Python that eliminates mechanical switch hysteresis and indexes 90° between pockets:

import RPi.GPIO as GPIO
import time
from adafruit_motorkit import MotorKit
from adafruit_motor import stepper

SWITCH_PIN = 20
STEPS_PER_REV = 200  # 1.8° NEMA-17 stepper (200 steps/rev)
OFFSET_TO_POCKET_1 = 14  # Calibrated step offset to center Pocket #1 under sensor

GPIO.setmode(GPIO.BCM)
GPIO.setup(SWITCH_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
kit = MotorKit(0x60)

def precision_home_wheel():
    print("Homing inspector wheel...")
    # Phase 1: Fast Seek forward until cam trips switch (active LOW)
    steps = 0
    while GPIO.input(SWITCH_PIN) == GPIO.HIGH:
        kit.stepper1.onestep(direction=stepper.FORWARD, style=stepper.SINGLE)
        steps += 1
        time.sleep(0.008)
        if steps > 250:
            kit.stepper1.release()
            raise RuntimeError("Homing timeout: Cam switch not found!")
    
    # Phase 2: Slow reverse release to eliminate mechanical hysteresis
    time.sleep(0.05)
    while GPIO.input(SWITCH_PIN) == GPIO.LOW:
        kit.stepper1.onestep(direction=stepper.BACKWARD, style=stepper.SINGLE)
        time.sleep(0.03)  # Slow precision speed

    # Phase 3: Step forward by fixed offset to center Pocket #1 under optical sensor
    for _ in range(OFFSET_TO_POCKET_1):
        kit.stepper1.onestep(direction=stepper.FORWARD, style=stepper.SINGLE)
        time.sleep(0.01)

    kit.stepper1.release()
    print("✓ Wheel homed and Pocket #1 centered under optical shroud.")

def index_pocket(steps_forward=50):
    """Index exactly 90 degrees (50 steps on 200-step motor)"""
    for _ in range(steps_forward):
        kit.stepper1.onestep(direction=stepper.FORWARD, style=stepper.SINGLE)
        time.sleep(0.008)
    kit.stepper1.release()
4-Pocket Wheel (wheel.stl) AS7341 Sensor Darkroom Hood (8mm Focal Gap) Optical Chamber (inspection.stl) Radial Cam (cam.stl)
Figure 6.1: Inspector subassembly: pocket wheel indexing, optical darkroom chamber, and radial homing cam.
Make it yours
  • Try modeling a 6-pocket or 8-pocket carousel wheel and calculate the change in steps-per-index (e.g. 200 / 6 = 33.33 steps). How would you handle fractional steps in code?
  • Add an integrated viewing window on the side of the optical shroud with a dark red acrylic filter to watch the inspection live without letting white room light in.

If it breaks Troubleshooting

Wheel slips on motor shaft during fast movesThe grub screw is not clamping against the flat part of the D-shaft. Loosen the screw, rotate the wheel until the screw aligns squarely over the flat edge, and tighten firmly.
Skittle jams against optical shroud rimIncrease vertical clearance between the bottom of the shroud and the top of the wheel to 1.0 mm.
Home position drifts over multiple cyclesMotor is missing steps due to high acceleration or mechanical rubbing. Reduce step delay from 0.008s to 0.012s and inspect the underside for friction against the bracket.
This week's checkpointThe inspector wheel and optical darkroom shroud are mounted to the stepper motor. The Python script homes to Position 1 against the limit switch and cleanly indexes 90° per command without skipping or binding.
Next week: Colour sensing with the AS7341 — capturing calibrated 8-channel spectral fingerprints inside your optical chamber.