Stepper Motor HAT (B)
| ||
Introduction
Provides RPi demo and Jetson Nano demo.
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 micro stepping indexer, easy-to-drive two-stepper motors.
- 6 available micro stepping 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.
- Integrates 5V regulator, output up to 3A current, allowing providing power to Raspberry Pi.
- Onboard multi-connector options for stepper motors in different specifications.
Parameter
- Motor driver chip: HR8825
- Motor drive voltage: 8.2V~28V
- Motor drive 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; Switch D0-D5: Control subdivision format;
D0-D2: Control stepper motor 1; D3-D5: Control stepper motor 2; Potentiometers: Control output current.
Power
MP1584 regularly supports 4.5V to 28V input, and up to 3A current output. Even though MP1584 supports the lowest input of 4.5V. However, VM also supplies power for the motor controller, 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
HR8825 is a dual H-bridge motor driver chip that supports 32 subdivisions. 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 providing protection for 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 is disabled, the charge pump circuit stops working, the V3P3 output is 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 in the enabled state, 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, and 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 onboard potentiometer.
Control Principle
H-bridge
HR8825 is a dual H-bridge motor driver chip. The H-bridge is a classic control motor circuit, named after its shape like the letter "H". It is composed of four triodes or MOSFETs, and the middle one is connected to the motor horizontally. To make the motor rotate, a group of diagonal lines needs to be turned on.
When Q1 and Q4 are accessed, the current flow from positive pole->Q1 -> Q4->negative pole, then the motor moves forward.
When Q2 and Q3 are accessed, the current flow from the positive pole->Q2 -> Q3->negative pole, then the motor moves forward.
If it is two H-bridge, there will be two sets of output lines, for example, a stepper motor has four wires which is two H-bridge.
Principle of Motor
According to Ampère's circuital law, when the current of coil A flow from left to right, the stator generates a magnetic field, and the internal side is the North pole which will adopt the rotator of the motor. When the currents of four coils are based on certain rules, they will generate a rotating magnetic field and drive the rotator rotates. If a 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 degrees;
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 turn from the previous status to the next status, we call it to 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 is also There will be multiple stable intermediate states, and only the direction of this vector will be changed so that the motor can rotate at a smaller angle and rotate more smoothly.
Taking the motor with the above four stators 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.
HR8825 Drive Motor
HR8825 only needs to give the number of pulses to realize the rotation of the stepper motor. According to the previous analysis, and without subdivision:
How many pulses are needed to drive 42 motors to make one revolution:
360 / 1.8 = 200
Through experiments, it was found that the 42 motors did rotate a circle.
How many pulses are needed to drive the 28BYJ-48 motor to make one revolution:
360 / 5.625 * 64 = 4096
So are you sure that's the case? Through experiments, it was found that 28BYJ-48 rotate 2 circles.
28BYJ-48 is a four-phase motor. It supports three working modes: single-four-beat, double-four-beat and eight-beat. The step angle of the eight-beat working mode is half of that of single-four-beat and double-four-beat. When using the HR8825 to drive, the single four beats mode is used, so it takes 2048 pulses to drive the 28BYJ-48 to make one revolution.
Subdivision Setting
The module supports up to 32 micro-stepping 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'
S0, S1, S2 correspond to MODE0, MODE1, MODE2 that control the M1 driver, and S3, S4, and S5 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 s0-s5 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. The size of the current can be adjusted by adjusting the potentiometer in the figure below.
Onboard Risense = 200mR, then we can simplify the formula: Ichop = Vxref.
So Ichop is proportional to Vxref, Vxref is the voltage of the potentiometer, and Ichop 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
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
sudo apt-get install p7zip-full wget https://files.waveshare.com/upload/9/9d/Stepper_Motor_HAT_B_Code.7z 7z x Stepper_Motor_HAT_B_Code.7z -r -o./Stepper_Motor_HAT_B_Code sudo chmod 777 -R Stepper_Motor_HAT_B_Code cd Stepper_Motor_HAT_B_Code/Raspberry\ PI/
Running Sample Demo
Provide five demos, BCM2835, wiringPi, python, lgpio, and python-gpiozero.
Note: lgpio and python-gpiozero support all versions of Raspberry Pi, and 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, 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 Demo
sudo apt-get install p7zip-full wget https://files.waveshare.com/upload/9/9d/Stepper_Motor_HAT_B_Code.7z 7z x Stepper_Motor_HAT_Code_B.7z -r -o./Stepper_Motor_HAT_Code_B sudo chmod 777 -R Stepper_Motor_HAT_Code_B cd Stepper_Motor_HAT_Code_B/Jetson\ nano/
Running Sample Demo
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
FAQ
1. The chip is replaced by HR8825 from DRV8825; the function remains unchanged.
2. Modify the layout, increase the heat dissipation area, and make the chip fan heat better.
3. All interface positions remain unchanged, fully compatible with Stepper Motor HAT.
4. Program compatibility.
{{{5}}}
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 HAT(B)s 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, 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 are fed back to the controller for open-loop control.
{{{5}}}
To install the lgpio libraries, you can check the link of it.
https://abyz.me.uk/lg/download.html
We do not have guide of the lgpio c yet.
A python3 code for Pi5 which use the gpiozero was provided for testing.
{{{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)