Difference between revisions of "Stepper Motor HAT"

From Waveshare Wiki
Jump to: navigation, search
 
(67 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox item|colorscheme=blue
+
<div class="wiki-pages jet-green-color">
 +
 +
<font size="4px">
 +
{{Infobox item  
 
|img=[[File:Stepper-Motor-HAT-1.jpg|400px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/stepper-motor-hat.htm}}]]
 
|img=[[File:Stepper-Motor-HAT-1.jpg|400px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/stepper-motor-hat.htm}}]]
 
|caption=Stepper Motor HAT for Raspberry Pi
 
|caption=Stepper Motor HAT for Raspberry Pi
Line 9: Line 12:
 
|interface1 = RPi
 
|interface1 = RPi
 
}}
 
}}
== Introduction ==
+
= Introduction =
 
Stepper Motor HAT for Raspberry Pi, Drives Two Stepper Motors, Up to 1/32 Microstepping
 
Stepper Motor HAT for Raspberry Pi, Drives Two Stepper Motors, 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,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 motor drive current via potentiometer, maximum 2.5A current output.
 +
*Integrates 5V regulator, allows providing power to Raspberry Pi.
 +
*Onboard multi connector options for stepper motors in different specifications.
  
== Resources ==
+
== Parameter ==
 +
*Motor controller: DRV8825
 +
*Motor drive voltage: 8.2V~28V
 +
*Motor drive current: 2.5A
 +
*Dimension: 65mm × 56mm
 +
*Mounting hole size: 3.0mm
 +
== Onboard Resource ==
 +
[[File:Onboard resource.png|450px|thumb|right]]
 +
{|class="wikitable" style="text-align:center"
 +
!Pin!!Description
 +
|-
 +
|VCC||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 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
 +
|}
 +
In which: A1、A2、B1、B2: Control pins of stepper motor M1; A3、A4、B3、B4: Control pins of stepper motor M2;<br/>
 +
Power switch: Control power supply for Raspberry Pi; Switch D0-D5: Control subdivision format;<br/>
 +
D0-D2: Control stepper motor 1;D3-D5: Control stepper motor 2;Potentiometers: Control output current<br/>
 +
 
 +
== Power ==
 +
[[File:Stepper Motor HAT2.png]]<br/>
 +
MP1584 regular supports 4.5V to 28V input, and up to 2A 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.<br/>
 +
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.<br/>
 +
 
 +
== 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 providing protection for the motor and driver chip.<br/>
 +
[[File:Motor Driver.png]]<br/>
 +
VM is the input voltage, the input range is: 8.2V to 45V, the input range of the integrated voltage regulator chip is 8.2V to 28V.<br/>
 +
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.<br/>
 +
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!<br/>
 +
STEP is the stepping clock input, DIR is the direction control input, and MODE0, MODE1, and MODE2 are the subdivision inputs.<br/>
 +
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 (data sheet: page11):<br/>
 +
 
 +
[[File:current regulation.png]]<br/>
 +
Ichop = V(xREF)/(5*R(ISENSE))<br/>
 +
Substitute R(ISENSE) = 0.2 into the formula<br/>
 +
Then the output current is proportional to the voltage on the potentiometer:<br/>
 +
I = Vref<br/>
 +
If the torque of the motor is not enough, the output current can be increased by adjusting the on-board potentiometer.<br/>
 +
 
 +
= Control Protocol =
 +
[[File:Control Protocol.png]]<br/>
 +
H-bridge is a popular motor control circuit. It is named because it looks like the character“H”. It consists of four transistors/MOSFET, the motor is connected to the center, and you should through two transistors in diagonal line to drive motor. <br/>
 +
When Q1 and Q4 is accessed, current flow from positive pole->Q1 to Q4->negative pole, then motor moves forward. <br/>
 +
When Q2 and Q4 is accessed, current flow from positive pole->Q2 to Q4->negative pole, then motor moves backward.<br/>
 +
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<br/>
 +
 
 +
== Protocol of Motor ==
 +
[[File:stepper-motor-hat-prin.png]]<br/>
 +
According to Ampère's circuital law, when the current of coil A flow from left to right, the stator generates a magnetic field, 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 every motor has four rotators, it has four statuses:<br/>
 +
Status 1: coil A left in right out(current), coil C right in left out, the motor rotates 0 degree;<br/>
 +
Status 2: coil B top in bottom out, coil D bottom in top out, the motor rotates 90 degrees against status 1.<br/>
 +
Status 3: coil A right in left out, coil C left in right out, the motor rotates 90 degrees against status 2;<br/>
 +
Status 4: coil B bottom in top out, coil D top in left out, the motor rotates 90 degrees against status 3;<br/>
 +
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.<br/>
 +
Most motors have more than four stators. For example, 42 motors, and 57 motors all have 50 stators with a step angle of 1.8 degrees.<br/>
 +
28BYJ-48 is four-phase and eight steps, Speed Variation Ratio is 1/64 and its step angle is 5.625/64 degrees.<br/>
 +
 
 +
== Microstepping ==
 +
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.<br/>
 +
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.<br/>
 +
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 50% current, 50% of the current of the B coil 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.<br/>
 +
== DRV8825 ==
 +
DRV88250 control stepper motor rotating according to pulses given by MCU.<br/>
 +
How many pulses do motors require to rotate a circle without microstepping?<br/>
 +
42 motor: 360/1.8 = 200<br/>
 +
28BYJ-48 motor: 360 / 5.625 * 64 = 4096<br/>
 +
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 that requires 2048 pulses for a circle actually.<br/>
 +
== Setting ==
 +
The module supports up to 32 microstepping and can be controlled using software or hardware.<br/>
 +
*Software Microstepping Control:<br/>
 +
First, you need to solder the 6 resistors on the back<br/>
 +
[[File:Stepper-motor-hat.png|thumb|right|Software Microstepping control]]
 +
Modify the corresponding command on the program to enable the corresponding software system<br/>
 +
python can be selected by 'softward'<br/>
 +
c language can be selected by SOFTWARD<br/>
 +
And it is necessary to turn all the DIP switches to 1 for the software control to take effect.<br/>
 +
Hardware Microstepping Control:<br/>
 +
In the c program can be selected by HARDWARD<br/>
 +
In python can be selected by 'hardward'<br/>
 +
[[File:Stepper-motor-hat2.png|thumb|right|Software Microstepping Control]]
 +
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<br/>
 +
[[File:Stepper-motor-hat3.png|650px|thumb|center]]
 +
[https://{{SERVERNAME}}/w/upload/b/b4/DRV8825_datasheet.pdf <font color="#FF0000">See datasheet page13</font>]
 +
 
 +
Note: The sample program needs to dial all D0-D5 to 0, corresponding to the full step.<br/>
 +
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.<br/>
 +
 
 +
== Current Setting ==
 +
The maximum output current of DRV8825 is 2.5A, and the current can be adjusted by the potentiometer in the figure below<br/>
 +
[[File:Stepper Motor HAT4.png]]<br/>
 +
[https://{{SERVERNAME}}/w/upload/b/b4/DRV8825_datasheet.pdf <font color="#FF0000">See datasheet page12</font>]<br/>
 +
Onboard Risense = 200mR, then we can simplify the formula: I(chop) = V(xref)<br/>
 +
So I(chop) is proportional to V(xref), V(xref) is the voltage of the potentiometer, and I(chop) is the output current.<br/>
 +
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, use a multimeter, the red test lead touches the bottom, and the black test lead touches the upper rectangular pad<br/>
 +
[[File:Stepper Motor HAT5.png]]<br/>
 +
The factory-set potentiometer is in the middle, which can drive most motors.<br/>
 +
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.<br/>
 +
<font color="#FF0000">Do not turn it counterclockwise to the end. Working for a long time may cause the chip to burn.</font><br/>
 +
 
 +
= Raspberry Pi =
 +
==Pin==
 +
{|class="wikitable" style="text-align:center"
 +
!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
 +
|}
 +
==Library Installation==
 +
===BCM2835===
 +
#Enable the Raspberry Pi terminal and run the following command
 +
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
 +
tar zxvf bcm2835-1.68.tar.gz
 +
cd bcm2835-1.68/
 +
sudo ./configure && sudo make && sudo make check && sudo make install
 +
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/
 +
===WiringPi===
 +
<pre>
 +
#Enable the Raspberry Pi terminal and run the following command
 +
sudo apt-get install wiringpi
 +
#For Raspberry Pi systems after May 2019 (earlier than before, you may not need to execute), you may need to upgrade:
 +
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 does not appear, the installation is wrong
 +
 
 +
#Bullseye branch system use the following command:
 +
git clone https://github.com/WiringPi/WiringPi
 +
cd WiringPi
 +
./build
 +
gpio -v
 +
# Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error
 +
</pre>
 +
 
 +
===Python===
 +
sudo apt-get update
 +
sudo pip install RPi.GPIO
 +
===Download Sample Program===
 +
New version (the date of purchase is later than 2021.01.05, the board has the word Rev2.1):<br/>
 +
sudo apt-get install p7zip-full
 +
wget https://www.waveshare.net/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
 +
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
 +
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
 +
cd Stepper_Motor_HAT_V2_Code/Raspberry\ PI/
 +
If your purchase date is earlier than 2021.01.05, please do the following:<br/>
 +
sudo apt-get install p7zip-full
 +
wget http://www.waveshare.net/w/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.<br/>
 +
 
 +
===Running Sample Program===
 +
Provide three programs, BCM2835, wiringPi, python<br/>
 +
Do the following steps before running the program:<br/>
 +
1. Raspberry Pi uses independent power supply<br/>
 +
2. The DC port of the module is connected to 8.2V-28V power supply, and the switch is turned ON<br/>
 +
3. Correctly connect the stepper motor<br/>
 +
*BCM2835 Demo
 +
cd bcm2835/
 +
make clean
 +
make
 +
sudo ./motor
 +
*wiringPi Demo
 +
cd wiringpi/
 +
make clean
 +
make
 +
sudo ./motor
 +
*Python Demo
 +
cd python/
 +
sudo python 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):<br/>
 +
sudo apt-get install p7zip-full -y
 +
wget https://www.waveshare.net/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
 +
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
 +
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
 +
cd Stepper_Motor_HAT_V2_Code/Jetson\ nano/
 +
If your purchase date is earlier than 2021.01.05, please do the following:<br/>
 +
sudo apt-get install p7zip-full
 +
wget http://www.waveshare.net/w/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.<br/>
 +
===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===
 
===Documents===
 
* [https://www.waveshare.com/w/upload/b/b2/Stepper_Motor_HAT_User_Manual_EN.pdf User Manual]
 
* [https://www.waveshare.com/w/upload/b/b2/Stepper_Motor_HAT_User_Manual_EN.pdf User Manual]
Line 25: Line 280:
 
* [https://www.waveshare.com/w/upload/8/8c/Stepper_Motor_HAT_Code.7z Demo Code]
 
* [https://www.waveshare.com/w/upload/8/8c/Stepper_Motor_HAT_Code.7z Demo Code]
 
* [https://www.waveshare.com/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z Rev2.1 Demo Code]
 
* [https://www.waveshare.com/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z Rev2.1 Demo Code]
 +
===Related Resources===
 +
* [[Libraries Installation for RPi]]
  
==FAQ==
+
=FAQ=
 +
{{FAQ|Why one channel does not turn after connecting two motors?
 +
|1. Confirm that all the pins of the Raspberry Pi are good and not burned by the pins;<br/>
 +
2. Confirm whether superimposing other modules will cause the misuse of pins;<br/>
 +
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 (channel 1) such as nema23 and nema14, if both are 1.8 The stepper motor needs 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.<br/>
 +
4. Replace the new system and test it.<br/>
 +
}}
 +
{{FAQ|The motor can only rotate in the forward direction and not in the reverse direction?
 +
|1. Check config.txt to confirm that no other pins are occupied<br/>
 +
2. Do not insert other modules, just insert a Stepper Motor HAT<br/>
 +
3. Make sure that the driver pins of the Raspberry Pi are all good, and no pins are burned<br/>
 +
4. Only forward rotation but not reverse rotation indicates that there is a pin that controls the direction not working<br/>
 +
}}
 +
{{FAQ|Do A1, A2, B1, and B2 correspond to A+, A-, B+, and B-?
 +
|Yes
 +
}}
 +
{{FAQ|Does it support stacking two Stepper Motor HATs?
 +
|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.
 +
}}
 +
{{FAQ|Does it support Stepper Motor HAT stacking with other expansion boards?
 +
|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.
 +
}}
 +
{{FAQ|Why does it plus the motor only make a sound and doesn't turn?
 +
|Poke the switch here with a pen to the other side, the default setting is 32 subdivisions, and the program only runs 200 pulses, and the rotation angle is only 360/32 degrees, the phenomenon is difficult to see
 +
[[File:stepper motor hat 7.png]]<br/>
 +
}}
 +
{{FAQ|Why does the SM24240 not turn 1 circle after giving 200 pulses?
 +
|Use the pen to poke the switch here to the other side, the default setting is 32 subdivisions
 +
[[File:stepper-motor-hat-faq.png]]<br/>
 +
}}
 +
{{FAQ|How to calculate motor power?
 +
|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. 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 [[File:p.png]], 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
 +
}}
 +
{{FAQ|The driver chip is hot and the motor doesn't turn?
 +
|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 the risk of heat dissipation without a fan, the driver chip may be burned.<br/>
 +
2. The default current is small, it is to try to change the resistance of the potentiometer<br/>
 +
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.<br/>
 +
}}
 +
{{FAQ|Is the driver board controlled by the open-loop or the closed-loop?
 +
|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.
 +
}}
 
{{FAQ|How to download the demo on Pi for the two versions?
 
{{FAQ|How to download the demo on Pi for the two versions?
|
+
|*New version (the purchase date is later than 2021.01.05, the PCB board is printed with the word Rev2.1)
*New version (the purchase date is later than 2021.01.05, the PCB board is printed with the word Rev2.1)
 
 
You can enter the following commands in the terminal to download the demo:
 
You can enter the following commands in the terminal to download the demo:
 
<pre>
 
<pre>
 
sudo apt-get install p7zip-full
 
sudo apt-get install p7zip-full
 
wget https://www.waveshare.com/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
 
wget https://www.waveshare.com/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
7z x Stepper_Motor_HAT_Code.7z -r -o./Stepper_Motor_HAT_Code
+
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
sudo chmod 777 -R Stepper_Motor_HAT_Code
+
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
cd Stepper_Motor_HAT_Code/Raspberry\ PI/
+
cd Stepper_Motor_HAT_V2_Code/Raspberry\ PI/
 
</pre>
 
</pre>
  
Line 43: Line 339:
 
sudo apt-get install p7zip-full
 
sudo apt-get install p7zip-full
 
wget https://www.waveshare.com/w/upload/8/8c/Stepper_Motor_HAT_Code.7z
 
wget https://www.waveshare.com/w/upload/8/8c/Stepper_Motor_HAT_Code.7z
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
+
7z x Stepper_Motor_HAT_Code.7z -r -o./Stepper_Motor_HAT_Code
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
+
sudo chmod 777 -R Stepper_Motor_HAT_Code
cd Stepper_Motor_HAT_V2_Code/Raspberry\ PI/
+
cd Stepper_Motor_HAT_Code/Raspberry\ PI/
 
</pre>
 
</pre>
 
The difference is that the new version uses high-level enable, so the motor will not work when the Raspberry Pi doesn't initialize the enable GPIO and let it output high-level.
 
The difference is that the new version uses high-level enable, so the motor will not work when the Raspberry Pi doesn't initialize the enable GPIO and let it output high-level.
 
}}
 
}}
  
==Related Resources==
 
* [[Libraries Installation for RPi]]
 
  
==Support==
 
 
{{Service00}}
 
{{Service00}}
  
 
[[Category:Expansions|Expansions]] [[Category:Raspberry Pi|Raspberry Pi]]
 
[[Category:Expansions|Expansions]] [[Category:Raspberry Pi|Raspberry Pi]]

Latest revision as of 08:26, 8 August 2022

Stepper Motor HAT
Stepper-Motor-HAT-1.jpg

Stepper Motor HAT for Raspberry Pi
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

Stepper Motor HAT for Raspberry Pi, Drives Two Stepper Motors, 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,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 motor drive current via potentiometer, maximum 2.5A current output.
  • Integrates 5V regulator, allows providing power to Raspberry Pi.
  • Onboard multi connector options for stepper motors in different specifications.

Parameter

  • Motor controller: DRV8825
  • Motor drive voltage: 8.2V~28V
  • Motor drive current: 2.5A
  • Dimension: 65mm × 56mm
  • Mounting hole size: 3.0mm

Onboard Resource

Onboard resource.png
Pin Description
VCC 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 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

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

Stepper Motor HAT2.png
MP1584 regular supports 4.5V to 28V input, and up to 2A 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

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 providing protection for the motor and driver chip.
Motor Driver.png
VM is the input voltage, the input range is: 8.2V to 45V, 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, R13 and R16 are sampling resistors of 0.2 ohms, according to the formula on the data sheet (data sheet: page11):

Current regulation.png
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 Protocol

Control Protocol.png
H-bridge is a popular motor control circuit. It is named because it looks like the character“H”. It consists of four transistors/MOSFET, the motor is connected to the center, and 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

Protocol of Motor

Stepper-motor-hat-prin.png
According to Ampère's circuital law, when the current of coil A flow from left to right, the stator generates a magnetic field, 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 every motor has four rotators, 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 left 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 with a step angle of 1.8 degrees.
28BYJ-48 is four-phase and eight steps, Speed Variation Ratio is 1/64 and its step angle is 5.625/64 degrees.

Microstepping

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 50% current, 50% of the current of the B coil 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

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 motors can rotate a circle. However, with 4096 pulses, 28BYJ-48 rotates two circles. That is because 28BYJ-48 is a four-phase motor that requires 2048 pulses for a circle actually.

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

Software Microstepping control

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'

Software Microstepping Control

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

Stepper-motor-hat3.png

See datasheet page13

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
Stepper Motor HAT4.png
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, use a multimeter, the red test lead touches the bottom, and the black test lead touches the upper rectangular pad
Stepper Motor HAT5.png
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

Library Installation

BCM2835

#Enable the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
tar zxvf bcm2835-1.68.tar.gz
cd bcm2835-1.68/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/

WiringPi

 #Enable the Raspberry Pi terminal and run the following command
 sudo apt-get install wiringpi
 #For Raspberry Pi systems after May 2019 (earlier than before, you may not need to execute), you may need to upgrade:
 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 does not appear, the installation is wrong

 #Bullseye branch system use the following command:
 git clone https://github.com/WiringPi/WiringPi
 cd WiringPi
 ./build
 gpio -v
 # Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error

Python

sudo apt-get update
sudo pip install RPi.GPIO

Download Sample Program

New version (the date of purchase is later than 2021.01.05, the board has the word Rev2.1):

sudo apt-get install p7zip-full
wget https://www.waveshare.net/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
cd Stepper_Motor_HAT_V2_Code/Raspberry\ PI/

If your purchase date is earlier than 2021.01.05, please do the following:

sudo apt-get install p7zip-full
wget http://www.waveshare.net/w/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 Program

Provide three programs, BCM2835, wiringPi, python
Do the following steps before running the program:
1. Raspberry Pi uses independent power supply
2. The DC port of the module is connected to 8.2V-28V power supply, and the switch is turned ON
3. Correctly connect the stepper motor

  • BCM2835 Demo
cd bcm2835/
make clean
make
sudo ./motor
  • wiringPi Demo
cd wiringpi/
make clean
make
sudo ./motor
  • Python Demo
cd python/
sudo python 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):

sudo apt-get install p7zip-full -y
wget https://www.waveshare.net/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
cd Stepper_Motor_HAT_V2_Code/Jetson\ nano/

If your purchase date is earlier than 2021.01.05, please do the following:

sudo apt-get install p7zip-full
wget http://www.waveshare.net/w/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

 Answer:
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 (channel 1) such as nema23 and nema14, if both are 1.8 The stepper motor needs 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.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
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

{{{3}}}
{{{4}}}

{{{5}}}



 Answer:
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.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
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.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Poke the switch here with a pen to the other side, the default setting is 32 subdivisions, and the program only runs 200 pulses, and the rotation angle is only 360/32 degrees, the phenomenon is difficult to see

Stepper motor hat 7.png

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Use the pen to poke the switch here to the other side, the default setting is 32 subdivisions

Stepper-motor-hat-faq.png

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
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. 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.png, 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
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
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 the risk of heat dissipation without a fan, 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.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
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.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
*New version (the purchase date is later than 2021.01.05, the PCB board is printed with the word Rev2.1)

You can enter the following commands in the terminal to download the demo:

sudo apt-get install p7zip-full
wget https://www.waveshare.com/w/upload/1/1f/Stepper_Motor_HAT_V2_Code.7z
7z x Stepper_Motor_HAT_V2_Code.7z -r -o./Stepper_Motor_HAT_V2_Code
sudo chmod 777 -R Stepper_Motor_HAT_V2_Code
cd Stepper_Motor_HAT_V2_Code/Raspberry\ PI/
  • If your purchase date is earlier than 2021.01.05, please perform the following:
sudo apt-get install p7zip-full
wget https://www.waveshare.com/w/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 high-level enable, so the motor will not work when the Raspberry Pi doesn't initialize the enable GPIO and let it output high-level.

{{{3}}}
{{{4}}}

{{{5}}}



Support

If you require technical support, please go to the Support page and open a ticket.