Datasheet

the GND terminal on the Motor HAT output block. then coil 1 should connect to one motor
port (say M1 or M3) and coil 2 should connect to the other motor port (M2 or M4).
For bipolar motors: its just like unipolar motors except theres no 5th wire to connect to
ground. The code is exactly the same.
For this demo, please connect it to M1 and M2
Now go into the Adafruit-Motor-HAT-Python/examples folder and run sudo python
StepperTest.py to watch your stepper motor spin back and forth.
Stepper motor control walkthru
Here's a walkthru of the code which shows you everything the MotorHAT library can do and
how to do it.
Start with importing at least these libraries:
#!/usr/bin/python
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_StepperMotor
import time
import atexit
The MotorHAT library contains a few different classes, one is the MotorHAT class itself
which is the main PWM controller. You'll always need to create an object, and set the
address. By default the address is 0x60 (see the stacking HAT page on why you may want
to change the address)
# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT(addr = 0x60)
Even though this example code does not use DC motors, it's still important to note that the
PWM driver is 'free running' - that means that even if the python code or Pi linux kernel
crashes, the PWM driver will still continue to work. This is good because it lets the Pi focus
on linuxy things while the PWM driver does its PWMy things.
Stepper motors will not continue to move when the Python script quits, but it's still strongly
recommend that you keep this 'at exit' code, it will do its best to shut down all the motors:
# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
© Adafruit Industries
https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-
raspberry-pi
Page 27 of 38