To verify that the encoder disc design would work, I started with a single-bit of the eventual 3-bit encoder and just the one stepper motor.
In this first pass, I didn't have any LM393s in my parts bin. So while I awaited delivery, I used an op-amp (LM386) and a 2N2222 transistor to get the digital input needed for the microcontroller. Above the pycom microcontroller is a DRV8825 for the stepper motor.
DEFAULT_SPEED = 100 enc0 = Pin('P3', mode=Pin.IN) step_pin = Pin('P11', mode=Pin.OUT), dir_pin = Pin('P12', mode=Pin.OUT) # turn the stepper motor n degrees def turnKnob(degrees, cw=True, speed=DEFAULT_SPEED): # set direction dir_pin.value(0 if cw else 1) # adjust for the 5:1 planetary gear reduction steps = int(degrees * (1036/360)) delay = 1 / speed # create a pulse for each step needed for i in range(0, steps): step_pin.value(0) time.sleep(0.0001) step_pin.value(1) time.sleep(0.0001) step_pin.value(0) # time between pulses sets speed # short delay, faster rotation # longer delay, slower rotation time.sleep(delay) # run until the encoder hits a slot def runUntil(cw=True, speed=DEFAULT_SPEED): while enc0.value() != 0: turnKnob(1, cw, speed)
This snippet turns the stepper motor until a slot in the encoder disk triggers the IR/photodiode comparator
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.