Stepper Motor Control Using Pi Face And Raspberry Pi

0

Stepper Motor Control Using Pi Face And Raspberry Pi

Stepper Motor Control Using Pi Face And Raspberry Pi

The below lesson is a very simple lesson which uses stepper motor, Raspberry Pi, PiFace, some jumper wires and Python.

Step 1:

Raspberry Pi – Graphical Representation of Stepper motor

Below diagram shows schematic representation of stepper motor

Graphical Representation of Stepper motor

Show All Items

Step 2:

Raspberry Pi – Establishing connection between Raspberry Pi and PiFace

The breakout board of Pi Face is connected with the GPIO connector pin of the Raspberry Pi.

Step 3:

Establish connection between Raspberry Pi & PiFace

The 5 V of PiFace is connected with the red wire of stepper motor using jumper wire as shown in the image.

Show All Items

Step 4:

Rasberry Pi - Output 4 Connect A Jumper Wire

Rasberry Pi – From Output 4 Connect A Jumper Wire

Show All Items

The next step is to connect the output 4 of PiFace with the orange wire of motor using jumper wires as per below image.

Step 5:

Raspberry Pi - Output 5 Connect A Jumper Wire

 

Raspberry Pi – From Output 5 Connect A Jumper Wire

Show All Items

Then the output 5 of PiFace is connected with the yellow wire of the motor using jumper wire as per the below image.

Step 6:

Raspberry Pi – From Output 6 Connect A Jumper Wire

Raspberry Pi - Output 6 Connect A Jumper Wire

Show All Items

Next is to connect output 6 of the Pi Face with the pink wire of the motor using jumper wire as per below image.

 Step 7: 

Raspberry Pi – From Output 7 Connect A Jumper Wire

Raspberry Pi - Output 7 Connect A Jumper Wire

Show All Items

Lastly, connect the output 7 of PiFace with blue wire of the stepper motor using jumper wire as shown in below image.

Step 8:

Raspberry Pi – Python code

Raspberry Pi - Python code

Show All Items

The next step is to write some lines of code using python programming language. You can copy the below code into a python file:

#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:

Raspberry Pi – Its Complete.

Cpmplete Python Code Ready to Function

The motor is ready to function as per the commands given by you. You can use 28BYJ48 motor with 5V DC supply.

Please feel free to contact me for any queries. Thanks.

Share.

About Author

Leave A Reply