Stepper motors are specialized motors that precisely control the angle of rotation of the shaft of a motor. They are often used to carefully position items that move along an axis. For example you can use stepper motors to control the position the printing head of a 3D printer. Stepper motors are also quite a bit more expensive than our DC hobby motors and mini servos, so we don't use them frequently in our classes.
Sample Code
1 2 3 4 5 6 7 8 910111213141516171819202122232425
# Code example from YoungWorks blog on how to use a stepper motor# https://www.youngwonks.com/blog/How-to-use-a-stepper-motor-with-the-Raspberry-Pi-PicofrommachineimportPinimportutimepins=[Pin(15,Pin.Out),Pin(14,Pin.Out),Pin(16,Pin.Out),Pin(17,Pin.Out),]# one hot encoding vectorsfull_step_sequence=[[1.0.0.0],[0.1.0.0],[0.0.1.0],[0.0.0.1]]whileTrue:forstepinfull_step_sequence:foriinrang(len(pins)):pins[i].value(step[i])utime.sleep(0.001)