sudo apt-get install python-rpi.gpio python3-rpi.gpio
This script has the control pins hardcoded to 7,11,13 and 15. Change as needed Pin Photo Locations: https://miro.medium.com/max/6048/1*xtuwVdcX1gx9rEQiyvBRhg.jpeg
import RPi.GPIO as GPIO | |
import time | |
import sys | |
args = sys.argv[1:] | |
GPIO.setmode(GPIO.BOARD) | |
controlPins = [7,11,13,15] | |
for pin in controlPins: | |
GPIO.setup(pin, GPIO.OUT) | |
GPIO.output(pin, 0) | |
halfstepSeq = [ | |
[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], | |
[1,0,0,1] | |
] | |
reverseHalfstepSeq = [ | |
[1,0,0,1], | |
[0,0,0,1], | |
[0,0,1,1], | |
[0,0,1,0], | |
[0,1,1,0], | |
[0,1,0,0], | |
[1,1,0,0], | |
[1,0,0,0] | |
] | |
def boolify(strInput): | |
return strInput.lower() in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh'] | |
def rotate(rotations=1, counterClockwise=False): | |
steps = int(512*rotations) | |
sequence = reverseHalfstepSeq if counterClockwise else halfstepSeq | |
for i in range(steps): | |
for halfstep in range(len(sequence)): | |
for pin in range(len(controlPins)): | |
GPIO.output(controlPins[pin], sequence[halfstep][pin]) | |
time.sleep(0.001) | |
if __name__ == "__main__": | |
rotations = float(args[0]) if len(args) > 0 else 1 | |
counterClockwise = boolify(args[1]) if len(args) > 1 else False | |
rotate(rotations, counterClockwise) | |
GPIO.cleanup() |
sudo apt-get install python-rpi.gpio python3-rpi.gpio
This script has the control pins hardcoded to 7,11,13 and 15. Change as needed Pin Photo Locations: https://miro.medium.com/max/6048/1*xtuwVdcX1gx9rEQiyvBRhg.jpeg