Control a steppermotor with a raspberry Pi

This post describe how to control a steppermotor with a Raspberry Pi.

Supplies needed:

  • Easydriver (i use the 4.4 version)
  • jumper wires (female – male)
  • A raspberry Pi offcourse
  • A breadboard
  • Restistors 4.4k Ohm
  • A steppermotor NEMA 17
  • Installed with Raspbian


To connect the Raspberry Pi to the easydriver i use the mapping in this table.

I use a breadboard. This make it easier to connect different wires to the Pi and Easydriver.

Circuit with Raspberry & Easydriver

I used a breadboard to connect the Raspberry Pi with the easydriver and motor. You can also connect the Pi directly to the easydriver.

Secondly i used pulldown resistors on the switching wires. For testing purpose this is not necessary and from Easydriver v4.5 the pulldown resistors are on the easydriver board.
For testingpurpose the motor is powered by the Raspberry Pi. In a real live situation you need an external power supply.

Control the steppermotor with Python

Create the following file: ‘~/’.

vim ~/

In the file paste the following text

import RPi.GPIO as GPIO, time

GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.output(16, True)

#iemand anders 500
p = GPIO.PWM(16, 5000)

def SpinMotor(direction, num_steps):
    GPIO.output(18, direction)
    while num_steps > 0:
        num_steps -= 1
    return True

direction_input = raw_input('Please enter O or C fro Open or Close:')
num_steps = input('Please enter the number of steps: ')
if direction_input == 'C':
    SpinMotor(False, num_steps)
    SpinMotor(True, num_steps)

As you can see we use PIN16 and PIN18 as output. Those pins control the directorion and the amount of steps to run. Make the file executable.

chmod +x ~/
#and play arround

Pin22 is connected to ENABLED. By default the easydriver chip is enabled and it consumes power. When you connect an external power supply with a higher voltage, the chip becomes very hot. Disable the chip by turning this pin on (or off).

About the author