Controlling Nema 14 Stepper Motor via Raspberry Pi


This post is to share some details on the setup to control Nema 14 stepper motor.

First of all, all the credit goes to a person who put this video that explains wiring and walks through some sample code:

The code itself is straightforward (this is what takes to rotate the stepper motor 360 degrees clockwise):

import time
import RPi.GPIO as GPIO

GPIO.setup(20, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
GPIO.output(20, 1)

for x in range(200):
    GPIO.output(21, GPIO.HIGH)
    GPIO.output(21, GPIO.LOW)


Below are the components used in this test.

The Raspberry Pi Zero W costs £12.82 (+delivery, in my case £2.99). It’s from here:

Nema 14 Stepper Motor costs $7.62 (+delivery, in my case $4.80). It’s from here:

DRV8825 Stepper Motor Driver Carrier costs $3.58 (free shipping to the UK). It’s from here:

100UF 100V Electrolytic Capacitor costs $2.49 (this is for 20 units, we need only one. Also free shipping to the UK). It’s from here:

A couple of things that is worth mentioning. First, it’s essential to adjust “Vref Potentiometer” correctly. We have it currently set to 0.05V, but when it was set to 0.2V the stepper motor produced high pitch sound. Second, it’s crucial to connect everything correctly! Initially, I made a mistake and attached the negative capacitor leg to the positive wire. Everything worked initially, but then the capacitor started to heat and expand. After replacing it and connecting correctly, everything seems to be working just fine.

The sample python code is available here: