loading

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!

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)

Step 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!

<p>hi</p><p>i want to controler 2 stepper motor with rasbperry pi 3 (python) </p><p>how!!!!</p>
<p>Thank you for this great tutorial, which was the basis for my project driving a small bipolar stepper motor using the PiFace (and a diy H-Bridge). I made a small modification to make it more precise though:The loop should start at 0 and not 1 :</p><blockquote>for loop in range(0,int(512*float(rotations)))</blockquote><p>or</p><blockquote>for loop in range(int(512*float(rotations)))</blockquote><p>This difference would not be noticeable in a motor which needs 512 steps for a full rotation but it was in my case (7.5 degrees steps =&gt; 30 degrees per loop iteration =&gt; 12 loop iterations for a full rotation) so my loop was like this:</p><blockquote>for loop in range(int(12*float(rotations)))</blockquote>
<p>My python shell tells me that there's a mistake in the line #6</p><p>import piface.pfio as pfio<br>ImportError: No module named piface.pfio</p>
<p>See page two here:</p><p>http://www.farnell.com/datasheets/1684425.pdf</p>
<p>the motor is bipolar</p>
<p>hey, can I use raspberry to make a CNC controller ?</p>
<p>I love it!!! I translated it for the PiFaceDigitalIO library:</p><p>Here is your code redone</p><p>#CONTROLLING A STEPPER MOTOR</p><p>#Author: Robert Caldwell</p><p>#Date: 14 August 2013</p><p>from time import sleep</p><p>import pifacedigitalio as p</p><p>p.init(False)</p><p>pfd = p.PiFaceDigital()</p><p>print(&quot;Type: direction(rotations, speed)&quot;)</p><p>def anticlockwise(rotations, speed):</p><p> sleep_time=0.1 / float(speed)</p><p> for loop in range(1,int(512*float(rotations))):</p><p> pfd.output_pins[4].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[7].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[5].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[4].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[6].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[5].turn_off()</p><p> sleep(sleep_time);</p><p> pfd.output_pins[7].turn_on();</p><p> sleep(sleep_time)</p><p> pfd.output_pins[6].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[7].turn_off()</p><p>def clockwise(rotations, speed):</p><p> sleep_time=0.1 / float(speed)</p><p> for loop in range(1,int(512*float(rotations))):</p><p> pfd.output_pins[7].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[4].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[6].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[7].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[5].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[6].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[4].turn_on()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[5].turn_off()</p><p> sleep(sleep_time)</p><p> pfd.output_pins[4].turn_off()</p>
<p>Sorry It did not seem to import the indents which are very important</p><p> Doug Wyman</p>
<p>Nice :)</p>
Does this leave a pi face output spare for an LED?
Yes it can I will post a guide for controlling an LED soon. <br>(PS you can use a breadboard to divide up which parts go where)
Next thing to do is a Raspberry Pi as a CNC controller
Like this sort of thing:<br> <a href="http://Like this sort of thing: http://funofdiy.blogspot.ca/2013/10/a-raspberry-pi-controlled-mini-laser.html" rel="nofollow">http://funofdiy.blogspot.ca/2013/10/a-raspberry-pi-controlled-mini-laser.html</a>
Right like this! Nice!
ok too many pics of the same thing. where are the images of the actual project steps? <br>if its not complete, dont hit publish. it is still saved in your account.
I added better pics now
:) <br>

About This Instructable

93,320views

151favorites

More by bertwert:Choosing your first DSLR Homemade Camera Lens bertwert 
Add instructable to: