ESP32 - Stepper Motor
This tutorial is currently updating.
|1||×||ESP-WROOM-32 Dev Module|
|1||×||Micro USB Cable|
About Stepper Motor
There are two types of step motors: bipolar stepper motor and unipolar stepper motor. They differ from each other in the internal structure and the working principle.
With the naked eyes, they look similar to each other. However, we can distinguish them by the number of wires. The bipolar motor usually has four wires. The unipolar motor usually has six wires.
Controlling the bipolar stepper motor and the unipolar stepper motor is different. Fortunately, we can control the unipolar stepper as if it is a bipolar stepper motor by using four of six wires.
How To Control Stepper Motor with ESP32
The stepper motor requires more power than ESP32 board can give it, so you’ll need another power supply for it. Ideally, Stepper motor's datasheet or manual lets you know the voltage of the power supply.
We CANNOT connect the stepper motor directly to ESP32. We MUST connect via a motor driver or motor controller.
The motor driver and motor controller can be:
- Chip (e.g. SN754410)
- Module (e.g. A4988)
Using ESP32 Motor Shield Rev3
- Stack ESP32 Motor Shield Rev3 on ESP32
- Connect stepper motor to ESP32 Motor Shield Rev3
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE
- Download or copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to compile and upload code to ESP32 board
- Open Serial Monitor to see result:
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
1. Stepper motor vibrates while moving
Do NOT worry if the stepper motor vibrates while moving. This is a characteristic of the stepper motor. We can reduce vibration by using the micro-stepping control method.
Also, because of this characteristic, if we control properly, the stepper motor can produce musical sounds as if it is a musical instrument. You can see this project on ESP32 Project Hub.
2. Method of controlling stepper motors
- Full-step: The unit of moving is one step, which is equivalent a value of degree specified in stepper motor's datasheet or manual.
- Half-step: divides each full step into two smaller steps. The unit of moving is half of the full step. This method allows the motor move with double resolution.
- Micro-step: divides each full step into many smaller steps. The unit of moving is a fraction of the full step. The fraction can be 1/4, 1/8, 1/16, 1/32 or even more. This method allows the motor move with higher resolution. It also make motor move smoother at low speeds. The bigger dividend is, the higher resolution and the smoother motion is.
For example, If the motor's datasheet specifies 1.8 degree/step:
- Full-step: The motor can move with 1.8 degree/step <⇒ 200 steps/ revolution
- Half-step: The motor can move with 0.9 degree/step <⇒ 400 steps/ revolution
- Micro-step: The motor can move with 0.45, 0.225, 1125, 0.05625 degree/step <⇒ 800, 1600, 3200, 6400... steps/ revolution
The above code used the full-step control method.
3. Resonance Issue
This is the advanced usages. The beginners do NOT need to pay attention to it. This happens in a speed range, in which the step rate equals the motor’s natural frequency. There may be an audible change in noise made by the motor, as well as an increase in vibration. In real applications, the developer SHOULD pay attention to this issue.
※ NOTE THAT:
Note that this tutorial is incomplete. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.