/forum/index.php?action=view&id=167

Welcome InMyPi Forum / Guestbook




DLD Sat 8 Dec 2018 at 12:54:56
Stepper Motor Control with the Raspberry Pi

-
Gaven MacDonald
Published on Jul 17, 2013

This video outlines both how stepper motors work, and how to control one using the Raspberry Pi.

Learn more about programming, electronics, and the Raspberry Pi at:
=>://cutequbit.zapto.org

website is down
think this looks like his python code in the video
maybe with qbasic MOD 4 or 8 or
or outputval=stepcounter%4 or outputval=stepcounter%8 in c / python the code can be simpler
wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/stepper.py
#!/usr/bin/python
#--------------------------------------
#    ___  ___  _ ____          
#   / _ \/ _ \(_) __/__  __ __ 
#  / , _/ ___/ /\ \/ _ \/ // / 
# /_/|_/_/  /_/___/ .__/\_, /  
#                /_/   /___/   
#
#    Stepper Motor Test
#
# A simple script to control
# a stepper motor.
#
# Author : Matt Hawkins
# Date   : 28/09/2015
#
# http://www.raspberrypi-spy.co.uk/
#
#--------------------------------------


# Import required libraries
import sys
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO signals to use
# Physical pins 11,15,16,18
# GPIO17,GPIO22,GPIO23,GPIO24
StepPins = [17,22,23,24]

# Set all pins as output
for pin in StepPins:
  print "Setup pins"
  GPIO.setup(pin,GPIO.OUT)
  GPIO.output(pin, False)

# Define advanced sequence
# as shown in manufacturers datasheet
Seq = [[1,0,0,1],
       [1,0,0,0],
       [1,1,0,0],
       [0,1,0,0],
       [0,1,1,0],
       [0,0,1,0],
       [0,0,1,1],
       [0,0,0,1]]
       
StepCount = len(Seq)
StepDir = 1 # Set to 1 or 2 for clockwise
            # Set to -1 or -2 for anti-clockwise

# Read wait time from command line
if len(sys.argv)>1:
  WaitTime = int(sys.argv[1])/float(1000)
else:
  WaitTime = 10/float(1000)

# Initialise variables
StepCounter = 0

# Start main loop
while True:

  print StepCounter,
  print Seq[StepCounter]

  for pin in range(0, 4):
    xpin = StepPins[pin]
    if Seq[StepCounter][pin]!=0:
      print " Enable GPIO %i" %(xpin)
      GPIO.output(xpin, True)
    else:
      GPIO.output(xpin, False)

  StepCounter += StepDir

  # If we reach the end of the sequence
  # start again
  if (StepCounter>=StepCount):
    StepCounter = 0
  if (StepCounter<0):
    StepCounter = StepCount+StepDir

  # Wait before moving on
  time.sleep(WaitTime)
IFRAME shows www.luberth.com/plotter/mod_javascript.html


End of Message, Thanks For Viewing! ☺
Tip: if your watching on your phone or tablet ⁝ add / save to homescreen and you get a nice icon its Free!
Tip: on your computer or laptop do not forget to bookmark this page its Free!
BookMark ShortCut Keys press ctrl+d on your keyboard




-

-

Reply to this Message


Name
Subject
Message

, <code> <b> <i> <u> .

   


Design a Bit like ForumOne 4.0 WayBack 1999 ©
Always Read the Small print?!



http://forum.luberth.com - - http://www.luberth.com/forum/




Page Optimized for Netscape Navigator 2.0 or Newer Real Gecko ;-)




Domoticz/#/Floorplans Co2 FootPrint of this RaspBerry Pi 3B+ DeskTop PC & WebServer