Datasheet
mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)
atexit.register(turnOffMotors)
Creating the Stepper motor object
OK now that you have the motor HAT object, note that each HAT can control up to 2
steppers. And you can have multiple HATs!
To create the actual Stepper motor object, you can request it from the MotorHAT object you
created above with getStepper(steps, portnum) where steps is how many steps per
rotation for the stepper motor (usually some number between 35 - 200) ith a value between
1 and 2. Port #1 is M1 and M2, port #2 is M3 and M4
myStepper = mh.getStepper(200, 1) # 200 steps/rev, motor port #1
Next, if you are planning to use the 'blocking' step() function to take multiple steps at once
you can set the speed in RPM. If you end up using oneStep() then this step isn't necessary.
Also, the speed is approximate as the Raspberry Pi can't do precision delays the way an
Arduino would. Anyways, we wanted to keep the Arduino and Pi versions of this library
similar so we kept setSpeed() in:
myStepper.setSpeed(30) # 30 RPM
Stepping
Stepper motors differ from DC motors in that the controller (in this case, Raspberry Pi) must
tick each of the 4 coils in order to make the motor move. Each two 'ticks' is a step. By
alternating the coils, the stepper motor will spin all the way around. If the coils are fired in
the opposite order, it will spin the other way around.
If the python code or Pi crashes or stops responding, the motor will no longer move.
Compare this to a DC motor which has a constant voltage across a single coil for
movement.
© Adafruit Industries
https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-
raspberry-pi
Page 28 of 38










