Controlling a stepper motor with the Raspberry Pi and Piface

Updated April 2015

I have made this because I have found no projects using the PiFace.

Forum topic at www.raspberrypi.org:
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=54314&p=413902
Here is a simple project that only needs a Raspberry Pi, PiFace, Python, jumper wires, and a stepper motor – that's it!Controlling a stepper motor with the Raspberry Pi and Piface

Step 1: Schematic

Step 2: Connect the PiFace to the Raspberry Pi

Put the PiFace breakout board onto the GPIO connectors pf the Raspberry Pi.

Simple 😉

Step 3:

First connect a jumper wire from ‘ 5 v' to red wire on motor.

Step 4:

Second connect a jumper wire from ‘output 4' to orange wire on motor.

Step 5:

Third connect a jumper wire from ‘output 5' to yellow wire on motor.

Step 6:

Fourth connect a jumper wire from ‘output 6' to pink wire on motor.

Step 7:

Fifth connect a jumper wire from ‘output 7' to blue wire on motor.

Step 8:

Sixth type this into a python file (or copy-paste):

  #CONTROLLING A STEPPER MOTOR
  #Author: Robert Caldwell
  #Date: 14 August 2013
  
  from time import sleep
  import piface.pfio as pfio
  pfio.init()
  
  print"Type: direction(rotations, speed)"
  
  def anticlockwise(rotations, speed):
      sleep_time=0.1 / float(speed)
      for loop in range(1,int(512*float(rotations))):
          pfio.digital_write(4,1)
          sleep(sleep_time)
          pfio.digital_write(7,0)
          sleep(sleep_time)
          pfio.digital_write(5,1)
          sleep(sleep_time)
          pfio.digital_write(4,0)
          sleep(sleep_time)
          pfio.digital_write(6,1)
          sleep(sleep_time)
          pfio.digital_write(5,0)
          sleep(sleep_time);
          pfio.digital_write(7,1);
          sleep(sleep_time)
          pfio.digital_write(6,0)
          sleep(sleep_time)
      pfio.digital_write(7,0)
  
  def clockwise(rotations, speed)
      sleep_time=0.1 / float(speed)
      for loop in range(1,int(512*float(rotations)))
          pfio.digital_write(7,1)
          sleep(sleep_time)
          pfio.digital_write(4,0)
          sleep(sleep_time)
          pfio.digital_write(6,1)
          sleep(sleep_time)
          pfio.digital_write(7,0)
          sleep(sleep_time)
          pfio.digital_write(5,1)
          sleep(sleep_time)
          pfio.digital_write(6,0)
          sleep(sleep_time)
          pfio.digital_write(4,1)
          sleep(sleep_time)
          pfio.digital_write(5,0)
          sleep(sleep_time)
      pfio.digital_write(4,0)

Controlling a stepper motor with the Raspberry Pi and Piface schematicStep 9:

Done!
The motor I used was 28BYJ48 5V DC
Your motor should now obey orders you type!
(make your speed 10-600)

If you have any problems, ask me!

 

For more detail: Controlling a stepper motor with the Raspberry Pi and Piface


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top