Skip to content

Instantly share code, notes, and snippets.

@theapi
Last active December 22, 2015 09:59
Show Gist options
  • Save theapi/6455725 to your computer and use it in GitHub Desktop.
Save theapi/6455725 to your computer and use it in GitHub Desktop.
Very basic script that rotates a stepper motor with a Raspberry Pi.
#!/usr/bin/env python
# Thanks to http://www.youtube.com/watch?v=Dc16mKFA7Fo
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
ControlPin = [18,22,24,26]
for pin in ControlPin:
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, 0)
seq = [ [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] ]
for i in range(256):
for halfstep in range(8):
for pin in range(4):
GPIO.output(ControlPin[pin], seq[halfstep][pin])
time.sleep(0.01)
time.sleep(2)
for i in range(256):
for halfstep in reversed(range(8)):
for pin in range(4):
GPIO.output(ControlPin[pin], seq[halfstep][pin])
time.sleep(0.001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment