Difference between revisions of "Controlling a stepper motor with python"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="pythom"> import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) control_pins = [7,11,13,15] for pin in control_pins: GPIO.setup(pin, GPIO.OUT) GP...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<source lang="pythom">
+
[[ The code to control a stepper motor ]]<br>
import RPi.GPIO as GPIO
+
[[ File:Pi-2-header.jpg|600px ]]
import time
+
+
GPIO.setmode(GPIO.BOARD)
+
+
control_pins = [7,11,13,15]
+
+
for pin in control_pins:
+
  GPIO.setup(pin, GPIO.OUT)
+
  GPIO.output(pin, 0)
+
+
halfstep_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(512):
+
  for halfstep in range(8):
+
    for pin in range(4):
+
      GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
+
    time.sleep(0.001)
+
+
GPIO.cleanup()
+
</source>
+

Latest revision as of 07:49, 18 May 2019

The code to control a stepper motor
Pi-2-header.jpg