Page 1 of 1

Stepper motors

Posted: Thu Mar 30, 2017 2:39 pm
by altaylor
Hi,

I'm new to Raspberry Pi and programming. I am trying to learn (play) with the Pi and have done some simple projects. I've managed to connect and run a stepper motor (downloaded program) and am now trying to control two.
The programming is below. It doesn't give any errors, but nothing happens when run.


import RPi.GPIO as gpio
import time
import random
gpio.setwarnings(False)
DELAY = 0.001
PINS_A = [4,25,24,23]
PINS_B = [22,21,18,17]

pins = PINS_A + PINS_B

SEQA = [(4,),(4,25),(25,),(25,24),(24,),(24,23),(23,),(23,4)]
RSEQA = [(23,),(23,24),(24,),(24,25),(25,),(25,4),(4,),(4,23)]
SEQB = [(22,),(22,21),(21,),(21,18),(18,),(18,17),(17,),(17,22)]
RSEQB = [(17,),(17,18),(18,),(18,21),(21,),(21,22),(22,),(22,17)]
print (SEQA)
RSEQA = SEQA[::-1]
print (RSEQA)

gpio.setmode(gpio.BCM)
for pin in pins:
gpio.setup(pin,gpio.OUT)

def stepper(sequence, pin, delay=DELAY):
for step in sequence:
for pin in pins:
gpio.output(pin, gpio.HIGH) if pin in step else gpio.output(pin, gpio.LOW)
time.sleep(DELAY)
try:
while True:
rate = DELAY * random.randint(1,3)
for _ in range(random.randint(10,64)):
stepper(SEQB,PINS_B,rate)
for _ in range(random.randint(10,64)):
stepper(RSEQB,PINS_B,rate)
except KeyboardInterrupt:
gpio.cleanup()

Can't find the source I used.
I've used the previous codes and they control a single stepper correctly and this is the extension.

Any help or advice would be greatly appreciated to identify my errors.

Cheers

Al