Created
November 29, 2019 22:13
-
-
Save freegroup/8ec0a5a8442d7fdeaf247bd80c07ae35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stel de GPIO pinnen in voor de stappenmotor: | |
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,18,27,22] | |
StepPins = [23,24,25,4] | |
#StepPins = [13,12,6,5] | |
#StepPins = [20,26,16,19] | |
# Set all pins as output | |
for pin in StepPins: | |
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 = 0.001 | |
# Initialise variables | |
StepCounter = 0 | |
# Start main loop | |
while True: | |
for pin in range(0, 4): | |
xpin = StepPins[pin]# | |
if Seq[StepCounter][pin]!=0: | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment