1| Supported Targets | ESP32-S2 | ESP32-C3 | ESP32-S3 | 2| ----------------- | -------- | -------- | -------- | 3 4# RMT Transmit Loop Example -- Step Motor controller 5 6(See the README.md file in the upper level 'examples' directory for more information about examples.) 7 8RMT peripheral can send customized RMT items in a loop, which means we can use it to generate a configurable length of periodic signal, with accurate number of pulses. 9 10This example will show how to control an A4988 based step motor driver to step accurately with simple APIs, based on the RMT loop feature. The example also implements a [Smoothstep](https://en.wikipedia.org/wiki/Smoothstep) feature which works out of the box. 11 12## How to Use Example 13 14### Hardware Required 15 16* Recommend running this example on development board with SOC chip that support loop auto-stop feature by hardware (e.g. ESP32-S3) 17* A USB cable for Power supply and programming 18* A 4-wire (A+, A-, B+, B-) step motor 19* An A4988 module 20 21Connection : 22 23``` 24+----------------+ +--------------------+ +--------------+ 25| | | A4988 | | 4-wire | 26| GND +-------------+ GND | | Step | 27| | | | | Motor | 28| 5V +-------------+ VDD 1B +------+ A2 | 29| | | | | | 30| GPIO18 +------------>+ DIRECTION 1A +------+ A1 | 31| | | | | | 32| ESP GPIO17 +------------>+ STEP 2A +------+ B1 | 33| | | | | | 34| GPIO16 +------------>+ SLEEP 2B +------+ B2 | 35| | | | +--------------+ 36| GPIO15 +------------>+ RESET VMOT +-------------------+ 37| | | | | 38| GPIO7 +------------>+ MS3 GND +----------+ | 39| | | | | | 40| GPIO6 +------------>+ MS2 | | | 41| | | | | | 42| GPIO5 +------------>+ MS1 | +---+--------+-----+ 43| | | | | GND +12V | 44| GPIO4 +------------>+ ENABLE | | POWER SUPPLY | 45+----------------+ +--------------------+ +------------------+ 46 47``` 48 49IO mapping on ESP side can be changed in `step_motor_main.c`: 50 51```c 52// GPIO configuration 53#define STEP_MOTOR_DIRECTION_PIN GPIO_NUM_18 54#define STEP_MOTOR_STEP_PIN GPIO_NUM_17 55#define STEP_MOTOR_SLEEP_PIN GPIO_NUM_16 56#define STEP_MOTOR_RESET_PIN GPIO_NUM_15 57#define STEP_MOTOR_MS3_PIN GPIO_NUM_7 58#define STEP_MOTOR_MS2_PIN GPIO_NUM_6 59#define STEP_MOTOR_MS1_PIN GPIO_NUM_5 60#define STEP_MOTOR_ENABLE_PIN GPIO_NUM_4 61``` 62 63### Build and Flash 64 65Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. 66 67(To exit the serial monitor, type ``Ctrl-]``.) 68 69See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. 70 71 72## Example Output 73 74``` 75I (344) step_motor: init 76I (344) step_motor: set_step 77I (1354) step_motor: step 10 @ 1000/s 78I (2364) step_motor: step 100 @ 1000/s 79I (3464) step_motor: step 1000 @ 1200/s 80I (5294) step_motor: step 5000 @ 1400/s 81I (9864) step_motor: smoothstep start 5000 steps @ 500~1400/s 82I (14454) step_motor: smoothstep finish 83I (15454) step_motor: continuous running for 5s 84I (20454) step_motor: stop 85I (21504) step_motor: deinit 86``` 87 88Motor should move as output indicates. 89 90## Troubleshooting 91 92For any technical queries, please open an [issue] (https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. 93