How to Control Stepper Motor with Raspberry Pi Pico and A4988 Driver in Wokwi - Complete Step-by-Step Tutorial
Project Overview
This comprehensive guide demonstrates how to control a stepper motor using a Raspberry Pi Pico microcontroller and an A4988 stepper motor driver in the Wokwi online simulator. Learn precise motor control, microstepping, direction changes, and speed adjustment for robotics, CNC, and automation projects.
What You'll Learn
- Stepper motor operation principles
- A4988 driver module configuration
- Raspberry Pi Pico GPIO control
- Motor speed and direction programming
- Microstepping techniques
- Wokwi simulation for motor projects
Components Required in Wokwi
Hardware (Virtual):
- 1x Raspberry Pi Pico board
- 1x A4988 Stepper Motor Driver module
- 1x NEMA 17 Stepper Motor (or similar bipolar stepper)
- Power supply (12V for motor - simulated in Wokwi)
- Jumper wires (automatic in Wokwi)
Software:
- MicroPython firmware
- Motor control library
Understanding Stepper Motors
What is a Stepper Motor?
A stepper motor is a brushless DC motor that divides a full rotation into equal steps. Unlike regular DC motors, steppers move in precise, repeatable increments.
Key Characteristics:
- Step Angle: Typically 1.8° (200 steps per revolution)
- Bipolar vs Unipolar: This project uses bipolar (4 wires)
- Holding Torque: Motor stays in position when powered
- Precise Positioning: No feedback sensors needed
Common Applications:
- 3D printers
- CNC machines
- Robotics
- Camera sliders
- Automated curtains
Understanding the A4988 Driver
The A4988 is a popular stepper motor driver that:
- Controls motor current
- Enables microstepping (1/16 step resolution)
- Protects against overcurrent
- Simplifies control to just STEP and DIR signals
A4988 Pin Configuration:
| Pin Name | Function | Description |
|---|---|---|
| VMOT | Motor Power | 8-35V power supply for motor |
| GND | Ground | Power ground |
| 1A, 1B | Motor Coil 1 | Connect to motor coil A |
| 2A, 2B | Motor Coil 2 | Connect to motor coil B |
| VDD | Logic Power | 3-5.5V logic power (from Pico) |
| GND | Logic Ground | Logic ground |
| STEP | Step Input | Pulse to move one step |
| DIR | Direction | HIGH = CW, LOW = CCW |
| ENABLE | Enable | LOW = enabled, HIGH = disabled |
| MS1, MS2, MS3 | Microstep Select | Set stepping resolution |
| RESET | Reset | Keep HIGH for normal operation |
| SLEEP | Sleep Mode | Keep HIGH for operation |
Step-by-Step Wokwi Setup Instructions
Step 1: Create New Raspberry Pi Pico Project
- Navigate to https://wokwi.com
- Click "New Project"
- Select "Raspberry Pi Pico"
- Pico board appears on canvas
Step 2: Add A4988 Stepper Driver Module
- Click the blue "+" (Add Part) button
- Search for "A4988" or "Stepper Driver"
- Select "A4988 Stepper Motor Driver"
- Place it to the right of the Pico
Note: If A4988 isn't available, search for generic stepper driver modules.
Step 3: Add Stepper Motor
- Click the "+" button
- Search for "Stepper Motor" or "NEMA 17"
- Select "Stepper Motor"
- Place it above the A4988 driver
Step 4: Understanding the Wiring Connections
Complete Connection Table:
| A4988 Pin | Raspberry Pi Pico Pin | Wire Color | Notes |
|---|---|---|---|
| VDD | 3V3 (OUT) | Red | Logic power 3.3V |
| GND | GND | Black | Logic ground |
| STEP | GPIO 2 | Blue | Step pulse signal |
| DIR | GPIO 3 | Green | Direction control |
| ENABLE | GND | Black | Always enabled (grounded) |
| RESET | VDD | Red | Keep high (connect to VDD) |
| SLEEP | VDD | Red | Keep awake (connect to VDD) |
| VMOT | External 12V+ | Red | Motor power supply |
| GND | External GND | Black | Motor power ground |
Motor to A4988 Connections:
| Motor Wire | A4988 Pin | Coil |
|---|---|---|
| Coil A+ (Red) | 1A | Coil 1 |
| Coil A- (Green) | 1B | Coil 1 |
| Coil B+ (Blue) | 2A | Coil 2 |
| Coil B- (Yellow) | 2B | Coil 2 |
Microstepping Configuration (Optional):
| MS1 | MS2 | MS3 | Step Resolution |
|---|---|---|---|
| LOW | LOW | LOW | Full step |
| HIGH | LOW | LOW | 1/2 step |
| LOW | HIGH | LOW | 1/4 step |
| HIGH | HIGH | LOW | 1/8 step |
| HIGH | HIGH | HIGH | 1/16 step |
For this tutorial, leave MS1, MS2, MS3 unconnected (defaults to full step).
Step 5: Wire the Circuit in Wokwi
Power Connections:
- Logic Power (Pico to A4988):
- Pico 3V3 (OUT) → A4988 VDD (red wire)
- Pico GND → A4988 GND (black wire)
- Motor Power (External Supply to A4988):
- In Wokwi, click "+" and add "Power Supply"
- Power Supply +12V → A4988 VMOT (red wire)
- Power Supply GND → A4988 GND (black wire)
- Also connect Power Supply GND to Pico GND (common ground)
Control Signal Connections:
- Pico GPIO 2 → A4988 STEP (blue wire)
- Pico GPIO 3 → A4988 DIR (green wire)
- A4988 ENABLE → Pico GND (enables driver)
- A4988 RESET → A4988 VDD (keeps driver active)
- A4988 SLEEP → A4988 VDD (prevents sleep mode)
Motor Connections:
- Stepper Motor Coil A+ (Red) → A4988 1A
- Stepper Motor Coil A- (Green) → A4988 1B
- Stepper Motor Coil B+ (Blue) → A4988 2A
- Stepper Motor Coil B- (Yellow) → A4988 2B
Wokwi Tip: Colors are suggested - Wokwi automatically assigns colors. Click each pin and drag to create connections.

Comments
Post a Comment