Stepper Motor HAT
| ||
Introduction
Provides RPi demo and Jetson nano demo.
Features
- Designed based on Raspberry PI interface, compatible with Raspberry Pi Zero/Zero W/Zero WH/2B/3B/3B+/4B/5.
- Onboard dual DRV8825 motor controller IC with built-in converter,easy to drive two stepper motors.
- 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 output current via potentiometer, maximum 2.5A current output.
- Onboard 5V voltage regulator chip, up to 3A output current, allows providing power to Raspberry Pi.
- A variety of on-board stepper motor interfaces facilitate the access of stepper motors of different specifications.
Parameter
- Motor drive voltage: 8.2V~28V
- Motor driver chip: DRV8825
- Maximum current: 2.5A
- Dimension: 65mm × 56mm
- Through-hole diameter: 3.0mm
Onboard Resource
Pin | Description |
---|---|
VIN | 8.2~28V Power Input |
5V | 5V Power |
GND | Ground |
A1 | Output 1 of bipolar stepper motor M1 winding A |
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 1 of bipolar stepper motor M2 winding A |
A4 | Output 2 of bipolar stepper motor M2 winding A |
B3 | Output 1 of bipolar stepper motor M2 winding B |
B4 | Output 2 of bipolar stepper motor M2 winding B |
In which:
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;
Dip switch D0-D5: Control subdivision format;
D0-D2: Control stepper motor 1;
D3-D5: Control stepper motor 2;
Two on-board potentiometers: Control the output current.
Power
MP1584 voltage regulator chip is used in the power supply, it regular supports wide voltage inputs from 4.5V to 28V, and up to 3A current output. Even though MP1584 supports the lowest input of 4.5V. However, VM also supplies operating voltage for the motor drive chip, which requires at least 8.2V. So, the recommended input voltage is 8.2~28v.
The specification of the power DC head is a powerhead with an outer diameter of 5.5 and an inner diameter of 2.1. There are many DC heads on the market with this specification. You can use a 9V2A or 12V2A power supply for power supply.
Motor Driver
DRV8825 is a dual H-bridge motor driver chip that supports 32 microstepping. It also integrates short-circuit, overheating, under-voltage, and cross-conduction protection circuits, which can detect fault conditions and quickly cut off the H-bridge, thus protecting the motor and driver chip.
VM is the input voltage, the input range is: 8.2V to 45V, and the input range of the integrated voltage regulator chip is 8.2V to 28V.
nSLEEP needs to be kept high, otherwise, the chip will directly enter sleep mode: the H-bridge of the device will be disabled, the charge pump circuit will stop working, the V3P3 output will be disabled, and all internal clocks stop working, and all logic inputs are ignored.
The nENBL pin is an enable pin, inputting a low level, the H bridge output is enabled, and the rising edge on STEP is recognized. When the input is high, the H-bridge is disabled, the output is in a high-impedance state, and the STEP input is ignored. It must be disabled when it is not working, otherwise, the chip will remain enabled, and the chip and the motor will always be in a high-temperature state!
STEP is the stepping clock input, DIR is the direction control input, and MODE0, MODE1, and MODE2 are the subdivision inputs.
Pins 12 and 13 are used to adjust the output current, R13 and R16 are sampling resistors of 0.2 ohms, according to the formula on the data sheet (datasheet: page11):
Ichop = V(xREF)/(5*R(ISENSE))
Substitute R(ISENSE) = 0.2 into the formula
Then the output current is proportional to the voltage on the potentiometer:
I = Vref
If the torque of the motor is not enough, the output current can be increased by adjusting the on-board potentiometer.
Control Principle
H-bridge
DRV8825 is a double H-bridge motor driver chip. H-bridge is a classic motor control circuit. It is named because it looks like the character“H”. It consists of four transistors/MOSFET in four columns, the motor is connected to the center, and you should through two transistors in a diagonal line to drive the motor.
When Q1 and Q4 are accessed, the current flow from positive pole-> Q1 -> Q4 -> negative pole, then the motor moves forward, as in the upper left picture;
When Q2 and Q3 are accessed, the current flow from positive pole -> Q2 -> Q3->negative pole, then motor moves forward, as in the upper right picture;
If it is two H-bridge, there will be two sets of output line, just corresponding to the four wires of the stepper motor.
Rotation Principle of Motor
For the two four-wire motors, their motion is shown as follows:
According to Ampère's circuital law, when the current of coil A flows from left to right, the stator generates a magnetic field, internal side is the North pole, which will attract the rotor on the motor When the currents of four coils are based on certain rules, it will generate a rotating magnetic field and drive the rotator to rotate. If every motor has four stators, it has four statuses:
Status 1: coil A left in right out(current), coil C right in left out, the motor rotates 0 degree;
Status 2: coil B top in bottom out, coil D bottom in top out, the motor rotates 90 degrees against status 1.
Status 3: coil A right in left out, coil C left in right out, the motor rotates 90 degrees against status 2;
Status 4: coil B bottom in top out, coil D top in bottom out, the motor rotates 90 degrees against status 3;
Motor turns from the previous status to the next status, we call it to a step. The motor rotates in a circle every four steps, and its step angle is 90 degrees.
Most motors have more than four stators. For example, 42 motors, and 57 motors all have 50 stators(There are actually only 48 stators, and two are removed to give each set of stators a certain spacing) with a step angle of 1.8 degrees.
28BYJ-48 is permanent magnet deceleration four-phase eight-beat stepper motor, reduction ratio is 64 and its step angle is 5.625/64 degrees.
Microstep Subdivision
The rotation of the motor is due to the regular energization of the coil, which will synthesize a uniformly distributed circular rotating magnetic field, thereby attracting the rotor to rotate.
According to this principle, controlling the currents in the windings of each phase can make them rise or fall according to a certain law, that is, to form multiple stable intermediate current states between zero current and maximum current, the direction of the corresponding synthetic magnetic field vector will also have multiple stable intermediate states, and only the direction of this vector is changed, so that the motor can rotate at a smaller angle and rotate more smoothly.
Taking the motor with four stators above as an example, if it is subdivided into half, then it takes two steps to complete the transition from the first state to the second state, because the state after the first state, the A coil with 50% current, B coil with 50% current will generate a vector magnetic field with an included angle of 45 degrees, thereby attracting the motor rotor to rotate 45 degrees. When running 8 steps, the motor completes one revolution.
DRV8825 drives the motor
DRV88250 control stepper motor rotating according to the number of pulses given by MCU. Following the previous analysis, and without using subdivisions:
How many pulses do motors require to rotate a circle?
42 motor: 360/1.8 = 200
28BYJ-48 motor: 360 / 5.625 * 64 = 4096
As we test, with 200 pulses, 42 motors can rotate a circle. However, with 4096 pulses, 28BYJ-48 rotates two circles. That is because 28BYJ-48 is a four-phase motor. It supports single four beats, double four beats and eight beats of three working modes, the step angle of the eight-beat working mode is half of that of single-four-beat and double-four-beat, and when using the HR8825 to drive, the single four beats mode is used, so it requires 2048 pulses for a circle.
Subdivision Setting
The module supports up to 32 microstepping and can be controlled using software or hardware.
- Software Microstepping Control:
First, you need to solder the 6 resistors on the back.
Modify the corresponding command on the program to enable the corresponding software system.
python can be selected by 'softward'
c language can be selected by SOFTWARD
And it is necessary to turn all the DIP switches to 1 for the software control to take effect.
- Hardware Microstepping Control:
In the c program can be selected by HARDWARD
In Python can be selected by 'hardward'
D0, D1, D2 correspond to MODE0, MODE1, MODE2 that control the M1 driver, and D3, D4, and D5 correspond to MODE0, MODE1, and MODE2 that control the M2 driver. The specific correspondence is as follows:
Note: The sample program needs to dial all D0-D5 to 0, corresponding to the full step.
Note: The default subdivision is all in the position of 1, so the subdivision of the hardware is very slow, and the experimental effect may not be seen. It is best to adjust it to 0.
Current Setting
The maximum output current of DRV8825 is 2.5A, and the current can be adjusted by the potentiometer in the figure below:
See datasheet page12
Onboard Risense = 200mR, then we can simplify the formula: I(chop) = V(xref)
So I (chop) is proportional to V(xref), V(xref) is the voltage of the potentiometer, and I(chop) is the output current.
When the potentiometer rotates clockwise, the voltage decreases, and when the potentiometer rotates counterclockwise the voltage increases. If you need to measure, you can plug in the power supply to the module, and use a multimeter, the red test lead touches the bottom, and the black test lead touches the upper rectangular pad.
The factory-set potentiometer is in the middle, which can drive most motors.
If the minimum phase current of the motor is larger than this, it may not reach the ideal state, and working for a long time may cause the chip to burn.
Do not turn it counterclockwise to the end, working for a long time may cause the chip to burn.
Raspberry Pi
Pin Definition
Stepper Motor HAT | Raspberry Pi (BCM) |
---|---|
A1A2B1B2 dir | 13 |
A1A2B1B2 step | 19 |
A1A2B1B2 enable | 12 |
A1A2B1B2 mode | 16 17 20 |
A3A4B3B4 dir | 24 |
A3A4B3B4 step | 18 |
A3A4B3B4 dir | 4 |
A3A4B3B4 mode | 21 22 27 |
Install Library
If you use bookworm system, only the lgpio library is available, bcm2835 and wiringPi libarary cannot be installed or used. Please note that the python library does not need to install, you can directly run the demo.
BCM2835
#Open the Raspberry Pi terminal and run the following command wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo ./configure && sudo make && sudo make check && sudo make install # For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/
WiringPi
#Open the Raspberry Pi terminal and run the following command cd sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error # Bullseye branch system using the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi . /build gpio -v # Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error
lgpio
wget https://github.com/joan2937/lg/archive/master.zip unzip master.zip cd lg-master sudo make install #for more details, you can refer to https://github.com/gpiozero/lg
Python
#python2 sudo apt-get update sudo pip install RPi.GPIO
#python3 sudo apt-get update sudo pip3 install RPi.GPIO
python-gpiozero
sudo apt-get update # python3 sudo apt install python3-gpiozero # python2 sudo apt install python-gpiozero
Download Sample Demo
wget https://files.waveshare.com/upload/1/1f/Stepper_Motor_HAT_Code.zip unzip Stepper_Motor_HAT_Code.zip sudo chmod 777 -R Stepper_Motor_HAT_Code cd Stepper_Motor_HAT_Code/Raspberry\ PI/
If your purchase date is earlier than 2021.01.05, please do the following:
sudo apt-get install p7zip-full wget https://files.waveshare.com/upload/8/8c/Stepper_Motor_HAT_Code.7z 7z x Stepper_Motor_HAT_Code.7z -r -o./Stepper_Motor_HAT_Code sudo chmod 777 -R Stepper_Motor_HAT_Code cd Stepper_Motor_HAT_Code/Raspberry\ PI/
The difference is that the new version uses a high-level enable so that the motor will not work when the Raspberry Pi does not initialize the enable GPIO and let it output a high level.
Running Sample Demo
Provide the following demos: BCM2835, wiringPi, python, lgpio, and python-gpiozero.
Note: lgpio and python-gpiozero support all versions of Raspberry Pi, BCM2835, wiringPi, and python do not support Pi5.
Do the following steps before running the demo:
1. Raspberry Pi uses an independent power supply;
2. The DC port of the module is connected to an 8.2V-28V power supply, and the switch is turned ON;
3. Correctly connect the stepper motor.
- BCM2835, wiringPi, and lgpio demo:
cd bcm2835/ make clean make sudo ./motor
- python and python-gpiozero demo:
#python2 cd python/ sudo python test.py #python3 cd python/ sudo python3 test.py
Jetson Nano
Library Installation
#python2 sudo apt-get install python-pip sudo pip install Jetson.GPIO sudo groupadd -f -r gpio sudo usermod -a -G gpio your_user_name sudo udevadm control --reload-rules && sudo udevadm trigger #python3 sudo apt-get install python3-pip sudo pip3 install Jetson.GPIO sudo groupadd -f -r gpio sudo usermod -a -G gpio your_user_name sudo udevadm control --reload-rules && sudo udevadm trigger
Download Sample Program
New version (the date of purchase is later than 2021.01.05, the board has the word Rev2.1):
wget https://files.waveshare.com/upload/1/1f/Stepper_Motor_HAT_Code.zip unzip Stepper_Motor_HAT_Code.zip sudo chmod 777 -R Stepper_Motor_HAT_Code cd Stepper_Motor_HAT_Code/Jetson\ nano/
If your purchase date is earlier than 2021.01.05, please do the following:
sudo apt-get install p7zip-full wget https://files.waveshare.com/upload/8/8c/Stepper_Motor_HAT_Code.7z 7z x Stepper_Motor_HAT_Code.7z -r -o./Stepper_Motor_HAT_Code sudo chmod 777 -R Stepper_Motor_HAT_Code cd Stepper_Motor_HAT_Code/Jetson\ nano/
The difference is that the new version uses a high-level enable, so that the driver board will not work when the Raspberry Pi is not driven and the GPIO status of the Raspberry Pi has not been configured.
Running Sample Program
Provides three demos: C, Python2, Python3
- C
cd C/ make clean make sudo ./main
- Python 2
cd python2/ sudo python main.py
- Python 3
cd python3/ sudo python3 main.py
Resources
Documents
Datasheet
Codes
Related Resources
FAQ
1. Confirm that all the pins of the Raspberry Pi are good and not burned by the pins;
2. Confirm whether superimposing other modules will cause the misuse of pins;
3. Confirm which model your motor is, the default demo is to drive 28BJY-48 (channel 2) for one channel, and one to drive 1.8-degree stepper motors such as nema23 and nema14(channel 1), if both are 1.8 stepper motor, you need to change the delay of channel 2 to the delay of channel 1. Because the GPIO high and low-level switching is used by default to simulate PWM, different motors have different frequencies for PWM.
4. Replace the new system and test it.
{{{5}}}
1. Check config.txt to confirm that no other pins are occupied.
2. Do not insert other modules, just insert a Stepper Motor HAT.
3. Make sure that the driver pins of the Raspberry Pi are all good, and no pins are burned.
4. Only forward rotation but not reverse rotation indicates that there is a pin that controls the direction not working.
{{{5}}}
Yes.
{{{5}}}
No, because it is driven by GPIO, the two Stepper Motor HATs use the same pins for stacking, and the actions of the two boards are the same even if they are stacked.
{{{5}}}
It needs to be confirmed that other expansion boards do not occupy GPIO pins. For detailed pins, please refer to the schematic diagram. The driving motor requires 12 pins.
{{{5}}}
Stepper motors generally do not talk about power, because when the control speed of the motor becomes faster or slower, the power consumed by the motor changes, which cannot be expressed in detail. The state we often use is to rotate in a single step. There will be multiple groups or groups of coils that will be energized at each step. Because the winding methods of different stepping motors are different, and the internal resistance of the coils is different, the resulting impedance will be different. If it must be calculated, it can be calculated by torque. To calculate , P is the power, the unit is the watt, n is the revolution per minute, M is the torque, and the unit is Newton·m.
{{{5}}}
1. There is a high probability that the motor cannot be driven. It is recommended that the phase current of the motor should not exceed 2.5A. If it exceeds and a fan is not added to dissipate heat, it is very risky, and the driver chip may be burned.
2. The default current is small, it is to try to change the resistance of the potentiometer.
3. The power adapter with larger output can be used. The output power of the power adapter provided by us is relatively small, and the motor with a large load may not be able to drive.
{{{5}}}
Open-loop control, the fundamental difference between open-loop and closed-loop is whether the current running status signal will be fed back. Open-loop has no feedback signal, so it only executes in sequence, while closed-loop feedback signal, the stepper motor driver will take corresponding actions according to the signal. Measures or signals will be fed back to the controller for open-loop control.
{{{5}}}
It is 0ohm, 0603 resistor.
{{{5}}}
It is XH2.54 4P connector.
{{{5}}}
Support
Technical Support
If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)