Waveshare HAT User manual

Stepper Motor HAT User Manual
1/ 24
Stepper Motor HAT
User Manual
OVERVIEW
Stepper Motor HAT is designed for Raspberry Pi, can drives two stepper motors and
support up to 1/32 microstepping
FEATURES
⚫Raspberry Pi connectivity, compatible with Raspberry Pi Zero/Zero W/Zero
WH/2B/3B/3B+
⚫Onboard dual DRV8825 motor controller IC with built-in microstepping indexer,
drives two stepper motors, easy to use
⚫6 available microstepping modes, configured with the DIP switches: full-step, half-
step, 1/4-step, 1/8-step, 1/16-step, and 1/32-step
⚫Adjustable motor drive current via potentiometer, maximum 2.5A current output
⚫Protection features: Overcurrent Protection (OCP), Thermal Shutdown (TSD), VM
Undervoltage Lockout (UVLO)
⚫Integrates 5V regulator, allows providing power to Raspberry Pi
⚫Onboard multi connector options for stepper motors in different specifications
⚫Comes with development resources and manual (examples in BCM2835, wiringPi,
and python)

Stepper Motor HAT User Manual
2/ 24
SPECIFICATIONS
⚫Motor controller: DRV8825
⚫Motor drive voltage: 8.2V~28V
⚫Motor drive current: 2.5A
⚫Logic voltage: 3.3V
⚫Dimension: 65mm × 56mm
⚫Mounting hole size: 3.0mm

Stepper Motor HAT User Manual
3/ 24
CONTENT
Overview....................................................................................................................................................... 1
Features................................................................................................................................................ 1
Specifications ..................................................................................................................................... 2
Hardware...................................................................................................................................................... 5
Pinout.................................................................................................................................................... 5
Power .................................................................................................................................................... 7
Motor Driver....................................................................................................................................... 7
Cotnrol protocol......................................................................................................................................10
H-bridge.............................................................................................................................................10
protocol of motor...........................................................................................................................11
Microstepping..................................................................................................................................12
DRV8825 ............................................................................................................................................12
Demo codes..............................................................................................................................................13
Preparation .......................................................................................................................................13
Downloading............................................................................................................................13
Libraries Installation ..............................................................................................................13
Setting.................................................................................................................................................15
Microstepping .........................................................................................................................15
Current setting ........................................................................................................................16
Running demo code ......................................................................................................................18
BCM2835 ...................................................................................................................................18

Stepper Motor HAT User Manual
4/ 24
WiringPi .....................................................................................................................................18
Python ........................................................................................................................................18
Code Analysis ...........................................................................................................................................19
BCM2835 ...........................................................................................................................................19
files ..............................................................................................................................................19
Codes..........................................................................................................................................20
wiringPi...............................................................................................................................................22
Files..............................................................................................................................................22
Python.................................................................................................................................................22
Files..............................................................................................................................................22
Codes..........................................................................................................................................22
FAQ...............................................................................................................................................................24

Stepper Motor HAT User Manual
5/ 24
HARDWARE
PINOUT
PIN
Description
VIN
8.2~28V Power Input
5V
5V Power
GND
Ground
A1
Output 1 of bipolar stepper motor M1
winding A

Stepper Motor HAT User Manual
6/ 24
A2
Output 2 of bipolar stepper motor M1
winding A
B1
Output 1 of bipolar stepper motor M1
winding B
B2
Output 2 of bipolar stepper motor M1
winding B
A3
Output 3 of bipolar stepper motor M2
winding A
A4
Output 4 of bipolar stepper motor M2
winding A
B3
Output 3 of bipolar stepper motor M2
winding B
B4
Output 4 of bipolar stepper motor M2
winding B
A1、A2、B1、B2: Control pins of stepper motor M1;
A3、A4、B3、B4: Control pins of stepper motor M2;
Power switch: Control power supply for Raspberry Pi;
Switch D0-D5: Control subdivision format;
D0-D2: Control stepper motor 1;
D3-D5: Control stepper motor 2;
Potentiometers: Control output current

Stepper Motor HAT User Manual
7/ 24
POWER
MP1584 regular supports wide 4.5V to 28V input, and up to 2A current output. Even
thought that MP1584 support low to 4.5V input, however, VM also supply power for
motor controller, which require at least 8.2V. So, the recommend input voltage is
8.2~28v.
MOTOR DRIVER

Stepper Motor HAT User Manual
8/ 24
The DRV8825 is e has two H-bridge and a microstepping indexer, and is intended
to drive a bipolar stepper motor. It supports up to 1/32 microstepping. Internal
shutdown functions are provided for overcurrent, short circuit, under voltage lockout
and over temperature.
VM:Voltage input, range: 8.2V~45V, consider of regular, the actual input range is:
8.2V~28V
nSLEEP: Should keep High, otherwise chip will enter sleep mode, and module cannot
work properly.
nENBL: Enable pin. Low: H-bridge is enabled and rise edge of STEP is sampled; High:
H-bridge is disabled, output is high impedance. Note that you should disable it if
you don’t use it, otherwise the chip and motor will keep heating!
STEP: Step clock input
DIR: Direction control
MODE0, MODE1, MODE2: Mcirostepping input
PIN 12/PIN 13: Adjust output current
R13/R16: Sample resistors, they are 0.2Ω
According to datasheet Page11:
Ichop = V(xREF)/(5*R(ISENSE))
and resistor is 0.2Ω, then we can get that output current is proportional to voltage of
potentiometer.
I = Vref

Stepper Motor HAT User Manual
9/ 24
So, if you need to increase the output current, you can adjust potentiometers on
board.

Stepper Motor HAT User Manual
10 / 24
COTNROL PROTOCOL
H-BRIDGE
H-bridge is a popular motor control circuit. It is named because it looks like character
“H”. It consists of four transistors/MOSFET, motor is connected on the center, you
should through two transistors in diagonal line to drive motor.
When Q1 and Q4 is accessed, current flow from positive pole->Q1 to Q4->negative
pole, then motor moves forward.
When Q2 and Q4 is accessed, current flow from positive pole->Q2 to Q4->negative
pole, then motor moves backward.
If it is two H-bridge, there will be two set of output lines, for example, stepper motor
has four wires which is two H-bridge.

Stepper Motor HAT User Manual
11 / 24
PROTOCOL OF MOTOR
According to Ampère's circuital law, when current of coil A flow from left to right,
stator generates magnetic field, internal side is North pole which will adopt rotator of
motor. When the currents of four coils based on certain rule, they will generate a
rotate magnetic field and drive the rotator rotate. If every motor has four rotators, it
has four statuses:
Status 1: coil A left in right out(current), coil C right in left out, motor rotate 0 degree;
Status 2: coil B top in bottom out, coil D bottom in top out, motor rotate 90 degree
against status 1.
Status 3: coil A right in left out, coil C left in right out, motor rotate 90 degree against
status 2;
Status 4: coil B bottom in top out, coil D top in left out, motor rotate 90 degree
against status 3;
Motor turn from previous status to next status, we call it step. Motor rotate in a circle
every four steps, and its step angle is 90 degree.
Most of motors have more than four stators. For example, 42 motor, 57 motors all
have 50 stators with step angle 1.8 degree.

Stepper Motor HAT User Manual
12 / 24
28BYJ-48 is four phase and eight steps, Speed Variation Ratio is 1/64 and its step
angle is 5.625/64 degree.
MICROSTEPPING
We have said that motor rotate because of flowing current.
According to its working principle, we can control currents in coils to make them
rise or fall regularly. It generates several stable intermediate-current statuses, related
vector directions of resultant magnetic fields also have several intermediate statuses.
To change the vector direction, motor can rotate in smaller angle and rotate more
smoothly.
Microstepping is to divide each full step into smaller steps to help smooth out the
motor’s rotation, especially at slow speeds. For example, if microstepping the motor
we described above to 1/2, status 1 should be done with two steps.
DRV8825
DRV88250 control stepper motor rotating according to pulses given by MCU.
How many pulses do motors require to rotate a circle without microstepping?
42 motor: 360/1.8 = 200
28BYJ-48 motor: 360 / 5.625 * 64 = 4096
As we test, with 200 pulses, 42 motor can rotate a circle. However, with 4096 pulses,
28BYJ-48 rotate two circles. That is because 28BYJ-48 is four-phase motor require
2048 pulses for a circle actually.

Stepper Motor HAT User Manual
13 / 24
DEMO CODES
PREPARATION
DOWNLOADING
Visit Waveshare Wiki and search for “Stepper Motor HAT”, open and download
demo code from wiki.
Extract and copy to your Raspberry Pi.
LIBRARIES INSTALLATION
1Install wiringPi
1.1 Open Terminal (Ctrl+T), clone wiringPi
git clone git://git.drogon.net/wiringPi

Stepper Motor HAT User Manual
14 / 24
1.2 Install it
cd wiringPi
./build
2Install BCM2835
2.1 Download the latest bcm2835 library
http://www.airspayce.com/mikem/bcm2835/index.html
2.2 Copy the zip you download to Raspberry Pi without extracting
2.3 Open Terminal, extract and install
#下载最新的函数库 bcm2835-1.xx.tar.gz
tar zxvf /boot/bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
./configure
make
sudo make check
sudo make install
3Install python library
sudo apt-get install python-rpi.gpio

Stepper Motor HAT User Manual
15 / 24
SETTING
MICROSTEPPING
Stepper motor HAT support up to 1/32 microstepping. Support both software and
hardware configuring.
Software configuring
In the demo codes, you can configure the microstepping by SOFTWARD/softward
which you can refer to Code Analysis
Hardware configuring
To use hardware configuration, you need to modify the function
Drv8825_SetMicroStep(HARDWARE, “”) in sample codes, then set the DIP switches
(D0~D5).
D0, D1, D2 are used to control motor M1 (MODW0, MODE1, MODE2), D3, D4, D5 are
used to control motor M2 (MODE0, MDOE1, MODE2). Their relationship are as below:

Stepper Motor HAT User Manual
16 / 24
For more details, please refer to datasheet page13
【Note】Sample codes uses full step setting, for which all switches are set to 0 by
default.
CURRENT SETTING
The maximum output current of DRV8856 is 2.5A, you can adjust current by adjusting
the potentiometer
Generally, working current of stepper motor is less than 2.5A, in this case, we need to
adjust the current outputted.

Stepper Motor HAT User Manual
17 / 24
For more details about the current required, please refer to datasheet page12.
The R(isense) on board is 200mR, so we can get that I(chop) = V(xref). V(xref) is
voltage of potentiometer, Ichop is output current. Reduce voltage by clockwise and
anticlockwise to increase the voltage.
The factory setting is compatible with most of stepper motor. However, there are
some motor whose minimum phase current is much larger, in this case, we need to
adjust the potentiometer for properly working.
【Note】
Chip may be damaged if motor works in abnormal states for long time.
Do not turn the potentiometer anticlockwise to maximum, otherwise, the chip will
be damaged after long time using.

Stepper Motor HAT User Manual
18 / 24
RUNNING DEMO CODE
BCM2835
cd bcm2835
sudo ./motor
WIRINGPI
cd wiringpi
sudo ./motor
PYTHON
cd python
sudo python test.py

Stepper Motor HAT User Manual
19 / 24
CODE ANALYSIS
We provide Raspberry Pi demo codes on wiki.
BCM2835
FILES
⚫/bin:
.o files which are generated by makfile
⚫Makefile: Code compilation
⚫motor: Executable file, you can execute command sudo ./motor to run the code
⚫Obj/: folders to save function files
Debug.h: Debug header file, you can set USE_DEBUG to 1 to print debug
information;
Deconflict(h): Define pins and interface of Raspberry Pi.
DRV8825.c(h): Driver code of DRV8825
main.c: Main function
README.txt: Description

Stepper Motor HAT User Manual
20 / 24
CODES
1. Initializing BCM2835 and setting pins
if(DEV_ModuleInit())
exit(0);
2. Choose Motor
DRV8825_SelectMotor(MOTOR1);
#Parameter: choose motor; MOTOR1, MOTOR2
3. Setting Microstepping
DRV8825_SetMicroStep(HARDWARD, "fullstep");
#Parameter 1: set control type; HARDWARE, SOFTWARD
#Parameter 2: set microstepping; "fullstep", "halfstep", "1/4step", "1/8step",
"1/16step", "1/32step"
4. Steps
DRV8825_TurnStep(BACKWARD, 200, 2);
#Parameter 1: control direction; FORWARD, BACKWARD
#Parameter 2: steps
#Parameter 2: delay for every step (ms)
5. Stop rotating
DRV8825_Stop();
6. Exception Handling
signal(SIGINT, Handler);
Other manuals for HAT
1
Table of contents
Popular Engine manuals by other brands

Jula
Jula 725-017 operating instructions

Kohler
Kohler COMMAND CV17-745 Service manual

Marley
Marley Geareducer M1712 user manual

Nederman
Nederman 865 series instruction manual

StepperOnline
StepperOnline iDM-RS Series user manual

ELSAN Elektrik San
ELSAN Elektrik San VEMS 80-2-77 Operation and maintenance instructions

MTD
MTD 277CC Operator's manual

Kubota
Kubota SM-E4B Series Workshop manual

Hatz Diesel
Hatz Diesel 4H50TIC Operator's manual

Ruggerini
Ruggerini RY125 Series Workshop manual

Briggs & Stratton
Briggs & Stratton 170700 Series Operating and maintenance instructions

Oriental motor
Oriental motor AXH Series operating manual