├── git_update.sh ├── test-trigger.sh ├── Stepper.pyc ├── ADXL345 ├── a.out ├── basic.py ├── tap.py └── test.c ├── __pycache__ └── Stepper.cpython-32.pyc ├── test-all-motors.sh ├── HMC5883L └── test-sensor.py ├── polkatrigger.py ├── test-motor.py ├── trigger-motor.py ├── thread-test.py ├── README.md ├── polkarobot.py ├── polkarobot2.py ├── mh-stepper.py ├── Stepper.py └── sp-move.py /git_update.sh: -------------------------------------------------------------------------------- 1 | git add * 2 | git commit . 3 | git push 4 | -------------------------------------------------------------------------------- /test-trigger.sh: -------------------------------------------------------------------------------- 1 | python3 trigger-motor.py 8 10 12 16 -1 180 2 | 3 | -------------------------------------------------------------------------------- /Stepper.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recantha/stepper-pi/HEAD/Stepper.pyc -------------------------------------------------------------------------------- /ADXL345/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recantha/stepper-pi/HEAD/ADXL345/a.out -------------------------------------------------------------------------------- /__pycache__/Stepper.cpython-32.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recantha/stepper-pi/HEAD/__pycache__/Stepper.cpython-32.pyc -------------------------------------------------------------------------------- /test-all-motors.sh: -------------------------------------------------------------------------------- 1 | python test-motor.py 8 10 12 16 & 2 | python test-motor.py 18 22 24 26 & 3 | python test-motor.py 3 5 7 11 & 4 | python test-motor.py 15 19 21 23 & 5 | 6 | -------------------------------------------------------------------------------- /ADXL345/basic.py: -------------------------------------------------------------------------------- 1 | from i2clibraries import i2c_adxl345 2 | from time import * 3 | 4 | adxl345 = i2c_adxl345.i2c_adxl345(1) 5 | 6 | while True: 7 | print(adxl345) 8 | sleep(1) 9 | -------------------------------------------------------------------------------- /HMC5883L/test-sensor.py: -------------------------------------------------------------------------------- 1 | from i2clibraries import i2c_hmc5883l 2 | 3 | hmc = i2c_hmc5883l.i2c_hmc5883l(1) 4 | 5 | hmc.setContinuousMode() 6 | hmc.setDeclination(-1,22) 7 | 8 | (degrees, minutes) = hmc.getHeading() 9 | print(degrees) 10 | print(minutes) 11 | print(hmc.getHeadingString()) 12 | -------------------------------------------------------------------------------- /polkatrigger.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from Stepper import Motor 4 | from time import sleep 5 | import RPi.GPIO as GPIO 6 | import sys 7 | import datetime 8 | import subprocess 9 | 10 | mFL = [ 8, 10, 12, 16] 11 | mFR = [18, 22, 24, 26] 12 | mBL = [ 3, 5, 7, 11] 13 | mBR = [15, 19, 21, 23] 14 | 15 | subprocess.call(["python trigger-motor.py " + str(mFL[1])]) 16 | -------------------------------------------------------------------------------- /test-motor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from Stepper import Motor 4 | from time import sleep 5 | import RPi.GPIO as GPIO 6 | import sys 7 | 8 | 9 | if __name__ == "__main__": 10 | GPIO.setmode(GPIO.BOARD) 11 | 12 | m = Motor([int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4])], 15) 13 | 14 | # clock 180 15 | m.move_to(180) 16 | sleep(0.2) 17 | m.move_to(270) 18 | sleep(0.5) 19 | m.move_to(0) 20 | m.move_to(-90) 21 | GPIO.cleanup() 22 | 23 | -------------------------------------------------------------------------------- /trigger-motor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from Stepper import Motor 4 | import RPi.GPIO as GPIO 5 | import sys 6 | 7 | 8 | if __name__ == "__main__": 9 | GPIO.setmode(GPIO.BOARD) 10 | 11 | pin1 = int(sys.argv[1]) 12 | pin2 = int(sys.argv[2]) 13 | pin3 = int(sys.argv[3]) 14 | pin4 = int(sys.argv[4]) 15 | direction = int(sys.argv[5]) 16 | angle = int(sys.argv[6]) 17 | 18 | m = Motor([pin1,pin2,pin3,pin4], 15) 19 | if direction == -1: 20 | m.move_acw(angle) 21 | 22 | GPIO.cleanup() 23 | 24 | -------------------------------------------------------------------------------- /ADXL345/tap.py: -------------------------------------------------------------------------------- 1 | from i2clibraries import i2c_adxl345 2 | from time import * 3 | 4 | adxl345 = i2c_adxl345.i2c_adxl345(1) 5 | 6 | adxl345.setTapAxes(adxl345.TA_TapZAxis) 7 | adxl345.setInterrupt(adxl345.SingleTap, adxl345.DoubleTap) 8 | 9 | while True: 10 | # Determine if interrupt set 11 | [dataready, singletap, doubletap, activity, inactivity, freefall, watermark, overrun] = adxl345.getInterruptStatus() 12 | 13 | if doubletap: 14 | print("Double Tap") 15 | elif singletap: 16 | print("Single Tap") 17 | -------------------------------------------------------------------------------- /thread-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import thread 4 | import time 5 | 6 | # Define a function for the thread 7 | def print_time( threadName, delay): 8 | count = 0 9 | while count < 5: 10 | time.sleep(delay) 11 | count += 1 12 | print "%s: %s" % ( threadName, time.ctime(time.time()) ) 13 | 14 | # Create two threads as follows 15 | try: 16 | thread.start_new_thread( print_time, ("Thread-1", 2, ) ) 17 | thread.start_new_thread( print_time, ("Thread-2", 4, ) ) 18 | except: 19 | print "Error: unable to start thread" 20 | 21 | while 1: 22 | pass 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | stepper-pi 2 | ========== 3 | 4 | Scripts to control stepper motors from the Raspberry Pi over GPIO 5 | These scripts are for a ULN2003 control board running a 5V 28BJY-48 motor 6 | 7 | ######################################################################### 8 | 9 | Stepper.py - class to control a stepper motor, based on work by Stephen C Phillips 10 | 11 | test-all-motors.sh - runs test-motor.py 4 times - one for each motor 12 | 13 | test-motor.py - tests a single motor, given the 4 GPIO pins it is connected to 14 | 15 | sp-move.py - Stephen C Phillips' original script incorporating class-based control of a stepper motor. www.scphillips.com 16 | 17 | mh-stepper.py - Matt Hawkins script to control a stepper, which doesn't work for me, probably because of a change in the GPIO library 18 | -------------------------------------------------------------------------------- /polkarobot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from Stepper import Motor 4 | from time import sleep 5 | import RPi.GPIO as GPIO 6 | import sys 7 | import datetime 8 | 9 | #import thread 10 | import threading 11 | 12 | class MotorThread(threading.Thread): 13 | def __init__(self, pin1, pin2, pin3, pin4, command_index): 14 | threading.Thread.__init__(self) 15 | self.pin1 = int(pin1) 16 | self.pin2 = int(pin2) 17 | self.pin3 = int(pin3) 18 | self.pin4 = int(pin4) 19 | self.command_index = int(command_index) 20 | 21 | self.motor = Motor([int(self.pin1), int(self.pin2), int(self.pin3), int(self.pin4)], 15) 22 | 23 | def run(self): 24 | self.motor.move_to(90) 25 | 26 | if __name__ == "__main__": 27 | GPIO.setmode(GPIO.BOARD) 28 | GPIO.setwarnings(False) 29 | 30 | try: 31 | mFL = MotorThread( 8, 10, 12, 16, 1) 32 | mFR = MotorThread(18, 22, 24, 26, 2) 33 | mBL = MotorThread( 3, 5, 7, 11, 3) 34 | mBR = MotorThread(15, 19, 21, 23, 4) 35 | 36 | mFL.start() 37 | mFR.start() 38 | mBL.start() 39 | #mBR.start() 40 | 41 | 42 | except Exception as inst: 43 | print("Error: unable to start thread") 44 | print(type(inst)) 45 | print(inst.args) 46 | print(inst) 47 | 48 | while True: 49 | pass 50 | 51 | GPIO.cleanup() 52 | 53 | -------------------------------------------------------------------------------- /polkarobot2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from Stepper import Motor 4 | from time import sleep 5 | import RPi.GPIO as GPIO 6 | import sys 7 | import datetime 8 | 9 | #import thread 10 | #import threading 11 | import multiprocessing 12 | 13 | # self.motor.move_to(90) 14 | 15 | def createMotor(pin1, pin2, pin3, pin4, command_index): 16 | pin1 = int(pin1) 17 | pin2 = int(pin2) 18 | pin3 = int(pin3) 19 | pin4 = int(pin4) 20 | command_index = int(command_index) 21 | 22 | motor = Motor([pin1,pin2,pin3,pin4], 15) 23 | motor.move_to(180) 24 | 25 | if __name__ == "__main__": 26 | GPIO.setmode(GPIO.BOARD) 27 | GPIO.setwarnings(False) 28 | 29 | 30 | mFL = multiprocessing.Process(target=createMotor, args=( 8,10,12,16,1)) 31 | mFL.start() 32 | mFR = multiprocessing.Process(target=createMotor, args=(18,22,24,26,2)) 33 | mFR.start() 34 | mBL = multiprocessing.Process(target=createMotor, args=( 3, 5, 7,11,3)) 35 | mBL.start() 36 | mBR = multiprocessing.Process(target=createMotor, args=(15,19,21,23,4)) 37 | mBR.start() 38 | #mFL = MotorThread( 8, 10, 12, 16, 1) 39 | #mFR = MotorThread(18, 22, 24, 26, 2) 40 | #mBL = MotorThread( 3, 5, 7, 11, 3) 41 | #mBR = MotorThread(15, 19, 21, 23, 4) 42 | 43 | 44 | try: 45 | pass 46 | #mFL = MotorThread( 8, 10, 12, 16, 1) 47 | #mFR = MotorThread(18, 22, 24, 26, 2) 48 | #mBL = MotorThread( 3, 5, 7, 11, 3) 49 | #mBR = MotorThread(15, 19, 21, 23, 4) 50 | 51 | #mFL.start() 52 | #mFR.start() 53 | #mBL.start() 54 | #mBR.start() 55 | 56 | 57 | except Exception as inst: 58 | print("Error: unable to start thread") 59 | print(type(inst)) 60 | print(inst.args) 61 | print(inst) 62 | 63 | while True: 64 | pass 65 | 66 | GPIO.cleanup() 67 | 68 | -------------------------------------------------------------------------------- /mh-stepper.py: -------------------------------------------------------------------------------- 1 | ################################# 2 | ################################# 3 | # This script doesn't work for me - possibly due to the different GPIO library version 4 | ################################# 5 | ################################# 6 | 7 | 8 | #----------------------------------- 9 | # Name: Stepper Motor 10 | # 11 | # Author: Matt Hawkins 12 | # 13 | # Created: 11/07/2012 14 | # Copyright: (c) matt.hawkins 2012 15 | #----------------------------------- 16 | #!/usr/bin/env python 17 | 18 | # Import required libraries 19 | import time 20 | import RPi.GPIO as GPIO 21 | 22 | # Use BCM GPIO references 23 | # instead of physical pin numbers 24 | GPIO.setmode(GPIO.BCM) 25 | 26 | # Define GPIO signals to use 27 | # Pins 18,22,24,26 28 | # GPIO24,GPIO25,GPIO8,GPIO7 29 | StepPins = [24,25,8,7] 30 | 31 | # Set all pins as output 32 | for pin in StepPins: 33 | print "Setup pins" 34 | GPIO.setup(pin,GPIO.OUT) 35 | GPIO.output(pin, False) 36 | 37 | # Define some settings 38 | StepCounter = 0 39 | WaitTime = 0.001 40 | 41 | # Define simple sequence 42 | StepCount1 = 4 43 | Seq1 = [] 44 | Seq1 = range(0, StepCount1) 45 | Seq1[0] = [1,0,0,0] 46 | Seq1[1] = [0,1,0,0] 47 | Seq1[2] = [0,0,1,0] 48 | Seq1[3] = [0,0,0,1] 49 | 50 | # Define advanced sequence 51 | # as shown in manufacturers datasheet 52 | StepCount2 = 8 53 | Seq2 = [] 54 | Seq2 = range(0, StepCount2) 55 | Seq2[0] = [1,0,0,0] 56 | Seq2[1] = [1,1,0,0] 57 | Seq2[2] = [0,1,0,0] 58 | Seq2[3] = [0,1,1,0] 59 | Seq2[4] = [0,0,1,0] 60 | Seq2[5] = [0,0,1,1] 61 | Seq2[6] = [0,0,0,1] 62 | Seq2[7] = [1,0,0,1] 63 | 64 | # Choose a sequence to use 65 | Seq = Seq1 66 | StepCount = StepCount1 67 | 68 | # Start main loop 69 | while 1==1: 70 | 71 | for pin in range(0, 4): 72 | xpin = StepPins[pin] 73 | if Seq[StepCounter][pin]!=0: 74 | print " Step %i Enable %i" %(StepCounter,xpin) 75 | GPIO.output(xpin, True) 76 | else: 77 | GPIO.output(xpin, False) 78 | 79 | StepCounter += 1 80 | 81 | # If we reach the end of the sequence 82 | # start again 83 | if (StepCounter==StepCount): 84 | StepCounter = 0 85 | if (StepCounter<0): 86 | StepCounter = StepCount 87 | 88 | # Wait before moving on 89 | time.sleep(WaitTime) 90 | 91 | -------------------------------------------------------------------------------- /ADXL345/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define ADXL345_I2C_ADDR 0x1d 12 | 13 | void selectDevice(int fd, int addr, char * name) 14 | { 15 | if (ioctl(fd, I2C_SLAVE, addr) < 0) 16 | { 17 | fprintf(stderr, "%s not present\n", name); 18 | } 19 | } 20 | 21 | void writeToDevice(int fd, int reg, int val) 22 | { 23 | char buf[2]; 24 | buf[0]=reg; buf[1]=val; 25 | if (write(fd, buf, 2) != 2) 26 | { 27 | fprintf(stderr, "Can't write to device\n"); 28 | } 29 | } 30 | 31 | int main(int argc, char **argv) 32 | { 33 | unsigned int range; 34 | int count, b; 35 | short x, y, z; 36 | float xa, ya, za; 37 | int fd; 38 | unsigned char buf[16]; 39 | 40 | if ((fd = open("/dev/i2c-1", O_RDWR)) < 0) 41 | { 42 | // Open port for reading and writing 43 | 44 | fprintf(stderr, "Failed to open i2c bus\n"); 45 | 46 | exit(1); 47 | } 48 | 49 | /* initialise ADXL345 */ 50 | 51 | selectDevice(fd, ADXL345_I2C_ADDR, "ADXL345"); 52 | 53 | writeToDevice(fd, 0x2d, 0); 54 | writeToDevice(fd, 0x2d, 16); 55 | writeToDevice(fd, 0x2d, 8); 56 | writeToDevice(fd, 0x31, 0); 57 | writeToDevice(fd, 0x31, 11); 58 | 59 | while (1) 60 | { 61 | 62 | /* select ADXL345 */ 63 | 64 | selectDevice(fd, ADXL345_I2C_ADDR, "ADXL345"); 65 | 66 | buf[0] = 0x32; 67 | 68 | if ((write(fd, buf, 1)) != 1) 69 | { 70 | // Send the register to read from 71 | 72 | fprintf(stderr, "Error writing to i2c slave\n"); 73 | } 74 | 75 | if (read(fd, buf, 6) != 6) 76 | { 77 | // X, Y, Z accelerations 78 | 79 | fprintf(stderr, "Unable to read from ADXL345\n"); 80 | } 81 | else 82 | { 83 | x = buf[1]<<8| buf[0]; 84 | y = buf[3]<<8| buf[2]; 85 | z = buf[5]<<8| buf[4]; 86 | xa = (90.0 / 256.0) * (float) x; 87 | ya = (90.0 / 256.0) * (float) y; 88 | za = (90.0 / 256.0) * (float) z; 89 | printf("%4.0f %4.0f %4.0f\n", xa, ya, za); 90 | } 91 | usleep(900000); 92 | } 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /Stepper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Class to control the 28BJY-48 stepper motor with ULN2003 control board. 4 | # Converted from work done by Stephen Phillips (www.scphillips.com) 5 | 6 | from time import sleep 7 | import RPi.GPIO as GPIO 8 | 9 | class Motor: 10 | def __init__(self, pins, revs_per_minute): 11 | for p in pins: 12 | GPIO.setup(p, GPIO.OUT) 13 | GPIO.output(p, 0) 14 | 15 | self.P1 = pins[0] 16 | self.P2 = pins[1] 17 | self.P3 = pins[2] 18 | self.P4 = pins[3] 19 | 20 | self.deg_per_step = 5.625 / 64 21 | self.steps_per_rev = int(360 / self.deg_per_step) # 4096 22 | self.step_angle = 0 # Assume the way it is pointing is zero degrees 23 | self._rpm = revs_per_minute 24 | 25 | # T is the amount of time to stop between signals 26 | self._T = (60.0 / self._rpm) / self.steps_per_rev 27 | 28 | def move_to(self, angle): 29 | """Take the shortest route to a particular angle (degrees).""" 30 | # Make sure there is a 1:1 mapping between angle and stepper angle 31 | target_step_angle = 8 * (int(angle / self.deg_per_step) / 8) 32 | steps = target_step_angle - self.step_angle 33 | steps = int(steps % self.steps_per_rev) 34 | if steps > self.steps_per_rev / 2: 35 | steps -= int(self.steps_per_rev) 36 | print("moving " + str(steps) + " steps") 37 | self._move_acw(-steps / 8) 38 | else: 39 | print("moving " + str(steps) + " steps") 40 | self._move_cw(steps / 8) 41 | self.step_angle = target_step_angle 42 | 43 | def move_acw(self, angle): 44 | target_step_angle = (int(angle / self.deg_per_step) / 8) 45 | steps = target_step_angle 46 | steps = int(steps % self.steps_per_rev) 47 | self._move_acw(steps) 48 | self.step_angle = self.step_angle - angle 49 | 50 | def _move_cw(self, big_steps): 51 | GPIO.output(self.P1, 0) 52 | GPIO.output(self.P2, 0) 53 | GPIO.output(self.P3, 0) 54 | GPIO.output(self.P4, 0) 55 | 56 | big_steps = int(big_steps) 57 | 58 | for i in range(big_steps): 59 | GPIO.output(self.P4, 1) 60 | sleep(self._T) 61 | GPIO.output(self.P2, 0) 62 | sleep(self._T) 63 | GPIO.output(self.P3, 1) 64 | sleep(self._T) 65 | GPIO.output(self.P1, 0) 66 | sleep(self._T) 67 | GPIO.output(self.P2, 1) 68 | sleep(self._T) 69 | GPIO.output(self.P4, 0) 70 | sleep(self._T) 71 | GPIO.output(self.P1, 1) 72 | sleep(self._T) 73 | GPIO.output(self.P3, 0) 74 | sleep(self._T) 75 | 76 | def _move_acw(self, big_steps): 77 | GPIO.output(self.P1, 0) 78 | GPIO.output(self.P2, 0) 79 | GPIO.output(self.P3, 0) 80 | GPIO.output(self.P4, 0) 81 | 82 | big_steps = int(big_steps) 83 | 84 | for i in range(big_steps): 85 | GPIO.output(self.P3, 0) 86 | sleep(self._T) 87 | GPIO.output(self.P1, 1) 88 | sleep(self._T) 89 | GPIO.output(self.P4, 0) 90 | sleep(self._T) 91 | GPIO.output(self.P2, 1) 92 | sleep(self._T) 93 | GPIO.output(self.P1, 0) 94 | sleep(self._T) 95 | GPIO.output(self.P3, 1) 96 | sleep(self._T) 97 | GPIO.output(self.P2, 0) 98 | sleep(self._T) 99 | GPIO.output(self.P4, 1) 100 | sleep(self._T) 101 | -------------------------------------------------------------------------------- /sp-move.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # This code is written by Stephen C Phillips. 4 | # It is in the public domain, so you can do what you like with it 5 | # but a link to http://scphillips.com would be nice. 6 | 7 | # It works on the Raspberry Pi computer with the standard Debian Wheezy OS and 8 | # the 28BJY-48 stepper motor with ULN2003 control board. 9 | 10 | from time import sleep 11 | import RPi.GPIO as GPIO 12 | 13 | class Motor(object): 14 | def __init__(self, pins): 15 | self.P1 = pins[0] 16 | self.P2 = pins[1] 17 | self.P3 = pins[2] 18 | self.P4 = pins[3] 19 | self.deg_per_step = 5.625 / 64 20 | self.steps_per_rev = int(360 / self.deg_per_step) # 4096 21 | self.step_angle = 0 # Assume the way it is pointing is zero degrees 22 | for p in pins: 23 | GPIO.setup(p, GPIO.OUT) 24 | GPIO.output(p, 0) 25 | 26 | def _set_rpm(self, rpm): 27 | """Set the turn speed in RPM.""" 28 | self._rpm = rpm 29 | # T is the amount of time to stop between signals 30 | self._T = (60.0 / rpm) / self.steps_per_rev 31 | 32 | # This means you can set "rpm" as if it is an attribute and 33 | # behind the scenes it sets the _T attribute 34 | rpm = property(lambda self: self._rpm, _set_rpm) 35 | 36 | def move_to(self, angle): 37 | """Take the shortest route to a particular angle (degrees).""" 38 | # Make sure there is a 1:1 mapping between angle and stepper angle 39 | target_step_angle = 8 * (int(angle / self.deg_per_step) / 8) 40 | steps = target_step_angle - self.step_angle 41 | steps = (steps % self.steps_per_rev) 42 | if steps > self.steps_per_rev / 2: 43 | steps -= self.steps_per_rev 44 | print "moving " + `steps` + " steps" 45 | self._move_acw(-steps / 8) 46 | else: 47 | print "moving " + `steps` + " steps" 48 | self._move_cw(steps / 8) 49 | self.step_angle = target_step_angle 50 | 51 | def _move_acw(self, big_steps): 52 | GPIO.output(self.P1, 0) 53 | GPIO.output(self.P2, 0) 54 | GPIO.output(self.P3, 0) 55 | GPIO.output(self.P4, 0) 56 | for i in range(big_steps): 57 | GPIO.output(self.P1, 0) 58 | sleep(self._T) 59 | GPIO.output(self.P3, 1) 60 | sleep(self._T) 61 | GPIO.output(self.P4, 0) 62 | sleep(self._T) 63 | GPIO.output(self.P2, 1) 64 | sleep(self._T) 65 | GPIO.output(self.P3, 0) 66 | sleep(self._T) 67 | GPIO.output(self.P1, 1) 68 | sleep(self._T) 69 | GPIO.output(self.P2, 0) 70 | sleep(self._T) 71 | GPIO.output(self.P4, 1) 72 | sleep(self._T) 73 | 74 | def _move_cw(self, big_steps): 75 | GPIO.output(self.P1, 0) 76 | GPIO.output(self.P2, 0) 77 | GPIO.output(self.P3, 0) 78 | GPIO.output(self.P4, 0) 79 | for i in range(big_steps): 80 | GPIO.output(self.P3, 0) 81 | sleep(self._T) 82 | GPIO.output(self.P1, 1) 83 | sleep(self._T) 84 | GPIO.output(self.P4, 0) 85 | sleep(self._T) 86 | GPIO.output(self.P2, 1) 87 | sleep(self._T) 88 | GPIO.output(self.P1, 0) 89 | sleep(self._T) 90 | GPIO.output(self.P3, 1) 91 | sleep(self._T) 92 | GPIO.output(self.P2, 0) 93 | sleep(self._T) 94 | GPIO.output(self.P4, 1) 95 | sleep(self._T) 96 | 97 | if __name__ == "__main__": 98 | GPIO.setmode(GPIO.BOARD) 99 | m = Motor([18,22,24,26]) 100 | m.rpm = 5 101 | print "Pause in seconds: " + `m._T` 102 | m.move_to(90) 103 | sleep(1) 104 | m.move_to(0) 105 | sleep(1) 106 | m.move_to(-90) 107 | sleep(1) 108 | m.move_to(-180) 109 | sleep(1) 110 | m.move_to(0) 111 | GPIO.cleanup() 112 | --------------------------------------------------------------------------------