Driving a Stepper Motor Using Beaglebone Black running Debian 7 Linux distribution

Hi guys… Here we will focus on Stepper Motor program on beaglebone black and also we look how it works with video tutorial.

Stepper Motor:

Stepper motors are DC motors that move in discrete steps. They have multiple coils that are organized in groups called “phases”. By energizing each phase in sequence, the motor will rotate, one step at a time.

With a Beaglebone controlled stepping you can achieve very precise positioning and/or speed control. For this reason, stepper motors are the motor of choice for many precision motion control applications.
For more about stepper motor go to link https://learn.adafruit.com/all-about-stepper-motors/what-is-a-stepper-motor”>Stepper Motor

We write this code in Python Language.. Use code as it is when doing program. Sometime you need to give GPIO values to stepper. This code is wrote by students of AISSMS’s Institute of Information Technology named Muskaan Khan, Purva Lila Satyam Singh Jordon Parag Suryawanshi, Rohit Pardesh and Shradha Bhagwat.


import sys
import time
import select
from stepperpins import *
from gpio import *

def stepperExit (gpio):
gpioSetVal(gpio, val="0")
gpioUnexport(gpio)
return
def stepperInit (gpio):
gpioExport(gpio)
gpioSetDir(gpio, flag="out")
gpioSetVal(gpio, val="0")
return
def stepperOn (gpio):
gpioSetVal(gpio, val="1")
return
def stepperOff (gpio):
gpioSetVal(gpio, val="0")
return
def stepperInitAll():
stepperInit(str(STEPPER_1))
stepperInit(str(STEPPER_2))
stepperInit(str(STEPPER_3))
stepperInit(str(STEPPER_4))
def stepperExitAll():
stepperExit(str(STEPPER_1))
stepperExit(str(STEPPER_2))
stepperExit(str(STEPPER_3))
stepperExit(str(STEPPER_4))
print "\n=== Demonstration END ===\n"
return
def stepperSeq5():
stepperOn(str(STEPPER_1))
time.sleep(0.0001)
stepperOff(str(STEPPER_2))
time.sleep(0.0001)
stepperOn(str(STEPPER_3))
time.sleep(0.0001)
stepperOff(str(STEPPER_4))
time.sleep(0.0001)
return
def stepperSeq9():
stepperOn(str(STEPPER_1))
time.sleep(0.0001)
stepperOff(str(STEPPER_2))
time.sleep(0.0001)
stepperOff(str(STEPPER_3))
time.sleep(0.0001)
stepperOn(str(STEPPER_4))
time.sleep(0.0001)
return
def stepperSeq10():
stepperOff(str(STEPPER_1))
time.sleep(0.0001)
stepperOn(str(STEPPER_2))
time.sleep(0.0001)
stepperOff(str(STEPPER_3))
time.sleep(0.0001)
stepperOn(str(STEPPER_4))
time.sleep(0.0001)
return
def stepperSeq6():
stepperOff(str(STEPPER_1))
time.sleep(0.0001)
stepperOn(str(STEPPER_2))
time.sleep(0.0001)
stepperOn(str(STEPPER_3))
time.sleep(0.0001)
stepperOff(str(STEPPER_4))
time.sleep(0.0001)
return
def stepperDirLeft():
stepperSeq5()
time.sleep(0.01)
stepperSeq9()
time.sleep(0.01)
stepperSeq10()
time.sleep(0.01)
stepperSeq6()
time.sleep(0.01)
return
def stepperDirRight():
stepperSeq6()
time.sleep(0.01)
stepperSeq10()
time.sleep(0.01)
stepperSeq9()
time.sleep(0.01)
stepperSeq5()
time.sleep(0.01)
return

try:
print "\nStepper Motor Driver using Python\n"
print "-----------------------------------------------\n"
stepperInitAll()
while True:
for i in range(0, 12):
stepperDirLeft()
time.sleep(3)
for i in range(0, 12):
stepperDirRight()
time.sleep(3)
stepperExitAll
exit()
except KeyboardInterrupt:
stepperExitAll()
print "Program Exit due to CTRL-C"
exit()
sys.exit(0)

Leave a Reply

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