2 versionen Schrittmotor ansteuern
This commit is contained in:
		
							
								
								
									
										1
									
								
								Adafruit_Python_SSD1306
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								Adafruit_Python_SSD1306
									
									
									
									
									
										Submodule
									
								
							 Submodule Adafruit_Python_SSD1306 added at b7eccd1c7a
									
								
							
							
								
								
									
										85
									
								
								schrittmotor.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								schrittmotor.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,85 @@ | ||||
| from time import sleep | ||||
| import RPi.GPIO as GPIO | ||||
|  | ||||
| GPIO.setmode(GPIO.BCM) | ||||
|  | ||||
| # Verwendete Pins am Rapberry Pi | ||||
| A=18 | ||||
| B=23 | ||||
| C=24 | ||||
| D=25 | ||||
| time = 0.001 | ||||
|  | ||||
| # Pins aus Ausgaenge definieren | ||||
| GPIO.setup(A,GPIO.OUT) | ||||
| GPIO.setup(B,GPIO.OUT) | ||||
| GPIO.setup(C,GPIO.OUT) | ||||
| GPIO.setup(D,GPIO.OUT) | ||||
| GPIO.output(A, False) | ||||
| GPIO.output(B, False) | ||||
| GPIO.output(C, False) | ||||
| GPIO.output(D, False) | ||||
|  | ||||
| # Schritte 1 - 8 festlegen | ||||
| def Step1(): | ||||
|     GPIO.output(D, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(D, False) | ||||
|  | ||||
| def Step2(): | ||||
|     GPIO.output(D, True) | ||||
|     GPIO.output(C, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(D, False) | ||||
|     GPIO.output(C, False) | ||||
|  | ||||
| def Step3(): | ||||
|     GPIO.output(C, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(C, False) | ||||
|  | ||||
| def Step4(): | ||||
|     GPIO.output(B, True) | ||||
|     GPIO.output(C, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(B, False) | ||||
|     GPIO.output(C, False) | ||||
|  | ||||
| def Step5(): | ||||
|     GPIO.output(B, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(B, False) | ||||
|  | ||||
| def Step6(): | ||||
|     GPIO.output(A, True) | ||||
|     GPIO.output(B, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(A, False) | ||||
|     GPIO.output(B, False) | ||||
|  | ||||
| def Step7(): | ||||
|     GPIO.output(A, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(A, False) | ||||
|  | ||||
| def Step8(): | ||||
|     GPIO.output(D, True) | ||||
|     GPIO.output(A, True) | ||||
|     sleep (time) | ||||
|     GPIO.output(D, False) | ||||
|     GPIO.output(A, False) | ||||
|  | ||||
| # Volle Umdrehung     | ||||
| for i in range (512):     | ||||
|     Step1() | ||||
|     Step2() | ||||
|     Step3() | ||||
|     Step4() | ||||
|     Step5() | ||||
|     Step6() | ||||
|     Step7() | ||||
|     Step8()   | ||||
|     print i | ||||
|  | ||||
| GPIO.cleanup() | ||||
|  | ||||
							
								
								
									
										56
									
								
								schrittmotor2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								schrittmotor2.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| import RPi.GPIO as GPIO | ||||
| import time | ||||
|   | ||||
| GPIO.setmode(GPIO.BCM) | ||||
| GPIO.setwarnings(False) | ||||
| coil_A_1_pin = 18 # pink | ||||
| coil_A_2_pin = 24 # orange | ||||
| coil_B_1_pin = 23 # blau | ||||
| coil_B_2_pin = 25 # gelb | ||||
| #enable_pin   = 7 # Nur bei bestimmten Motoren benoetigt (+Zeile 24 und 30) | ||||
|   | ||||
| # anpassen, falls andere Sequenz | ||||
| StepCount = 8 | ||||
| Seq = list(range(0, StepCount)) | ||||
| Seq[0] = [0,1,0,0] | ||||
| Seq[1] = [0,1,0,1] | ||||
| Seq[2] = [0,0,0,1] | ||||
| Seq[3] = [1,0,0,1] | ||||
| Seq[4] = [1,0,0,0] | ||||
| Seq[5] = [1,0,1,0] | ||||
| Seq[6] = [0,0,1,0] | ||||
| Seq[7] = [0,1,1,0] | ||||
|   | ||||
| #GPIO.setup(enable_pin, GPIO.OUT) | ||||
| GPIO.setup(coil_A_1_pin, GPIO.OUT) | ||||
| GPIO.setup(coil_A_2_pin, GPIO.OUT) | ||||
| GPIO.setup(coil_B_1_pin, GPIO.OUT) | ||||
| GPIO.setup(coil_B_2_pin, GPIO.OUT) | ||||
|   | ||||
| #GPIO.output(enable_pin, 1) | ||||
|   | ||||
| def setStep(w1, w2, w3, w4): | ||||
|     GPIO.output(coil_A_1_pin, w1) | ||||
|     GPIO.output(coil_A_2_pin, w2) | ||||
|     GPIO.output(coil_B_1_pin, w3) | ||||
|     GPIO.output(coil_B_2_pin, w4) | ||||
|   | ||||
| def forward(delay, steps): | ||||
|     for i in range(steps): | ||||
|         for j in range(StepCount): | ||||
|             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) | ||||
|             time.sleep(delay) | ||||
|   | ||||
| def backwards(delay, steps): | ||||
|     for i in range(steps): | ||||
|         for j in reversed(range(StepCount)): | ||||
|             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) | ||||
|             time.sleep(delay) | ||||
|              | ||||
| if __name__ == '__main__': | ||||
|     while True: | ||||
|         delay = raw_input("Zeitverzoegerung (ms)?") | ||||
|         steps = raw_input("Wie viele Schritte vorwaerts? ") | ||||
|         forward(int(delay) / 1000.0, int(steps)) | ||||
|         steps = raw_input("Wie viele Schritte rueckwaerts? ") | ||||
|         backwards(int(delay) / 1000.0, int(steps)) | ||||
		Reference in New Issue
	
	Block a user
	 Bernhard
					Bernhard